Skip to content

Commit d56f230

Browse files
committed
Merge pull request octokit#207 from danthareja/stats
Adds statistics methods to repo
2 parents 9f8664a + 25147e3 commit d56f230

File tree

3 files changed

+320
-0
lines changed

3 files changed

+320
-0
lines changed

api/v3.0.0/repos.js

Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2793,4 +2793,209 @@ var repos = module.exports = {
27932793
});
27942794
};
27952795

2796+
/** section: github
2797+
* repos#getStatsContributors(msg, callback) -> null
2798+
* - msg (Object): Object that contains the parameters and their values to be sent to the server.
2799+
* - callback (Function): function to call when the request is finished with an error as first argument and result data as second argument.
2800+
*
2801+
* ##### Params on the `msg` object:
2802+
*
2803+
* - headers (Object): Optional. Key/ value pair of request headers to pass along with the HTTP request. Valid headers are: 'If-Modified-Since', 'If-None-Match', 'Cookie', 'User-Agent', 'Accept', 'X-GitHub-OTP'.
2804+
* - user (String): Required.
2805+
* - repo (String): Required.
2806+
**/
2807+
this.getStatsContributors = function(msg, block, callback) {
2808+
var self = this;
2809+
this.client.httpSend(msg, block, function(err, res) {
2810+
if (err)
2811+
return self.sendError(err, null, msg, callback);
2812+
2813+
var ret;
2814+
try {
2815+
ret = res.data && JSON.parse(res.data);
2816+
}
2817+
catch (ex) {
2818+
if (callback)
2819+
callback(new error.InternalServerError(ex.message), res);
2820+
return;
2821+
}
2822+
2823+
if (!ret)
2824+
ret = {};
2825+
if (!ret.meta)
2826+
ret.meta = {};
2827+
["x-ratelimit-limit", "x-ratelimit-remaining", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
2828+
if (res.headers[header])
2829+
ret.meta[header] = res.headers[header];
2830+
});
2831+
2832+
if (callback)
2833+
callback(null, ret);
2834+
});
2835+
};
2836+
2837+
/** section: github
2838+
* repos#getStatsCommitActivity(msg, callback) -> null
2839+
* - msg (Object): Object that contains the parameters and their values to be sent to the server.
2840+
* - callback (Function): function to call when the request is finished with an error as first argument and result data as second argument.
2841+
*
2842+
* ##### Params on the `msg` object:
2843+
*
2844+
* - headers (Object): Optional. Key/ value pair of request headers to pass along with the HTTP request. Valid headers are: 'If-Modified-Since', 'If-None-Match', 'Cookie', 'User-Agent', 'Accept', 'X-GitHub-OTP'.
2845+
* - user (String): Required.
2846+
* - repo (String): Required.
2847+
**/
2848+
this.getStatsCommitActivity = function(msg, block, callback) {
2849+
var self = this;
2850+
this.client.httpSend(msg, block, function(err, res) {
2851+
if (err)
2852+
return self.sendError(err, null, msg, callback);
2853+
2854+
var ret;
2855+
try {
2856+
ret = res.data && JSON.parse(res.data);
2857+
}
2858+
catch (ex) {
2859+
if (callback)
2860+
callback(new error.InternalServerError(ex.message), res);
2861+
return;
2862+
}
2863+
2864+
if (!ret)
2865+
ret = {};
2866+
if (!ret.meta)
2867+
ret.meta = {};
2868+
["x-ratelimit-limit", "x-ratelimit-remaining", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
2869+
if (res.headers[header])
2870+
ret.meta[header] = res.headers[header];
2871+
});
2872+
2873+
if (callback)
2874+
callback(null, ret);
2875+
});
2876+
};
2877+
2878+
/** section: github
2879+
* repos#getStatsCodeFrequency(msg, callback) -> null
2880+
* - msg (Object): Object that contains the parameters and their values to be sent to the server.
2881+
* - callback (Function): function to call when the request is finished with an error as first argument and result data as second argument.
2882+
*
2883+
* ##### Params on the `msg` object:
2884+
*
2885+
* - headers (Object): Optional. Key/ value pair of request headers to pass along with the HTTP request. Valid headers are: 'If-Modified-Since', 'If-None-Match', 'Cookie', 'User-Agent', 'Accept', 'X-GitHub-OTP'.
2886+
* - user (String): Required.
2887+
* - repo (String): Required.
2888+
**/
2889+
this.getStatsCodeFrequency = function(msg, block, callback) {
2890+
var self = this;
2891+
this.client.httpSend(msg, block, function(err, res) {
2892+
if (err)
2893+
return self.sendError(err, null, msg, callback);
2894+
2895+
var ret;
2896+
try {
2897+
ret = res.data && JSON.parse(res.data);
2898+
}
2899+
catch (ex) {
2900+
if (callback)
2901+
callback(new error.InternalServerError(ex.message), res);
2902+
return;
2903+
}
2904+
2905+
if (!ret)
2906+
ret = {};
2907+
if (!ret.meta)
2908+
ret.meta = {};
2909+
["x-ratelimit-limit", "x-ratelimit-remaining", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
2910+
if (res.headers[header])
2911+
ret.meta[header] = res.headers[header];
2912+
});
2913+
2914+
if (callback)
2915+
callback(null, ret);
2916+
});
2917+
};
2918+
2919+
/** section: github
2920+
* repos#getStatsParticipation(msg, callback) -> null
2921+
* - msg (Object): Object that contains the parameters and their values to be sent to the server.
2922+
* - callback (Function): function to call when the request is finished with an error as first argument and result data as second argument.
2923+
*
2924+
* ##### Params on the `msg` object:
2925+
*
2926+
* - headers (Object): Optional. Key/ value pair of request headers to pass along with the HTTP request. Valid headers are: 'If-Modified-Since', 'If-None-Match', 'Cookie', 'User-Agent', 'Accept', 'X-GitHub-OTP'.
2927+
* - user (String): Required.
2928+
* - repo (String): Required.
2929+
**/
2930+
this.getStatsParticipation = function(msg, block, callback) {
2931+
var self = this;
2932+
this.client.httpSend(msg, block, function(err, res) {
2933+
if (err)
2934+
return self.sendError(err, null, msg, callback);
2935+
2936+
var ret;
2937+
try {
2938+
ret = res.data && JSON.parse(res.data);
2939+
}
2940+
catch (ex) {
2941+
if (callback)
2942+
callback(new error.InternalServerError(ex.message), res);
2943+
return;
2944+
}
2945+
2946+
if (!ret)
2947+
ret = {};
2948+
if (!ret.meta)
2949+
ret.meta = {};
2950+
["x-ratelimit-limit", "x-ratelimit-remaining", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
2951+
if (res.headers[header])
2952+
ret.meta[header] = res.headers[header];
2953+
});
2954+
2955+
if (callback)
2956+
callback(null, ret);
2957+
});
2958+
};
2959+
2960+
/** section: github
2961+
* repos#getStatsPunchCard(msg, callback) -> null
2962+
* - msg (Object): Object that contains the parameters and their values to be sent to the server.
2963+
* - callback (Function): function to call when the request is finished with an error as first argument and result data as second argument.
2964+
*
2965+
* ##### Params on the `msg` object:
2966+
*
2967+
* - headers (Object): Optional. Key/ value pair of request headers to pass along with the HTTP request. Valid headers are: 'If-Modified-Since', 'If-None-Match', 'Cookie', 'User-Agent', 'Accept', 'X-GitHub-OTP'.
2968+
* - user (String): Required.
2969+
* - repo (String): Required.
2970+
**/
2971+
this.getStatsPunchCard = function(msg, block, callback) {
2972+
var self = this;
2973+
this.client.httpSend(msg, block, function(err, res) {
2974+
if (err)
2975+
return self.sendError(err, null, msg, callback);
2976+
2977+
var ret;
2978+
try {
2979+
ret = res.data && JSON.parse(res.data);
2980+
}
2981+
catch (ex) {
2982+
if (callback)
2983+
callback(new error.InternalServerError(ex.message), res);
2984+
return;
2985+
}
2986+
2987+
if (!ret)
2988+
ret = {};
2989+
if (!ret.meta)
2990+
ret.meta = {};
2991+
["x-ratelimit-limit", "x-ratelimit-remaining", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
2992+
if (res.headers[header])
2993+
ret.meta[header] = res.headers[header];
2994+
});
2995+
2996+
if (callback)
2997+
callback(null, ret);
2998+
});
2999+
};
3000+
27963001
}).call(repos.repos);

