Skip to content
Browse files

Merge pull request #62 from kycan/master

added repo method getBranch
  • Loading branch information...
2 parents 0a98840 + 586970a commit 0d0b905c92d1d709b76ab61fb446a4c7640dca30 @mikedeboer mikedeboer committed
Showing with 79 additions and 0 deletions.
  1. +43 −0 api/v3.0.0/repos.js
  2. +17 −0 api/v3.0.0/reposTest.js
  3. +19 −0 api/v3.0.0/routes.json
View
43 api/v3.0.0/repos.js
@@ -586,6 +586,49 @@ var repos = module.exports = {
};
/** section: github
+ * repos#getBranch(msg, callback) -> null
+ * - msg (Object): Object that contains the parameters and their values to be sent to the server.
+ * - callback (Function): function to call when the request is finished with an error as first argument and result data as second argument.
+ *
+ * ##### Params on the `msg` object:
+ *
+ * - user (String): Required.
+ * - repo (String): Required.
+ * - branch (String): Required.
+ * - page (Number): Optional. Page number of the results to fetch. Validation rule: ` ^[0-9]+$ `.
+ * - per_page (Number): Optional. A custom page size up to 100. Default is 30. Validation rule: ` ^[0-9]+$ `.
+ **/
+ this.getBranch = function(msg, block, callback) {
+ var self = this;
+ this.client.httpSend(msg, block, function(err, res) {
+ if (err)
+ return self.sendError(err, null, msg, callback);
+
+ var ret;
+ try {
+ ret = res.data && JSON.parse(res.data);
+ }
+ catch (ex) {
+ if (callback)
+ callback(new error.InternalServerError(ex.message), res);
+ return;
+ }
+
+ if (!ret)
+ ret = {};
+ if (!ret.meta)
+ ret.meta = {};
+ ["x-ratelimit-limit", "x-ratelimit-remaining", "link"].forEach(function(header) {
+ if (res.headers[header])
+ ret.meta[header] = res.headers[header];
+ });
+
+ if (callback)
+ callback(null, ret);
+ });
+ };
+
+ /** section: github
* repos#getCollaborators(msg, callback) -> null
* - msg (Object): Object that contains the parameters and their values to be sent to the server.
* - callback (Function): function to call when the request is finished with an error as first argument and result data as second argument.
View
17 api/v3.0.0/reposTest.js
@@ -254,6 +254,23 @@ describe("[repos]", function() {
);
});
+ it("should successfully execute GET /repos/:user/:repo/branches/:branch (getBranch)", function(next) {
+ client.repos.getBranches(
+ {
+ user: "String",
+ repo: "String",
+ branch: "String",
+ page: "Number",
+ per_page: "Number"
+ },
+ function(err, res) {
+ Assert.equal(err, null);
+ // other assertions go here
+ next();
+ }
+ );
+ });
+
it("should successfully execute GET /repos/:user/:repo/collaborators (getCollaborators)", function(next) {
client.repos.getCollaborators(
{
View
19 api/v3.0.0/routes.json
@@ -43,6 +43,13 @@
"invalidmsg": "",
"description": ""
},
+ "branch": {
+ "type": "String",
+ "required": true,
+ "validation": "",
+ "invalidmsg": "",
+ "description": ""
+ },
"sha": {
"type": "String",
"required": true,
@@ -1831,6 +1838,18 @@
}
},
+ "get-branch": {
+ "url": "/repos/:user/:repo/branches/:branch",
+ "method": "GET",
+ "params": {
+ "$user": null,
+ "$repo": null,
+ "$branch": null,
+ "$page": null,
+ "$per_page": null
+ }
+ },
+
"get-collaborators": {
"url": "/repos/:user/:repo/collaborators",
"method": "GET",

0 comments on commit 0d0b905

Please sign in to comment.
Something went wrong with that request. Please try again.