<commit_before>var GitHubApi = require("github");
var jsonUtils = require('../utils/json');
var nodeURL = require("url");
var repoClients;



function contributorStatistics (request, response)	{

	var data_out = {},
		responseCount;

	if(nodeURL.parse(request.url).query !== null && nodeURL.parse(request.url, true).query.repo != "all")   {

		if (repoClients[nodeURL.parse(request.url, true).query.repo]) {

			data_out[nodeURL.parse(request.url, true).query.repo] = [];

			repoClients[nodeURL.parse(request.url, true).query.repo].github.repos.getContributors({"user": nodeURL.parse(request.url, true).query.repo.split("/").shift(), "repo": nodeURL.parse(request.url, true).query.repo.split("/").pop(), "anon": false}, function(errors, contribs){
				if (errors == null) {

					contribs.forEach(function(nextContrib){

						(data_out[nodeURL.parse(request.url, true).query.repo]).push({"login": nextContrib.login, "contributions": nextContrib.contributions});
					
					});

					if (nodeURL.parse(request.url, true).query.hasOwnProperty('callback'))	{

						jsonUtils.renderJsonp(data_out, nodeURL.parse(request.url, true).query.callback, response);

					} else {

						jsonUtils.render(data_out, response);

					}

				}
			});

		} else {

			jsonUtils.renderErrors([new Error("Not monitoring this repository!")], response, nodeURL.parse(request.url).query.callback);

		}

	} else {

		responseCount = 0;

		Object.keys(repoClients).forEach(function (nextRepo) {

			data_out[nextRepo] = [];

			repoClients[nextRepo].github.repos.getContributors({"user": repoClients[nextRepo].toString().split("/").shift(), "repo": repoClients[nextRepo].toString().split("/").pop(), "anon": false}, function(errors, contribs){
				if (errors == null) {

					contribs.forEach(function(nextContrib){

						(data_out[nextRepo]).push({"login": nextContrib.login, "contributions": nextContrib.contributions});
					
					});

					responseCount++;

					if (responseCount >= Object.keys(repoClients).length)	{
						
						if (nodeURL.parse(request.url, true).query.hasOwnProperty('callback'))	{

							jsonUtils.renderJsonp(data_out, nodeURL.parse(request.url, true).query.callback, response);

						} else {

							jsonUtils.render(data_out, response);

						}

					}

				} else {

					jsonUtils.renderErrors([new Error(errors)], response, nodeURL.parse(request.url).query.callback);

				}

			});

		});

	}

}


contributorStatistics.name = "Contribution Reporter";
contributorStatistics.description = "Generates JSON/JSONP with all contributors and how many contributions they made for all repos or the repo specified.";

module.exports = {
    '/contribStats': function(_repoClients) {
    	repoClients = _repoClients;
        return contributorStatistics;
    }
};<commit_msg>Small improvements.<commit_after>var jsonUtils = require('../utils/json');
var nodeURL = require("url");
var repoClients;



function contributorStatistics (request, response)    {

    var dataOut = {},
        responseCount,
        urlQuery = nodeURL.parse(request.url, true).query;

    if(nodeURL.parse(request.url).query !== null && urlQuery.repo != "all")   {

        if (repoClients[urlQuery.repo]) {

            dataOut[urlQuery.repo] = [];

            repoClients[urlQuery.repo].github.repos.getContributors({
                "user": urlQuery.repo.split("/").shift(),
                "repo": urlQuery.repo.split("/").pop(),
                "anon": false
            }, function(errors, contribs){
                if (errors == null) {

                    dataOut[urlQuery.repo] = contribs.map(function(nextContrib){

					    return {
					        "login": nextContrib.login, 
					        "contributions": nextContrib.contributions
					    };

					});

                    jsonUtils.render(dataOut, response, urlQuery.callback);

                }
            });

        } else {

            jsonUtils.renderErrors([new Error("Not monitoring this repository!")], response, urlQuery.callback);

        }

    } else {

        responseCount = 0;

        Object.keys(repoClients).forEach(function (nextRepo) {

            dataOut[nextRepo] = [];

            repoClients[nextRepo].github.repos.getContributors({
            	"user": repoClients[nextRepo].toString().split("/").shift(),
            	"repo": repoClients[nextRepo].toString().split("/").pop(),
            	"anon": false
            }, function(errors, contribs){

                if (errors == null) {

                    dataOut[nextRepo] = contribs.map(function(nextContrib){

					    return {
					        "login": nextContrib.login, 
					        "contributions": nextContrib.contributions
					    };

					});

                    responseCount++;

                    if (responseCount >= Object.keys(repoClients).length)    {

                        jsonUtils.render(dataOut, response, urlQuery.callback);

                    }

                } else {

                    jsonUtils.renderErrors([new Error(errors)], response, urlQuery.callback);

                }

            });

        });

    }

}


contributorStatistics.name = "Contribution Reporter";
contributorStatistics.description = "Generates JSON/JSONP with all contributors and how many contributions they made for all repositorys or the repository specified in a 'repo' parameter. For JSONP add a 'callback' parameter.";

module.exports = {
    '/contribStats': function(_repoClients) {
        repoClients = _repoClients;
        return contributorStatistics;
    }
};
{'fraction_non_alphanumeric': 0.14409847936278058, 'fraction_numerical': 0.0003620564808110065, 'mean_word_length': 2.708053691275168, 'pattern_counts': {'":': 20, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4871331', 'n_tokens_mistral': 1829, 'n_tokens_neox': 1533, 'n_words': 268}