api/v3.0.0/reposTest.js

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,4 +1053,74 @@ describe("[repos]", function() {
10531053
}
10541054
);
10551055
});
1056+
1057+
it("should successfully execute GET /repos/:user/:repo/stats/contributors (getStatsContributors)", function(next) {
1058+
client.repos.getStatsContributors(
1059+
{
1060+
user: "String",
1061+
repo: "String"
1062+
},
1063+
function(err, res) {
1064+
Assert.equal(err, null);
1065+
// other assertions go here
1066+
next();
1067+
}
1068+
);
1069+
});
1070+
1071+
it("should successfully execute GET /repos/:user/:repo/stats/commit_activity (getStatsCommitActivity)", function(next) {
1072+
client.repos.getStatsCommitActivity(
1073+
{
1074+
user: "String",
1075+
repo: "String"
1076+
},
1077+
function(err, res) {
1078+
Assert.equal(err, null);
1079+
// other assertions go here
1080+
next();
1081+
}
1082+
);
1083+
});
1084+
1085+
it("should successfully execute GET /repos/:user/:repo/stats/code_frequency (getStatsCodeFrequency)", function(next) {
1086+
client.repos.getStatsCodeFrequency(
1087+
{
1088+
user: "String",
1089+
repo: "String"
1090+
},
1091+
function(err, res) {
1092+
Assert.equal(err, null);
1093+
// other assertions go here
1094+
next();
1095+
}
1096+
);
1097+
});
1098+
1099+
it("should successfully execute GET /repos/:user/:repo/stats/participation (getStatsParticipation)", function(next) {
1100+
client.repos.getStatsParticipation(
1101+
{
1102+
user: "String",
1103+
repo: "String"
1104+
},
1105+
function(err, res) {
1106+
Assert.equal(err, null);
1107+
// other assertions go here
1108+
next();
1109+
}
1110+
);
1111+
});
1112+
1113+
it("should successfully execute GET /repos/:user/:repo/stats/punch_card (getStatsPunchCard)", function(next) {
1114+
client.repos.getStatsPunchCard(
1115+
{
1116+
user: "String",
1117+
repo: "String"
1118+
},
1119+
function(err, res) {
1120+
Assert.equal(err, null);
1121+
// other assertions go here
1122+
next();
1123+
}
1124+
);
1125+
});
10561126
});

api/v3.0.0/routes.json

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2843,6 +2843,51 @@
28432843
"$repo": null,
28442844
"$id": null
28452845
}
2846+
},
2847+
2848+
"get-stats-contributors": {
2849+
"url": "/repos/:user/:repo/stats/contributors",
2850+
"method": "GET",
2851+
"params": {
2852+
"$user": null,
2853+
"$repo": null
2854+
}
2855+
},
2856+
2857+
"get-stats-commit-activity": {
2858+
"url": "/repos/:user/:repo/stats/commit_activity",
2859+
"method": "GET",
2860+
"params": {
2861+
"$user": null,
2862+
"$repo": null
2863+
}
2864+
},
2865+
2866+
"get-stats-code-frequency": {
2867+
"url": "/repos/:user/:repo/stats/code_frequency",
2868+
"method": "GET",
2869+
"params": {
2870+
"$user": null,
2871+
"$repo": null
2872+
}
2873+
},
2874+
2875+
"get-stats-participation": {
2876+
"url": "/repos/:user/:repo/stats/participation",
2877+
"method": "GET",
2878+
"params": {
2879+
"$user": null,
2880+
"$repo": null
2881+
}
2882+
},
2883+
2884+
"get-stats-punch-card": {
2885+
"url": "/repos/:user/:repo/stats/punch_card",
2886+
"method": "GET",
2887+
"params": {
2888+
"$user": null,
2889+
"$repo": null
2890+
}
28462891
}
28472892
},
28482893

0 commit comments

Comments
 (0)