├── .gitignore ├── .npmignore ├── LICENSE ├── README.md ├── doc └── apidoc.js ├── examples ├── addLabelsToIssue.js ├── createFile.js ├── getAllPages.js ├── getFollowing.js ├── getIssuesForRepo.js ├── getOrgPublicMembers.js ├── getReleaseAsset.js ├── getStarred.js ├── getUser.js ├── getUserById.js ├── listOrgs.js ├── searchIssues.js └── searchMostStarredRepos.js ├── lib ├── error.js ├── generate.js ├── index.js ├── routes.json └── util.js ├── package.json ├── templates ├── test_handler.js.tpl └── test_section.js.tpl └── test ├── activityTest.js ├── allPagesTest.js ├── authorizationTest.js ├── enterpriseTest.js ├── gistsTest.js ├── gitdataTest.js ├── issuesTest.js ├── miscTest.js ├── orgsTest.js ├── pullRequestsTest.js ├── reposTest.js ├── searchTest.js └── usersTest.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | 3 | logs 4 | *.log 5 | npm-debug.log* 6 | 7 | *.orig 8 | 9 | .settings.xml 10 | .settings 11 | 12 | .c9revisions 13 | .DS_Store 14 | .idea 15 | 16 | testAuth.json 17 | 18 | apidoc/ 19 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | 3 | logs 4 | *.log 5 | npm-debug.log* 6 | 7 | *.orig 8 | 9 | .settings.xml 10 | .settings 11 | 12 | .c9revisions 13 | .DS_Store 14 | .idea 15 | 16 | testAuth.json 17 | 18 | apidoc/ 19 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright (c) 2012 Cloud9 IDE, Inc. (Mike de Boer) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ##### This repo is deprecated. Use [mikedeboer/node-github](https://github.com/mikedeboer/node-github) instead. 2 | 3 | # Node-github 4 | 5 | A Node.js wrapper for GitHub API. 6 | 7 | ## Installation 8 | 9 | Install via [npm](https://www.npmjs.com/package/github4) ![NPM version](https://badge.fury.io/js/github4.svg) 10 | 11 | ```bash 12 | $ npm install github4 13 | ``` 14 | 15 | or 16 | 17 | Install via git clone 18 | 19 | ```bash 20 | $ git clone git@github.com:kaizensoze/node-github.git 21 | $ cd node-github 22 | $ npm install 23 | ``` 24 | 25 | ## Documentation 26 | 27 | Client API: [https://kaizensoze.github.io/node-github/](https://kaizensoze.github.io/node-github/) 28 | GitHub API: [https://developer.github.com/v3/](https://developer.github.com/v3/) 29 | 30 | ## Test auth file 31 | 32 | Create test auth file for running tests/examples. 33 | 34 | ```bash 35 | $ > testAuth.json 36 | { 37 | "token": "" 38 | } 39 | ``` 40 | 41 | ## Example 42 | 43 | Get all followers for user "defunkt": 44 | ```javascript 45 | var GitHubApi = require("github4"); 46 | 47 | var github = new GitHubApi({ 48 | // optional 49 | debug: true, 50 | protocol: "https", 51 | host: "github.my-GHE-enabled-company.com", // should be api.github.com for GitHub 52 | pathPrefix: "/api/v3", // for some GHEs; none for GitHub 53 | timeout: 5000, 54 | headers: { 55 | "user-agent": "My-Cool-GitHub-App" // GitHub is happy with a unique user agent 56 | } 57 | }); 58 | github.users.getFollowingForUser({ 59 | // optional: 60 | // headers: { 61 | // "cookie": "blahblah" 62 | // }, 63 | user: "defunkt" 64 | }, function(err, res) { 65 | console.log(JSON.stringify(res)); 66 | }); 67 | ``` 68 | 69 | ## Authentication 70 | 71 | Most GitHub API calls don't require authentication. As a rule of thumb: If you can see the information by visiting the site without being logged in, you don't have to be authenticated to retrieve the same information through the API. Of course calls, which change data or read sensitive information have to be authenticated. 72 | 73 | You need the GitHub user name and the API key for authentication. The API key can be found in the user's _Account Settings_. 74 | 75 | ```javascript 76 | // basic 77 | github.authenticate({ 78 | type: "basic", 79 | username: USERNAME, 80 | password: PASSWORD 81 | }); 82 | 83 | // OAuth2 84 | github.authenticate({ 85 | type: "oauth", 86 | token: AUTH_TOKEN 87 | }); 88 | 89 | // OAuth2 Key/Secret 90 | github.authenticate({ 91 | type: "oauth", 92 | key: CLIENT_ID, 93 | secret: CLIENT_SECRET 94 | }) 95 | ``` 96 | 97 | Note: `authenticate` is synchronous because it only stores the 98 | credentials for the next request. 99 | 100 | Once authenticated you can update a user field like so: 101 | ```javascript 102 | github.users.update({ 103 | location: "Argentina" 104 | }, function(err) { 105 | console.log("done!"); 106 | }); 107 | ``` 108 | 109 | ### Creating tokens for your application 110 | [Create a new authorization](https://developer.github.com/v3/oauth_authorizations/#create-a-new-authorization) for your application giving it access to the wanted scopes you need instead of relying on username / password and is the way to go if you have [two-factor authentication](https://github.com/blog/1614-two-factor-authentication) on. 111 | 112 | For example: 113 | 114 | 1. Use github.authenticate() to auth with GitHub using your username / password 115 | 2. Create an application token programmatically with the scopes you need and, if you use two-factor authentication send the `X-GitHub-OTP` header with the one-time-password you get on your token device. 116 | 117 | ```javascript 118 | github.authorization.create({ 119 | scopes: ["user", "public_repo", "repo", "repo:status", "gist"], 120 | note: "what this auth is for", 121 | note_url: "http://url-to-this-auth-app", 122 | headers: { 123 | "X-GitHub-OTP": "two-factor-code" 124 | } 125 | }, function(err, res) { 126 | if (res.token) { 127 | //save and use res.token as in the Oauth process above from now on 128 | } 129 | }); 130 | ``` 131 | 132 | ## Update docs/tests 133 | 134 | ```bash 135 | $ node lib/generate.js 136 | ``` 137 | 138 | Dev note for updating apidoc for github pages: 139 | 140 | ```bash 141 | $ npm install apidoc -g 142 | $ apidoc -i doc/ -o apidoc/ 143 | ``` 144 | 145 | ## Tests 146 | 147 | Run all tests 148 | 149 | ```bash 150 | $ npm test 151 | ``` 152 | 153 | Or run a specific test 154 | 155 | ```bash 156 | $ npm test test/issuesTest.js 157 | ``` 158 | 159 | ## LICENSE 160 | 161 | MIT license. See the LICENSE file for details. 162 | -------------------------------------------------------------------------------- /examples/addLabelsToIssue.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var Client = require("./../lib/index"); 4 | var testAuth = require("./../testAuth.json"); 5 | 6 | var github = new Client({ 7 | debug: true 8 | }); 9 | 10 | github.authenticate({ 11 | type: "oauth", 12 | token: testAuth["token"] 13 | }); 14 | 15 | github.issues.addLabels({ 16 | user: "kaizensoze", 17 | repo: "node-github", 18 | number: "101", 19 | body: ["invalid", "bug", "duplicate"] 20 | }, function(err, res) { 21 | console.log(err, res); 22 | }); 23 | -------------------------------------------------------------------------------- /examples/createFile.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var Client = require("./../lib/index"); 4 | var testAuth = require("./../testAuth.json"); 5 | 6 | var github = new Client({ 7 | debug: true 8 | }); 9 | 10 | github.authenticate({ 11 | type: "oauth", 12 | token: testAuth["token"] 13 | }); 14 | 15 | github.repos.createFile({ 16 | user: "kaizensoze", 17 | repo: "misc-scripts", 18 | path: "blah.txt", 19 | message: "blah blah", 20 | content: "YmxlZXAgYmxvb3A=" 21 | }, function(err, res) { 22 | console.log(err, res); 23 | }); 24 | -------------------------------------------------------------------------------- /examples/getAllPages.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var Assert = require("assert"); 4 | var Client = require("./../lib/index"); 5 | var testAuth = require("./../testAuth.json"); 6 | 7 | var github = new Client({}); 8 | 9 | github.authenticate({ 10 | type: "oauth", 11 | token: testAuth["token"] 12 | }); 13 | 14 | github.getAllPages(github.activity.getStarredRepos, { per_page: 100 }, function(err, res) { 15 | console.log(res.map(function(repo) { return repo['full_name']; })); 16 | console.log(res.length); 17 | }); 18 | -------------------------------------------------------------------------------- /examples/getFollowing.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var Client = require("./../lib/index"); 4 | var testAuth = require("./../testAuth.json"); 5 | 6 | var github = new Client({ 7 | debug: true 8 | }); 9 | 10 | github.authenticate({ 11 | type: "oauth", 12 | token: testAuth["token"] 13 | }); 14 | 15 | github.users.getFollowingForUser({ 16 | user: "defunkt" 17 | }, function(err, res) { 18 | console.log(err, res); 19 | }); 20 | -------------------------------------------------------------------------------- /examples/getIssuesForRepo.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var Client = require("./../lib/index"); 4 | var testAuth = require("./../testAuth.json"); 5 | 6 | var github = new Client({ 7 | debug: false 8 | }); 9 | 10 | github.authenticate({ 11 | type: "oauth", 12 | token: testAuth["token"] 13 | }); 14 | 15 | github.issues.getForRepo({ 16 | user: "kaizensoze", 17 | repo: "node-github" 18 | }, function(err, res) { 19 | if (err) { 20 | console.log(err.toJSON()); 21 | } else { 22 | console.log(res); 23 | } 24 | }); 25 | -------------------------------------------------------------------------------- /examples/getOrgPublicMembers.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var Client = require("./../lib/index"); 4 | var testAuth = require("./../testAuth.json"); 5 | 6 | var github = new Client({ 7 | debug: true 8 | }); 9 | 10 | github.authenticate({ 11 | type: "oauth", 12 | token: testAuth["token"] 13 | }); 14 | 15 | github.orgs.getPublicMembers({ 16 | org: "square" 17 | }, function(err, res) { 18 | console.log(err, res); 19 | }); 20 | -------------------------------------------------------------------------------- /examples/getReleaseAsset.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var Client = require("./../lib/index"); 4 | var testAuth = require("./../testAuth.json"); 5 | 6 | var github = new Client({ 7 | debug: true 8 | }); 9 | 10 | github.authenticate({ 11 | type: "oauth", 12 | token: testAuth["token"] 13 | }); 14 | 15 | var testRepo = { 16 | user: "aktau", 17 | repo: "github-release" 18 | }; 19 | 20 | github.repos.getReleases({ 21 | user: testRepo.user, 22 | repo: testRepo.repo 23 | }, function(err, res) { 24 | var releases = res; 25 | if (releases.length == 0) { 26 | return; 27 | } 28 | var release = releases[0]; 29 | var releaseId = release.id; 30 | console.log(release); 31 | 32 | github.repos.listAssets({ 33 | user: testRepo.user, 34 | repo: testRepo.repo, 35 | id: releaseId 36 | }, function(err, res) { 37 | var assets = res; 38 | if (assets.length == 0) { 39 | return; 40 | } 41 | var asset = assets[0]; 42 | var assetId = asset.id; 43 | console.log(asset); 44 | 45 | github.repos.getAsset({ 46 | user: testRepo.user, 47 | repo: testRepo.repo, 48 | id: assetId, 49 | // headers: { 50 | // "Accept": "application/octet-stream" 51 | // } 52 | }, function(err, res) { 53 | console.log(res); 54 | }); 55 | }); 56 | }); 57 | -------------------------------------------------------------------------------- /examples/getStarred.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var Client = require("./../lib/index"); 4 | var testAuth = require("./../testAuth.json"); 5 | 6 | var github = new Client({}); 7 | 8 | github.authenticate({ 9 | type: "oauth", 10 | token: testAuth["token"] 11 | }); 12 | 13 | var starredRepos = []; 14 | 15 | var req = github.activity.getStarredRepos({ per_page: 100}, getRepos); 16 | function getRepos(err, res) { 17 | if (err) { 18 | return false; 19 | } 20 | 21 | starredRepos = starredRepos.concat(res); 22 | if (github.hasNextPage(res)) { 23 | github.getNextPage(res, getRepos) 24 | } else { 25 | outputStarredRepos(); 26 | } 27 | } 28 | 29 | function outputStarredRepos() { 30 | console.log(starredRepos.map(function(repo) { return repo['full_name']; })); 31 | console.log('starred repos: ' + starredRepos.length); 32 | } 33 | -------------------------------------------------------------------------------- /examples/getUser.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var Client = require("./../lib/index"); 4 | var testAuth = require("./../testAuth.json"); 5 | 6 | var github = new Client({ 7 | debug: true 8 | }); 9 | 10 | github.authenticate({ 11 | type: "oauth", 12 | token: testAuth["token"] 13 | }); 14 | 15 | github.users.get({}, function(err, res) { 16 | console.log(err, res); 17 | }); 18 | -------------------------------------------------------------------------------- /examples/getUserById.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var Client = require("./../lib/index"); 4 | var testAuth = require("./../testAuth.json"); 5 | 6 | var github = new Client({ 7 | debug: true 8 | }); 9 | 10 | github.authenticate({ 11 | type: "oauth", 12 | token: testAuth["token"] 13 | }); 14 | 15 | github.users.getById({ id: "429706" }, function(err, res) { 16 | console.log(err, res); 17 | }); 18 | -------------------------------------------------------------------------------- /examples/listOrgs.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var Client = require("./../lib/index"); 4 | var testAuth = require("./../testAuth.json"); 5 | 6 | var github = new Client({ 7 | debug: true 8 | }); 9 | 10 | github.authenticate({ 11 | type: "oauth", 12 | token: testAuth["token"] 13 | }); 14 | 15 | github.orgs.getAll({ 16 | page: 5, 17 | per_page: 100 18 | }, function(err, res) { 19 | console.log(err, res); 20 | }); 21 | -------------------------------------------------------------------------------- /examples/searchIssues.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var Client = require("./../lib/index"); 4 | var testAuth = require("./../testAuth.json"); 5 | 6 | var github = new Client({ 7 | debug: true 8 | }); 9 | 10 | github.authenticate({ 11 | type: "oauth", 12 | token: testAuth["token"] 13 | }); 14 | 15 | github.search.issues({ 16 | q: "bazinga" 17 | }, function(err, res) { 18 | console.log(err, res); 19 | }); 20 | -------------------------------------------------------------------------------- /examples/searchMostStarredRepos.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var Client = require("./../lib/index"); 4 | var testAuth = require("./../testAuth.json"); 5 | 6 | var github = new Client({ 7 | // debug: true 8 | }); 9 | 10 | github.authenticate({ 11 | type: "oauth", 12 | token: testAuth["token"] 13 | }); 14 | 15 | github.search.repos({ 16 | q: "stars:>=20000", 17 | sort: "stars", 18 | order: "desc" 19 | }, function(err, res) { 20 | for (var itemKey in res['items']) { 21 | var item = res['items'][itemKey]; 22 | var url = item['html_url']; 23 | var star_count = item['stargazers_count']; 24 | console.log(url + " (" + star_count + ")"); 25 | } 26 | }); 27 | -------------------------------------------------------------------------------- /lib/error.js: -------------------------------------------------------------------------------- 1 | /** section: github 2 | * class HttpError 3 | * 4 | * Copyright 2012 Cloud9 IDE, Inc. 5 | * 6 | * This product includes software developed by 7 | * Cloud9 IDE, Inc (http://c9.io). 8 | * 9 | * Author: Mike de Boer 10 | **/ 11 | 12 | var Util = require("util"); 13 | 14 | exports.HttpError = function(message, code, headers) { 15 | Error.call(this, message); 16 | //Error.captureStackTrace(this, arguments.callee); 17 | this.message = message; 18 | this.code = code; 19 | this.status = statusCodes[code]; 20 | this.headers = headers; 21 | }; 22 | Util.inherits(exports.HttpError, Error); 23 | 24 | (function() { 25 | /** 26 | * HttpError#toString() -> String 27 | * 28 | * Returns the stringified version of the error (i.e. the message). 29 | **/ 30 | this.toString = function() { 31 | return this.message; 32 | }; 33 | 34 | /** 35 | * HttpError#toJSON() -> Object 36 | * 37 | * Returns a JSON object representation of the error. 38 | **/ 39 | this.toJSON = function() { 40 | return { 41 | code: this.code, 42 | status: this.status, 43 | message: this.message 44 | }; 45 | }; 46 | 47 | }).call(exports.HttpError.prototype); 48 | 49 | 50 | var statusCodes = { 51 | 400: "Bad Request", 52 | 401: "Unauthorized", 53 | 402: "Payment Required", 54 | 403: "Forbidden", 55 | 404: "Not Found", 56 | 405: "Method Not Allowed", 57 | 406: "Not Acceptable", 58 | 407: "Proxy Authentication Required", 59 | 408: "Request Timeout", 60 | 409: "Conflict", 61 | 410: "Gone", 62 | 411: "Length Required", 63 | 412: "Precondition Failed", 64 | 413: "Request Entity Too Large", 65 | 414: "Request-URI Too Long", 66 | 415: "Unsupported Media Type", 67 | 416: "Requested Range Not Satisfiable", 68 | 417: "Expectation Failed", 69 | 420: "Enhance Your Calm", 70 | 422: "Unprocessable Entity", 71 | 423: "Locked", 72 | 424: "Failed Dependency", 73 | 425: "Unordered Collection", 74 | 426: "Upgrade Required", 75 | 428: "Precondition Required", 76 | 429: "Too Many Requests", 77 | 431: "Request Header Fields Too Large", 78 | 444: "No Response", 79 | 449: "Retry With", 80 | 499: "Client Closed Request", 81 | 500: "Internal Server Error", 82 | 501: "Not Implemented", 83 | 502: "Bad Gateway", 84 | 503: "Service Unavailable", 85 | 504: "Gateway Timeout", 86 | 505: "HTTP Version Not Supported", 87 | 506: "Variant Also Negotiates", 88 | 507: "Insufficient Storage", 89 | 508: "Loop Detected", 90 | 509: "Bandwidth Limit Exceeded", 91 | 510: "Not Extended", 92 | 511: "Network Authentication Required" 93 | }; 94 | 95 | // XXX: Remove? 96 | for (var status in statusCodes) { 97 | var defaultMsg = statusCodes[status]; 98 | 99 | var error = (function(defaultMsg, status) { 100 | return function(msg) { 101 | this.defaultMessage = defaultMsg; 102 | exports.HttpError.call(this, msg || status + ": " + defaultMsg, status); 103 | 104 | if (status >= 500) 105 | Error.captureStackTrace(this, arguments.callee); 106 | }; 107 | })(defaultMsg, status); 108 | 109 | Util.inherits(error, exports.HttpError); 110 | 111 | var className = toCamelCase(defaultMsg); 112 | exports[className] = error; 113 | exports[status] = error; 114 | } 115 | 116 | function toCamelCase(str) { 117 | return str.toLowerCase().replace(/(?:(^.)|(\s+.))/g, function(match) { 118 | return match.charAt(match.length-1).toUpperCase(); 119 | }); 120 | } 121 | -------------------------------------------------------------------------------- /lib/generate.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | /** section: github, internal 3 | * class ApiGenerator 4 | * 5 | * Copyright 2012 Cloud9 IDE, Inc. 6 | * 7 | * This product includes software developed by 8 | * Cloud9 IDE, Inc (http://c9.io). 9 | * 10 | * Author: Mike de Boer 11 | **/ 12 | 13 | "use strict"; 14 | 15 | var fs = require("fs"); 16 | var Path = require("path"); 17 | var Url = require("url"); 18 | var Util = require("./util"); 19 | 20 | var TestSectionTpl = fs.readFileSync(__dirname + "/../templates/test_section.js.tpl", "utf8"); 21 | var TestHandlerTpl = fs.readFileSync(__dirname + "/../templates/test_handler.js.tpl", "utf8"); 22 | 23 | var main = module.exports = function() { 24 | // check routes path 25 | var routesPath = Path.join(__dirname, "routes.json"); 26 | var routes = JSON.parse(fs.readFileSync(routesPath, "utf8")); 27 | if (!routes.defines) { 28 | Util.log("No routes defined.", "fatal"); 29 | process.exit(1); 30 | } 31 | 32 | Util.log("Generating..."); 33 | 34 | var defines = routes.defines; 35 | delete routes.defines; 36 | var sections = {}; 37 | var testSections = {}; 38 | var apidocs = ""; 39 | 40 | function prepareApi(struct, baseType) { 41 | if (!baseType) 42 | baseType = ""; 43 | 44 | Object.keys(struct).sort().forEach(function(routePart) { 45 | var block = struct[routePart]; 46 | if (!block) 47 | return; 48 | var messageType = baseType + "/" + routePart; 49 | if (block.url && block.params) { 50 | // we ended up at an API definition part! 51 | var parts = messageType.split("/"); 52 | var section = Util.toCamelCase(parts[1]); 53 | if (!block.method) { 54 | throw new Error("No HTTP method specified for " + messageType + 55 | "in section " + section); 56 | } 57 | 58 | // add the handler to the sections 59 | if (!sections[section]) { 60 | sections[section] = []; 61 | } 62 | 63 | parts.splice(0, 2); 64 | var funcName = Util.toCamelCase(parts.join("-")); 65 | apidocs += createComment(section, funcName, block); 66 | 67 | // add test to the testSections 68 | if (!testSections[section]) 69 | testSections[section] = []; 70 | testSections[section].push(TestHandlerTpl 71 | .replace("<%name%>", block.method + " " + block.url + " (" + funcName + ")") 72 | .replace("<%funcName%>", section + "." + funcName) 73 | .replace("<%params%>", getParams(block.params, " ")) 74 | ); 75 | } 76 | else { 77 | // recurse into this block next: 78 | prepareApi(block, messageType); 79 | } 80 | }); 81 | } 82 | 83 | function createComment(section, funcName, block) { 84 | var method = block['method'].toLowerCase(); 85 | var url = block['url']; 86 | var funcDisplayName = funcName; 87 | 88 | var commentLines = [ 89 | "/**", 90 | " * @api {" + method + "} " + url + " " + funcName, 91 | " * @apiName " + funcDisplayName, 92 | " * @apiDescription " + block['description'], 93 | " * @apiGroup " + section, 94 | " *" 95 | ]; 96 | 97 | var paramsObj = block['params']; 98 | 99 | // sort params so Required come before Optional 100 | var paramKeys = Object.keys(paramsObj); 101 | paramKeys.sort(function(paramA, paramB) { 102 | var cleanParamA = paramA.replace(/^\$/, ""); 103 | var cleanParamB = paramB.replace(/^\$/, ""); 104 | 105 | var paramInfoA = paramsObj[paramA] || defines['params'][cleanParamA]; 106 | var paramInfoB = paramsObj[paramB] || defines['params'][cleanParamB]; 107 | 108 | var paramRequiredA = paramInfoA['required']; 109 | var paramRequiredB = paramInfoB['required']; 110 | 111 | if (paramRequiredA && !paramRequiredB) return -1; 112 | if (!paramRequiredA && paramRequiredB) return 1; 113 | return 0; 114 | }); 115 | 116 | paramKeys.forEach(function(param) { 117 | var cleanParam = param.replace(/^\$/, ""); 118 | var paramInfo = paramsObj[param] || defines['params'][cleanParam]; 119 | 120 | var paramRequired = paramInfo['required']; 121 | var paramType = paramInfo['type']; 122 | var paramDescription = paramInfo['description']; 123 | var paramDefaultVal = paramInfo['default']; 124 | 125 | var paramLabel = cleanParam; 126 | 127 | // add default value if there is one 128 | if (typeof paramDefaultVal !== "undefined") { 129 | paramLabel += '=' + paramDefaultVal 130 | } 131 | 132 | // show param as either required or optional 133 | if (!paramRequired) { 134 | paramLabel = "[" + paramLabel + "]"; 135 | } 136 | 137 | commentLines.push(" * @apiParam {" + paramType + "} " + paramLabel + " " + paramDescription); 138 | }); 139 | 140 | commentLines.push(" * @apiExample {js} ex:\ngithub." + section + "." + funcName + "({ ... });"); 141 | 142 | return commentLines.join("\n") + "\n */\n\n"; 143 | } 144 | 145 | function getParams(paramsStruct, indent) { 146 | var params = Object.keys(paramsStruct); 147 | if (!params.length) 148 | return "{}"; 149 | var values = []; 150 | var paramName, def; 151 | for (var i = 0, l = params.length; i < l; ++i) { 152 | paramName = params[i]; 153 | if (paramName.charAt(0) == "$") { 154 | paramName = paramName.substr(1); 155 | if (!defines.params[paramName]) { 156 | Util.log("Invalid variable parameter name substitution; param '" + 157 | paramName + "' not found in defines block", "fatal"); 158 | process.exit(1); 159 | } 160 | else 161 | def = defines.params[paramName]; 162 | } 163 | else 164 | def = paramsStruct[paramName]; 165 | 166 | values.push(indent + " " + paramName + ": \"" + def.type + "\""); 167 | } 168 | return "{\n" + values.join(",\n") + "\n" + indent + "}"; 169 | } 170 | 171 | Util.log("Converting routes to functions"); 172 | prepareApi(routes); 173 | 174 | var apidocsPath = Path.join(__dirname, "/../doc", "apidoc.js"); 175 | fs.writeFileSync(apidocsPath, apidocs); 176 | 177 | Object.keys(sections).forEach(function(section) { 178 | Util.log("Writing test file for " + section); 179 | 180 | var def = testSections[section]; 181 | var body = TestSectionTpl 182 | .replace("<%version%>", "3.0.0") 183 | .replace(/<%sectionName%>/g, section) 184 | .replace("<%testBody%>", def.join("\n\n")); 185 | var path = Path.join(__dirname, "/../test", section + "Test.js"); 186 | 187 | fs.writeFileSync(path, body, "utf8"); 188 | }); 189 | }; 190 | 191 | main(); 192 | -------------------------------------------------------------------------------- /lib/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var error = require("./error"); 4 | var fs = require("fs"); 5 | var mime = require("mime"); 6 | var Util = require("./util"); 7 | var Url = require("url"); 8 | 9 | /** section: github 10 | * class Client 11 | * 12 | * Copyright 2012 Cloud9 IDE, Inc. 13 | * 14 | * This product includes software developed by 15 | * Cloud9 IDE, Inc (http://c9.io). 16 | * 17 | * Author: Mike de Boer 18 | * 19 | * Upon instantiation of the [[Client]] class, the routes.json file is loaded 20 | * and parsed for the API HTTP endpoints. For each HTTP endpoint to the 21 | * HTTP server, a method is generated which accepts a Javascript Object 22 | * with parameters and an optional callback to be invoked when the API request 23 | * returns from the server or when the parameters could not be validated. 24 | * 25 | * When an HTTP endpoint is processed and a method is generated as described 26 | * above, [[Client]] also sets up parameter validation with the rules as 27 | * defined in the routes.json. 28 | * 29 | * These definitions are parsed and methods are created that the client can call 30 | * to make an HTTP request to the server. 31 | * 32 | * For example, the endpoint `gists/get-from-user` will be exposed as a member 33 | * on the [[Client]] object and may be invoked with 34 | * 35 | * client.getFromUser({ 36 | * "user": "bob" 37 | * }, function(err, ret) { 38 | * // do something with the result here. 39 | * }); 40 | * 41 | * // or to fetch a specfic page: 42 | * client.getFromUser({ 43 | * "user": "bob", 44 | * "page": 2, 45 | * "per_page": 100 46 | * }, function(err, ret) { 47 | * // do something with the result here. 48 | * }); 49 | * 50 | * All the parameters as specified in the Object that is passed to the function 51 | * as first argument, will be validated according to the rules in the `params` 52 | * block of the route definition. 53 | * Thus, in the case of the `user` parameter, according to the definition in 54 | * the `params` block, it's a variable that first needs to be looked up in the 55 | * `params` block of the `defines` section (at the top of the JSON file). Params 56 | * that start with a `$` sign will be substituted with the param with the same 57 | * name from the `defines/params` section. 58 | * There we see that it is a required parameter (needs to hold a value). In other 59 | * words, if the validation requirements are not met, an HTTP error is passed as 60 | * first argument of the callback. 61 | * 62 | * Implementation Notes: the `method` is NOT case sensitive, whereas `url` is. 63 | * The `url` parameter also supports denoting parameters inside it as follows: 64 | * 65 | * "get-from-user": { 66 | * "url": ":user/gists", 67 | * "method": "GET" 68 | * ... 69 | * } 70 | **/ 71 | var Client = module.exports = function(config) { 72 | config = config || {} 73 | config.headers = config.headers || {}; 74 | this.config = config; 75 | this.debug = Util.isTrue(config.debug); 76 | 77 | this.routes = JSON.parse(fs.readFileSync(__dirname + "/routes.json", "utf8")); 78 | 79 | var pathPrefix = ""; 80 | // Check if a prefix is passed in the config and strip any leading or trailing slashes from it. 81 | if (typeof config.pathPrefix == "string") { 82 | pathPrefix = "/" + config.pathPrefix.replace(/(^[\/]+|[\/]+$)/g, ""); 83 | this.config.pathPrefix = pathPrefix; 84 | } 85 | 86 | this.setupRoutes(); 87 | }; 88 | 89 | (function() { 90 | /** 91 | * Client#setupRoutes() -> null 92 | * 93 | * Configures the routes as defined in routes.json. 94 | * 95 | * [[Client#setupRoutes]] is invoked by the constructor, takes the 96 | * contents of the JSON document that contains the definitions of all the 97 | * available API routes and iterates over them. 98 | * 99 | * It first recurses through each definition block until it reaches an API 100 | * endpoint. It knows that an endpoint is found when the `url` and `param` 101 | * definitions are found as a direct member of a definition block. 102 | * Then the availability of an implementation by the API is checked; if it's 103 | * not present, this means that a portion of the API as defined in the routes.json 104 | * file is not implemented properly, thus an exception is thrown. 105 | * After this check, a method is attached to the [[Client]] instance 106 | * and becomes available for use. Inside this method, the parameter validation 107 | * and typecasting is done, according to the definition of the parameters in 108 | * the `params` block, upon invocation. 109 | * 110 | * This mechanism ensures that the handlers ALWAYS receive normalized data 111 | * that is of the correct format and type. JSON parameters are parsed, Strings 112 | * are trimmed, Numbers and Floats are casted and checked for NaN after that. 113 | * 114 | * Note: Query escaping for usage with SQL products is something that can be 115 | * implemented additionally by adding an additional parameter type. 116 | **/ 117 | this.setupRoutes = function() { 118 | var self = this; 119 | var routes = this.routes; 120 | var defines = routes.defines; 121 | this.constants = defines.constants; 122 | this.requestHeaders = defines["request-headers"].map(function(header) { 123 | return header.toLowerCase(); 124 | }); 125 | this.responseHeaders = defines["response-headers"].map(function(header) { 126 | return header.toLowerCase(); 127 | }); 128 | delete routes.defines; 129 | 130 | function trim(s) { 131 | if (typeof s != "string") 132 | return s; 133 | return s.replace(/^[\s\t\r\n]+/, "").replace(/[\s\t\r\n]+$/, ""); 134 | } 135 | 136 | function parseParams(msg, paramsStruct) { 137 | var params = Object.keys(paramsStruct); 138 | var paramName, def, value, type; 139 | for (var i = 0, l = params.length; i < l; ++i) { 140 | paramName = params[i]; 141 | if (paramName.charAt(0) == "$") { 142 | paramName = paramName.substr(1); 143 | if (!defines.params[paramName]) { 144 | throw new error.BadRequest("Invalid variable parameter name substitution; param '" + 145 | paramName + "' not found in defines block", "fatal"); 146 | } 147 | else { 148 | def = paramsStruct[paramName] = defines.params[paramName]; 149 | delete paramsStruct["$" + paramName]; 150 | } 151 | } 152 | else 153 | def = paramsStruct[paramName]; 154 | 155 | value = trim(msg[paramName]); 156 | if (typeof value != "boolean" && !value) { 157 | // we don't need to validation for undefined parameter values 158 | // that are not required. 159 | if (!def.required || (def["allow-empty"] && value === "")) 160 | continue; 161 | throw new error.BadRequest("Empty value for parameter '" + 162 | paramName + "': " + value); 163 | } 164 | 165 | // validate the value and type of parameter: 166 | if (def.validation) { 167 | if (!new RegExp(def.validation).test(value)) { 168 | throw new error.BadRequest("Invalid value for parameter '" + 169 | paramName + "': " + value); 170 | } 171 | } 172 | 173 | if (def.type) { 174 | type = def.type.toLowerCase(); 175 | if (type == "number") { 176 | value = parseInt(value, 10); 177 | if (isNaN(value)) { 178 | throw new error.BadRequest("Invalid value for parameter '" + 179 | paramName + "': " + msg[paramName] + " is NaN"); 180 | } 181 | } 182 | else if (type == "float") { 183 | value = parseFloat(value); 184 | if (isNaN(value)) { 185 | throw new error.BadRequest("Invalid value for parameter '" + 186 | paramName + "': " + msg[paramName] + " is NaN"); 187 | } 188 | } 189 | else if (type == "json") { 190 | if (typeof value == "string") { 191 | try { 192 | value = JSON.parse(value); 193 | } 194 | catch(ex) { 195 | throw new error.BadRequest("JSON parse error of value for parameter '" + 196 | paramName + "': " + value); 197 | } 198 | } 199 | } 200 | else if (type == "date") { 201 | value = new Date(value); 202 | } 203 | } 204 | msg[paramName] = value; 205 | } 206 | } 207 | 208 | function prepareApi(struct, baseType) { 209 | if (!baseType) 210 | baseType = ""; 211 | Object.keys(struct).forEach(function(routePart) { 212 | var block = struct[routePart]; 213 | if (!block) 214 | return; 215 | var messageType = baseType + "/" + routePart; 216 | if (block.url && block.params) { 217 | // we ended up at an API definition part! 218 | var endPoint = messageType.replace(/^[\/]+/g, ""); 219 | var parts = messageType.split("/"); 220 | var section = Util.toCamelCase(parts[1].toLowerCase()); 221 | parts.splice(0, 2); 222 | var funcName = Util.toCamelCase(parts.join("-")); 223 | 224 | if (!self[section]) { 225 | self[section] = {}; 226 | // add a utility function 'getFooApi()', which returns the 227 | // section to which functions are attached. 228 | self[Util.toCamelCase("get-" + section + "-api")] = function() { 229 | return self[section]; 230 | }; 231 | } 232 | 233 | self[section][funcName] = function(msg, callback) { 234 | try { 235 | parseParams(msg, block.params); 236 | } 237 | catch (ex) { 238 | // when the message was sent to the client, we can 239 | // reply with the error directly. 240 | self.sendError(ex, block, msg, callback); 241 | if (self.debug) 242 | Util.log(ex.message, "fatal"); 243 | // on error, there's no need to continue. 244 | return; 245 | } 246 | self.handler(msg, JSON.parse(JSON.stringify(block)), callback); 247 | }; 248 | } 249 | else { 250 | // recurse into this block next: 251 | prepareApi(block, messageType); 252 | } 253 | }); 254 | } 255 | 256 | prepareApi(routes); 257 | }; 258 | 259 | /** 260 | * Client#authenticate(options) -> null 261 | * - options (Object): Object containing the authentication type and credentials 262 | * - type (String): One of the following: `basic` or `oauth` 263 | * - username (String): Github username 264 | * - password (String): Password to your account 265 | * - token (String): OAuth2 token 266 | * 267 | * Set an authentication method to have access to protected resources. 268 | * 269 | * ##### Example 270 | * 271 | * // basic 272 | * github.authenticate({ 273 | * type: "basic", 274 | * username: "mikedeboertest", 275 | * password: "test1324" 276 | * }); 277 | * 278 | * // or oauth 279 | * github.authenticate({ 280 | * type: "oauth", 281 | * token: "e5a4a27487c26e571892846366de023349321a73" 282 | * }); 283 | * 284 | * // or oauth key/ secret 285 | * github.authenticate({ 286 | * type: "oauth", 287 | * key: "clientID", 288 | * secret: "clientSecret" 289 | * }); 290 | * 291 | * // or token 292 | * github.authenticate({ 293 | * type: "token", 294 | * token: "userToken", 295 | * }); 296 | **/ 297 | this.authenticate = function(options) { 298 | if (!options) { 299 | this.auth = false; 300 | return; 301 | } 302 | if (!options.type || "basic|oauth|client|token".indexOf(options.type) === -1) 303 | throw new Error("Invalid authentication type, must be 'basic', 'oauth' or 'client'"); 304 | if (options.type == "basic" && (!options.username || !options.password)) 305 | throw new Error("Basic authentication requires both a username and password to be set"); 306 | if (options.type == "oauth") { 307 | if (!options.token && !(options.key && options.secret)) 308 | throw new Error("OAuth2 authentication requires a token or key & secret to be set"); 309 | } 310 | if (options.type == "token" && !options.token) 311 | throw new Error("Token authentication requires a token to be set"); 312 | 313 | this.auth = options; 314 | }; 315 | 316 | function getPageLinks(link) { 317 | if (typeof link == "object" && (link.link || link.meta.link)) 318 | link = link.link || link.meta.link; 319 | 320 | var links = {}; 321 | if (typeof link != "string") 322 | return links; 323 | 324 | // link format: 325 | // '; rel="next", ; rel="last"' 326 | link.replace(/<([^>]*)>;\s*rel="([\w]*)\"/g, function(m, uri, type) { 327 | links[type] = uri; 328 | }); 329 | return links; 330 | } 331 | 332 | /** 333 | * Client#hasNextPage(link) -> null 334 | * - link (mixed): response of a request or the contents of the Link header 335 | * 336 | * Check if a request result contains a link to the next page 337 | **/ 338 | this.hasNextPage = function(link) { 339 | return getPageLinks(link).next; 340 | }; 341 | 342 | /** 343 | * Client#getAllPages(method, options, callback) -> null 344 | * - method (Function): github client method to be called recursively 345 | * - options (Object): options to be passed in to the method, see the documentation for the passed in method 346 | * - callback (Function): function to call when the request is finished with an error as first argument and result data as second argument. 347 | * 348 | * Follow all next links and returned the combined data of all pages 349 | */ 350 | this.getAllPages = function (method, options, callback) { 351 | options.per_page = options.per_page || 100 352 | var result = [] 353 | var cont = function (err, list) { 354 | if (err) 355 | return callback(err) 356 | 357 | result = result.concat(list) 358 | if (!this.hasNextPage(list)) { 359 | return callback(null, result) 360 | } 361 | this.getNextPage(list, cont) 362 | }.bind(this) 363 | method(options, cont) 364 | }; 365 | 366 | /** 367 | * Client#hasPreviousPage(link) -> null 368 | * - link (mixed): response of a request or the contents of the Link header 369 | * 370 | * Check if a request result contains a link to the previous page 371 | **/ 372 | this.hasPreviousPage = function(link) { 373 | return getPageLinks(link).prev; 374 | }; 375 | 376 | /** 377 | * Client#hasLastPage(link) -> null 378 | * - link (mixed): response of a request or the contents of the Link header 379 | * 380 | * Check if a request result contains a link to the last page 381 | **/ 382 | this.hasLastPage = function(link) { 383 | return getPageLinks(link).last; 384 | }; 385 | 386 | /** 387 | * Client#hasFirstPage(link) -> null 388 | * - link (mixed): response of a request or the contents of the Link header 389 | * 390 | * Check if a request result contains a link to the first page 391 | **/ 392 | this.hasFirstPage = function(link) { 393 | return getPageLinks(link).first; 394 | }; 395 | 396 | function getPage(link, which, callback) { 397 | var url = getPageLinks(link)[which]; 398 | if (!url) 399 | return callback(new error.NotFound("No " + which + " page found")); 400 | 401 | var parsedUrl = Url.parse(url, true); 402 | var block = { 403 | url: parsedUrl.pathname, 404 | method: "GET", 405 | params: parsedUrl.query 406 | }; 407 | var self = this; 408 | this.httpSend(parsedUrl.query, block, function(err, res) { 409 | if (err) 410 | return self.sendError(err, null, parsedUrl.query, callback); 411 | 412 | var ret; 413 | try { 414 | ret = res.data; 415 | var contentType = res.headers["content-type"]; 416 | if (contentType && contentType.indexOf("application/json") !== -1) 417 | ret = JSON.parse(ret); 418 | } 419 | catch (ex) { 420 | if (callback) 421 | callback(new error.InternalServerError(ex.message), res); 422 | return; 423 | } 424 | 425 | if (!ret) 426 | ret = {}; 427 | if (typeof ret == "object") { 428 | if (!ret.meta) 429 | ret.meta = {}; 430 | self.responseHeaders.forEach(function(header) { 431 | if (res.headers[header]) 432 | ret.meta[header] = res.headers[header]; 433 | }); 434 | } 435 | 436 | if (callback) 437 | callback(null, ret); 438 | }); 439 | } 440 | 441 | /** 442 | * Client#getNextPage(link, callback) -> null 443 | * - link (mixed): response of a request or the contents of the Link header 444 | * - callback (Function): function to call when the request is finished with an error as first argument and result data as second argument. 445 | * 446 | * Get the next page, based on the contents of the `Link` header 447 | **/ 448 | this.getNextPage = function(link, callback) { 449 | getPage.call(this, link, "next", callback); 450 | }; 451 | 452 | /** 453 | * Client#getPreviousPage(link, callback) -> null 454 | * - link (mixed): response of a request or the contents of the Link header 455 | * - callback (Function): function to call when the request is finished with an error as first argument and result data as second argument. 456 | * 457 | * Get the previous page, based on the contents of the `Link` header 458 | **/ 459 | this.getPreviousPage = function(link, callback) { 460 | getPage.call(this, link, "prev", callback); 461 | }; 462 | 463 | /** 464 | * Client#getLastPage(link, callback) -> null 465 | * - link (mixed): response of a request or the contents of the Link header 466 | * - callback (Function): function to call when the request is finished with an error as first argument and result data as second argument. 467 | * 468 | * Get the last page, based on the contents of the `Link` header 469 | **/ 470 | this.getLastPage = function(link, callback) { 471 | getPage.call(this, link, "last", callback); 472 | }; 473 | 474 | /** 475 | * Client#getFirstPage(link, callback) -> null 476 | * - link (mixed): response of a request or the contents of the Link header 477 | * - callback (Function): function to call when the request is finished with an error as first argument and result data as second argument. 478 | * 479 | * Get the first page, based on the contents of the `Link` header 480 | **/ 481 | this.getFirstPage = function(link, callback) { 482 | getPage.call(this, link, "first", callback); 483 | }; 484 | 485 | function getRequestFormat(hasBody, block) { 486 | if (hasBody) 487 | return block.requestFormat || this.constants.requestFormat; 488 | 489 | return "query"; 490 | } 491 | 492 | function getQueryAndUrl(msg, def, format, config) { 493 | var url = def.url; 494 | if (config.pathPrefix && url.indexOf(config.pathPrefix) !== 0) { 495 | url = config.pathPrefix + def.url; 496 | } 497 | var ret = { 498 | query: format == "json" ? {} : format == "raw" ? msg.data : [] 499 | }; 500 | if (!def || !def.params) { 501 | ret.url = url; 502 | return ret; 503 | } 504 | 505 | Object.keys(def.params).forEach(function(paramName) { 506 | paramName = paramName.replace(/^[$]+/, ""); 507 | if (!(paramName in msg)) 508 | return; 509 | 510 | var isUrlParam = url.indexOf(":" + paramName) !== -1; 511 | var valFormat = isUrlParam || format != "json" ? "query" : format; 512 | var val; 513 | if (valFormat != "json") { 514 | if (typeof msg[paramName] == "object") { 515 | try { 516 | msg[paramName] = JSON.stringify(msg[paramName]); 517 | val = encodeURIComponent(msg[paramName]); 518 | } 519 | catch (ex) { 520 | return Util.log("httpSend: Error while converting object to JSON: " 521 | + (ex.message || ex), "error"); 522 | } 523 | } 524 | else if (def.params[paramName] && def.params[paramName].combined) { 525 | // Check if this is a combined (search) string. 526 | val = msg[paramName].split(/[\s\t\r\n]*\+[\s\t\r\n]*/) 527 | .map(function(part) { 528 | return encodeURIComponent(part); 529 | }) 530 | .join("+"); 531 | } 532 | else 533 | val = encodeURIComponent(msg[paramName]); 534 | } 535 | else 536 | val = msg[paramName]; 537 | 538 | if (isUrlParam) { 539 | url = url.replace(":" + paramName, val); 540 | } 541 | else { 542 | if (format == "json" && def.params[paramName].sendValueAsBody) 543 | ret.query = val; 544 | else if (format == "json") 545 | ret.query[paramName] = val; 546 | else if (format != "raw") 547 | ret.query.push(paramName + "=" + val); 548 | } 549 | }); 550 | ret.url = url; 551 | return ret; 552 | } 553 | 554 | /** 555 | * Client#httpSend(msg, block, callback) -> null 556 | * - msg (Object): parameters to send as the request body 557 | * - block (Object): parameter definition from the `routes.json` file that 558 | * contains validation rules 559 | * - callback (Function): function to be called when the request returns. 560 | * If the the request returns with an error, the error is passed to 561 | * the callback as its first argument (NodeJS-style). 562 | * 563 | * Send an HTTP request to the server and pass the result to a callback. 564 | **/ 565 | this.httpSend = function(msg, block, callback) { 566 | var self = this; 567 | var method = block.method.toLowerCase(); 568 | var hasFileBody = block.hasFileBody; 569 | var hasBody = !hasFileBody && ("head|get|delete".indexOf(method) === -1); 570 | var format = getRequestFormat.call(this, hasBody, block); 571 | var obj = getQueryAndUrl(msg, block, format, self.config); 572 | var query = obj.query; 573 | var url = this.config.url ? this.config.url + obj.url : obj.url; 574 | var HttpsProxyAgent = require('https-proxy-agent'); 575 | var agent = undefined; 576 | 577 | var path = url; 578 | var protocol = this.config.protocol || this.constants.protocol || "http"; 579 | var host = block.host || this.config.host || this.constants.host; 580 | var port = this.config.port || this.constants.port || (protocol == "https" ? 443 : 80); 581 | var proxyUrl; 582 | var ca = this.config.ca; 583 | if (this.config.proxy !== undefined) { 584 | proxyUrl = this.config.proxy; 585 | } else { 586 | proxyUrl = process.env.HTTPS_PROXY || process.env.HTTP_PROXY; 587 | } 588 | if (proxyUrl) { 589 | agent = new HttpsProxyAgent(proxyUrl); 590 | } 591 | if (!hasBody && query.length) 592 | path += "?" + query.join("&"); 593 | 594 | var headers = { 595 | "host": host, 596 | "content-length": "0" 597 | }; 598 | if (hasBody) { 599 | if (format == "json") 600 | query = JSON.stringify(query); 601 | else if (format != "raw") 602 | query = query.join("&"); 603 | headers["content-length"] = Buffer.byteLength(query, "utf8"); 604 | headers["content-type"] = format == "json" 605 | ? "application/json; charset=utf-8" 606 | : format == "raw" 607 | ? "text/plain; charset=utf-8" 608 | : "application/x-www-form-urlencoded; charset=utf-8"; 609 | } 610 | if (this.auth) { 611 | var basic; 612 | switch (this.auth.type) { 613 | case "oauth": 614 | if (this.auth.token) { 615 | path += (path.indexOf("?") === -1 ? "?" : "&") + 616 | "access_token=" + encodeURIComponent(this.auth.token); 617 | } else { 618 | path += (path.indexOf("?") === -1 ? "?" : "&") + 619 | "client_id=" + encodeURIComponent(this.auth.key) + 620 | "&client_secret=" + encodeURIComponent(this.auth.secret); 621 | } 622 | break; 623 | case "token": 624 | headers.authorization = "token " + this.auth.token; 625 | break; 626 | case "basic": 627 | basic = new Buffer(this.auth.username + ":" + this.auth.password, "ascii").toString("base64"); 628 | headers.authorization = "Basic " + basic; 629 | break; 630 | default: 631 | break; 632 | } 633 | } 634 | 635 | function callCallback(err, result) { 636 | if (callback) { 637 | var cb = callback; 638 | callback = undefined; 639 | cb(err, result); 640 | } 641 | } 642 | 643 | function addCustomHeaders(customHeaders) { 644 | Object.keys(customHeaders).forEach(function(header) { 645 | var headerLC = header.toLowerCase(); 646 | if (self.requestHeaders.indexOf(headerLC) == -1) 647 | return; 648 | headers[headerLC] = customHeaders[header]; 649 | }); 650 | } 651 | addCustomHeaders(Util.extend(msg.headers || {}, this.config.headers)); 652 | 653 | if (!headers["user-agent"]) 654 | headers["user-agent"] = "NodeJS HTTP Client"; 655 | 656 | if (!("accept" in headers)) 657 | headers.accept = this.config.requestMedia || this.constants.requestMedia; 658 | 659 | var options = { 660 | host: host, 661 | port: port, 662 | path: path, 663 | method: method, 664 | headers: headers, 665 | ca: ca 666 | }; 667 | 668 | if (agent) { 669 | options.agent = agent; 670 | } 671 | 672 | if (this.config.rejectUnauthorized !== undefined) 673 | options.rejectUnauthorized = this.config.rejectUnauthorized; 674 | 675 | if (this.debug) 676 | console.log("REQUEST: ", options); 677 | 678 | function httpSendRequest() { 679 | var req = require('follow-redirects/' + protocol).request(options, function(res) { 680 | if (self.debug) { 681 | console.log("STATUS: " + res.statusCode); 682 | console.log("HEADERS: " + JSON.stringify(res.headers)); 683 | } 684 | res.setEncoding("utf8"); 685 | var data = ""; 686 | res.on("data", function(chunk) { 687 | data += chunk; 688 | }); 689 | res.on("error", function(err) { 690 | callCallback(err); 691 | }); 692 | res.on("end", function() { 693 | if (res.statusCode >= 400 && res.statusCode < 600 || res.statusCode < 10) { 694 | callCallback(new error.HttpError(data, res.statusCode, res.headers)); 695 | } else { 696 | res.data = data; 697 | callCallback(null, res); 698 | } 699 | }); 700 | }); 701 | 702 | var timeout = (block.timeout !== undefined) ? block.timeout : self.config.timeout; 703 | if (timeout) { 704 | req.setTimeout(timeout); 705 | } 706 | 707 | req.on("error", function(e) { 708 | if (self.debug) 709 | console.log("problem with request: " + e.message); 710 | callCallback(e.message); 711 | }); 712 | 713 | req.on("timeout", function() { 714 | if (self.debug) 715 | console.log("problem with request: timed out"); 716 | callCallback(new error.GatewayTimeout()); 717 | }); 718 | 719 | // write data to request body 720 | if (hasBody && query.length) { 721 | if (self.debug) 722 | console.log("REQUEST BODY: " + query + "\n"); 723 | req.write(query + "\n"); 724 | } 725 | 726 | if (block.hasFileBody) { 727 | var stream = fs.createReadStream(msg.filePath); 728 | stream.pipe(req); 729 | } else { 730 | req.end(); 731 | } 732 | }; 733 | 734 | if (hasFileBody) { 735 | fs.stat(msg.filePath, function(err, stat) { 736 | if (err) { 737 | callCallback(err); 738 | } else { 739 | headers["content-length"] = stat.size; 740 | headers["content-type"] = mime.lookup(msg.name); 741 | httpSendRequest(); 742 | } 743 | }); 744 | } else { 745 | httpSendRequest(); 746 | } 747 | }; 748 | 749 | this.sendError = function(err, block, msg, callback) { 750 | if (this.debug) 751 | Util.log(err, block, msg, "error"); 752 | if (typeof err == "string") 753 | err = new error.InternalServerError(err); 754 | if (callback && typeof(callback) === "function") 755 | callback(err); 756 | }; 757 | 758 | this.handler = function(msg, block, callback) { 759 | var self = this; 760 | this.httpSend(msg, block, function(err, res) { 761 | if (err) 762 | return self.sendError(err, msg, null, callback); 763 | 764 | var ret; 765 | try { 766 | ret = res.data && JSON.parse(res.data); 767 | } 768 | catch (ex) { 769 | if (callback) 770 | callback(new error.InternalServerError(ex.message), res); 771 | return; 772 | } 773 | 774 | if (!ret) { 775 | ret = {}; 776 | } 777 | ret.meta = {}; 778 | self.responseHeaders.forEach(function(header) { 779 | if (res.headers[header]) { 780 | ret.meta[header] = res.headers[header]; 781 | } 782 | }); 783 | 784 | if (callback) 785 | callback(null, ret); 786 | }); 787 | } 788 | }).call(Client.prototype); 789 | -------------------------------------------------------------------------------- /lib/util.js: -------------------------------------------------------------------------------- 1 | /** section: github 2 | * class Util 3 | * 4 | * Copyright 2012 Cloud9 IDE, Inc. 5 | * 6 | * This product includes software developed by 7 | * Cloud9 IDE, Inc (http://c9.io). 8 | * 9 | * Author: Mike de Boer 10 | **/ 11 | 12 | var Util = require("util"); 13 | 14 | /** 15 | * Util#extend(dest, src, noOverwrite) -> Object 16 | * - dest (Object): destination object 17 | * - src (Object): source object 18 | * - noOverwrite (Boolean): set to `true` to overwrite values in `src` 19 | * 20 | * Shallow copy of properties from the `src` object to the `dest` object. If the 21 | * `noOverwrite` argument is set to to `true`, the value of a property in `src` 22 | * will not be overwritten if it already exists. 23 | **/ 24 | exports.extend = function(dest, src, noOverwrite) { 25 | for (var prop in src) { 26 | if (!noOverwrite || typeof dest[prop] == "undefined") 27 | dest[prop] = src[prop]; 28 | } 29 | return dest; 30 | }; 31 | 32 | /** 33 | * Util#escapeRegExp(str) -> String 34 | * - str (String): string to escape 35 | * 36 | * Escapes characters inside a string that will an error when it is used as part 37 | * of a regex upon instantiation like in `new RegExp("[0-9" + str + "]")` 38 | **/ 39 | exports.escapeRegExp = function(str) { 40 | return str.replace(/([.*+?^${}()|[\]\/\\])/g, '\\$1'); 41 | }; 42 | 43 | /** 44 | * Util#toCamelCase(str, [upper]) -> String 45 | * - str (String): string to transform 46 | * - upper (Boolean): set to `true` to transform to CamelCase 47 | * 48 | * Transform a string that contains spaces or dashes to camelCase. If `upper` is 49 | * set to `true`, the string will be transformed to CamelCase. 50 | * 51 | * Example: 52 | * 53 | * Util.toCamelCase("why U no-work"); // returns 'whyUNoWork' 54 | * Util.toCamelCase("I U no-work", true); // returns 'WhyUNoWork' 55 | **/ 56 | exports.toCamelCase = function(str, upper) { 57 | str = str.toLowerCase().replace(/(?:(^.)|(\s+.)|(-.))/g, function(match) { 58 | return match.charAt(match.length - 1).toUpperCase(); 59 | }); 60 | if (upper) 61 | return str; 62 | return str.charAt(0).toLowerCase() + str.substr(1); 63 | }; 64 | 65 | /** 66 | * Util#isTrue(c) -> Boolean 67 | * - c (mixed): value the variable to check. Possible values: 68 | * true The function returns true. 69 | * 'true' The function returns true. 70 | * 'on' The function returns true. 71 | * 1 The function returns true. 72 | * '1' The function returns true. 73 | * 74 | * Determines whether a string is true in the html attribute sense. 75 | **/ 76 | exports.isTrue = function(c){ 77 | return (c === true || c === "true" || c === "on" || typeof c == "number" && c > 0 || c === "1"); 78 | }; 79 | 80 | /** 81 | * Util#isFalse(c) -> Boolean 82 | * - c (mixed): value the variable to check. Possible values: 83 | * false The function returns true. 84 | * 'false' The function returns true. 85 | * 'off' The function returns true. 86 | * 0 The function returns true. 87 | * '0' The function returns true. 88 | * 89 | * Determines whether a string is false in the html attribute sense. 90 | **/ 91 | exports.isFalse = function(c){ 92 | return (c === false || c === "false" || c === "off" || c === 0 || c === "0"); 93 | }; 94 | 95 | var levels = { 96 | "info": ["\u001b[90m", "\u001b[39m"], // grey 97 | "error": ["\u001b[31m", "\u001b[39m"], // red 98 | "fatal": ["\u001b[35m", "\u001b[39m"], // magenta 99 | "exit": ["\u001b[36m", "\u001b[39m"] // cyan 100 | }; 101 | var _slice = Array.prototype.slice; 102 | 103 | /** 104 | * Util#log(arg1, [arg2], [type]) -> null 105 | * - arg1 (mixed): messages to be printed to the standard output 106 | * - type (String): type denotation of the message. Possible values: 107 | * 'info', 'error', 'fatal', 'exit'. Optional, defaults to 'info'. 108 | * 109 | * Unified logging to the console; arguments passed to this function will put logged 110 | * to the standard output of the current process and properly formatted. 111 | * Any non-String object will be inspected by the NodeJS util#inspect utility 112 | * function. 113 | * Messages will be prefixed with its type (with corresponding font color), like so: 114 | * 115 | * [info] informational message 116 | * [error] error message 117 | * [fatal] fatal error message 118 | * [exit] program exit message (not an error) 119 | * 120 | * The type of message can be defined by passing it to this function as the last/ 121 | * final argument. If the type can not be found, this last/ final argument will be 122 | * regarded as yet another message. 123 | **/ 124 | exports.log = function() { 125 | var args = _slice.call(arguments); 126 | var lastArg = args[args.length - 1]; 127 | 128 | var level = levels[lastArg] ? args.pop() : "info"; 129 | if (!args.length) 130 | return; 131 | 132 | var msg = args.map(function(arg) { 133 | return typeof arg != "string" ? Util.inspect(arg) : arg; 134 | }).join(" "); 135 | var pfx = levels[level][0] + "[" + level + "]" + levels[level][1]; 136 | 137 | msg.split("\n").forEach(function(line) { 138 | console.log(pfx + " " + line); 139 | }); 140 | }; 141 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "github4", 3 | "version": "1.1.1", 4 | "description": "NodeJS wrapper for the GitHub API", 5 | "author": "Mike de Boer ", 6 | "contributors": [ 7 | { 8 | "name": "Mike de Boer", 9 | "email": "info@mikedeboer.nl" 10 | }, 11 | { 12 | "name": "Fabian Jakobs", 13 | "email": "fabian@c9.io" 14 | }, 15 | { 16 | "name": "Joe Gallo", 17 | "email": "joe@brassafrax.com" 18 | } 19 | ], 20 | "homepage": "https://github.com/kaizensoze/node-github", 21 | "repository": { 22 | "type": "git", 23 | "url": "https://github.com/kaizensoze/node-github.git" 24 | }, 25 | "engine": { 26 | "node": ">=0.4.0" 27 | }, 28 | "dependencies": { 29 | "follow-redirects": "0.0.7", 30 | "https-proxy-agent": "^1.0.0", 31 | "mime": "^1.2.11" 32 | }, 33 | "devDependencies": { 34 | "mocha": "~1.13.0" 35 | }, 36 | "main": "lib", 37 | "scripts": { 38 | "test": "mocha" 39 | }, 40 | "license": "MIT", 41 | "licenses": [ 42 | { 43 | "type": "The MIT License", 44 | "url": "http://www.opensource.org/licenses/mit-license.php" 45 | } 46 | ], 47 | "apidoc": { 48 | "title": "node-github", 49 | "name": "node-github", 50 | "template": { 51 | "withCompare": false 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /templates/test_handler.js.tpl: -------------------------------------------------------------------------------- 1 | it("should successfully execute <%name%>", function(next) { 2 | client.<%funcName%>( 3 | <%params%>, 4 | function(err, res) { 5 | Assert.equal(err, null); 6 | // other assertions go here 7 | next(); 8 | } 9 | ); 10 | }); -------------------------------------------------------------------------------- /templates/test_section.js.tpl: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 Cloud9 IDE, Inc. 3 | * 4 | * This product includes software developed by 5 | * Cloud9 IDE, Inc (http://c9.io). 6 | * 7 | * Author: Mike de Boer 8 | */ 9 | 10 | "use strict"; 11 | 12 | var Assert = require("assert"); 13 | var Client = require("./../lib/index"); 14 | var testAuth = require("./../testAuth.json"); 15 | 16 | describe("[<%sectionName%>]", function() { 17 | var client; 18 | var token = testAuth["token"]; 19 | 20 | beforeEach(function() { 21 | client = new Client(); 22 | client.authenticate({ 23 | type: "oauth", 24 | token: token 25 | }); 26 | }); 27 | 28 | <%testBody%> 29 | }); 30 | -------------------------------------------------------------------------------- /test/activityTest.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 Cloud9 IDE, Inc. 3 | * 4 | * This product includes software developed by 5 | * Cloud9 IDE, Inc (http://c9.io). 6 | * 7 | * Author: Mike de Boer 8 | */ 9 | 10 | "use strict"; 11 | 12 | var Assert = require("assert"); 13 | var Client = require("./../lib/index"); 14 | var testAuth = require("./../testAuth.json"); 15 | 16 | describe("[activity]", function() { 17 | var client; 18 | var token = testAuth["token"]; 19 | 20 | beforeEach(function() { 21 | client = new Client(); 22 | client.authenticate({ 23 | type: "oauth", 24 | token: token 25 | }); 26 | }); 27 | 28 | it("should successfully execute GET /notifications/threads/:id/subscription (checkNotificationThreadSubscription)", function(next) { 29 | client.activity.checkNotificationThreadSubscription( 30 | { 31 | id: "String" 32 | }, 33 | function(err, res) { 34 | Assert.equal(err, null); 35 | // other assertions go here 36 | next(); 37 | } 38 | ); 39 | }); 40 | 41 | it("should successfully execute GET /user/starred/:user/:repo (checkStarringRepo)", function(next) { 42 | client.activity.checkStarringRepo( 43 | { 44 | user: "String", 45 | repo: "String", 46 | page: "Number", 47 | per_page: "Number" 48 | }, 49 | function(err, res) { 50 | Assert.equal(err, null); 51 | // other assertions go here 52 | next(); 53 | } 54 | ); 55 | }); 56 | 57 | it("should successfully execute DELETE /notifications/threads/:id/subscription (deleteNotificationThreadSubscription)", function(next) { 58 | client.activity.deleteNotificationThreadSubscription( 59 | { 60 | id: "String" 61 | }, 62 | function(err, res) { 63 | Assert.equal(err, null); 64 | // other assertions go here 65 | next(); 66 | } 67 | ); 68 | }); 69 | 70 | it("should successfully execute GET /events (getEvents)", function(next) { 71 | client.activity.getEvents( 72 | { 73 | page: "Number", 74 | per_page: "Number" 75 | }, 76 | function(err, res) { 77 | Assert.equal(err, null); 78 | // other assertions go here 79 | next(); 80 | } 81 | ); 82 | }); 83 | 84 | it("should successfully execute GET /orgs/:org/events (getEventsForOrg)", function(next) { 85 | client.activity.getEventsForOrg( 86 | { 87 | org: "String", 88 | page: "Number", 89 | per_page: "Number" 90 | }, 91 | function(err, res) { 92 | Assert.equal(err, null); 93 | // other assertions go here 94 | next(); 95 | } 96 | ); 97 | }); 98 | 99 | it("should successfully execute GET /repos/:user/:repo/events (getEventsForRepo)", function(next) { 100 | client.activity.getEventsForRepo( 101 | { 102 | user: "String", 103 | repo: "String", 104 | page: "Number", 105 | per_page: "Number" 106 | }, 107 | function(err, res) { 108 | Assert.equal(err, null); 109 | // other assertions go here 110 | next(); 111 | } 112 | ); 113 | }); 114 | 115 | it("should successfully execute GET /repos/:user/:repo/issues/events (getEventsForRepoIssues)", function(next) { 116 | client.activity.getEventsForRepoIssues( 117 | { 118 | user: "String", 119 | repo: "String", 120 | page: "Number", 121 | per_page: "Number" 122 | }, 123 | function(err, res) { 124 | Assert.equal(err, null); 125 | // other assertions go here 126 | next(); 127 | } 128 | ); 129 | }); 130 | 131 | it("should successfully execute GET /networks/:user/:repo/events (getEventsForRepoNetwork)", function(next) { 132 | client.activity.getEventsForRepoNetwork( 133 | { 134 | user: "String", 135 | repo: "String", 136 | page: "Number", 137 | per_page: "Number" 138 | }, 139 | function(err, res) { 140 | Assert.equal(err, null); 141 | // other assertions go here 142 | next(); 143 | } 144 | ); 145 | }); 146 | 147 | it("should successfully execute GET /users/:user/events (getEventsForUser)", function(next) { 148 | client.activity.getEventsForUser( 149 | { 150 | user: "String", 151 | page: "Number", 152 | per_page: "Number" 153 | }, 154 | function(err, res) { 155 | Assert.equal(err, null); 156 | // other assertions go here 157 | next(); 158 | } 159 | ); 160 | }); 161 | 162 | it("should successfully execute GET /users/:user/events/orgs/:org (getEventsForUserOrg)", function(next) { 163 | client.activity.getEventsForUserOrg( 164 | { 165 | user: "String", 166 | org: "String", 167 | page: "Number", 168 | per_page: "Number" 169 | }, 170 | function(err, res) { 171 | Assert.equal(err, null); 172 | // other assertions go here 173 | next(); 174 | } 175 | ); 176 | }); 177 | 178 | it("should successfully execute GET /users/:user/events/public (getEventsForUserPublic)", function(next) { 179 | client.activity.getEventsForUserPublic( 180 | { 181 | user: "String", 182 | page: "Number", 183 | per_page: "Number" 184 | }, 185 | function(err, res) { 186 | Assert.equal(err, null); 187 | // other assertions go here 188 | next(); 189 | } 190 | ); 191 | }); 192 | 193 | it("should successfully execute GET /users/:user/received_events (getEventsReceived)", function(next) { 194 | client.activity.getEventsReceived( 195 | { 196 | user: "String", 197 | page: "Number", 198 | per_page: "Number" 199 | }, 200 | function(err, res) { 201 | Assert.equal(err, null); 202 | // other assertions go here 203 | next(); 204 | } 205 | ); 206 | }); 207 | 208 | it("should successfully execute GET /users/:user/received_events/public (getEventsReceivedPublic)", function(next) { 209 | client.activity.getEventsReceivedPublic( 210 | { 211 | user: "String", 212 | page: "Number", 213 | per_page: "Number" 214 | }, 215 | function(err, res) { 216 | Assert.equal(err, null); 217 | // other assertions go here 218 | next(); 219 | } 220 | ); 221 | }); 222 | 223 | it("should successfully execute GET /feeds (getFeeds)", function(next) { 224 | client.activity.getFeeds( 225 | {}, 226 | function(err, res) { 227 | Assert.equal(err, null); 228 | // other assertions go here 229 | next(); 230 | } 231 | ); 232 | }); 233 | 234 | it("should successfully execute GET /notifications/threads/:id (getNotificationThread)", function(next) { 235 | client.activity.getNotificationThread( 236 | { 237 | id: "String" 238 | }, 239 | function(err, res) { 240 | Assert.equal(err, null); 241 | // other assertions go here 242 | next(); 243 | } 244 | ); 245 | }); 246 | 247 | it("should successfully execute GET /notifications (getNotifications)", function(next) { 248 | client.activity.getNotifications( 249 | { 250 | all: "Boolean", 251 | participating: "Boolean", 252 | since: "Date", 253 | before: "String" 254 | }, 255 | function(err, res) { 256 | Assert.equal(err, null); 257 | // other assertions go here 258 | next(); 259 | } 260 | ); 261 | }); 262 | 263 | it("should successfully execute GET /repos/:user/:repo/notifications (getNotificationsForUser)", function(next) { 264 | client.activity.getNotificationsForUser( 265 | { 266 | user: "String", 267 | repo: "String", 268 | all: "Boolean", 269 | participating: "Boolean", 270 | since: "Date", 271 | before: "String" 272 | }, 273 | function(err, res) { 274 | Assert.equal(err, null); 275 | // other assertions go here 276 | next(); 277 | } 278 | ); 279 | }); 280 | 281 | it("should successfully execute GET /repos/:user/:repo/subscription (getRepoSubscription)", function(next) { 282 | client.activity.getRepoSubscription( 283 | { 284 | user: "String", 285 | repo: "String", 286 | page: "Number", 287 | per_page: "Number" 288 | }, 289 | function(err, res) { 290 | Assert.equal(err, null); 291 | // other assertions go here 292 | next(); 293 | } 294 | ); 295 | }); 296 | 297 | it("should successfully execute GET /repos/:user/:repo/stargazers (getStargazersForRepo)", function(next) { 298 | client.activity.getStargazersForRepo( 299 | { 300 | user: "String", 301 | repo: "String", 302 | page: "Number", 303 | per_page: "Number" 304 | }, 305 | function(err, res) { 306 | Assert.equal(err, null); 307 | // other assertions go here 308 | next(); 309 | } 310 | ); 311 | }); 312 | 313 | it("should successfully execute GET /user/starred (getStarredRepos)", function(next) { 314 | client.activity.getStarredRepos( 315 | { 316 | page: "Number", 317 | per_page: "Number" 318 | }, 319 | function(err, res) { 320 | Assert.equal(err, null); 321 | // other assertions go here 322 | next(); 323 | } 324 | ); 325 | }); 326 | 327 | it("should successfully execute GET /users/:user/starred (getStarredReposForUser)", function(next) { 328 | client.activity.getStarredReposForUser( 329 | { 330 | user: "String", 331 | page: "Number", 332 | per_page: "Number" 333 | }, 334 | function(err, res) { 335 | Assert.equal(err, null); 336 | // other assertions go here 337 | next(); 338 | } 339 | ); 340 | }); 341 | 342 | it("should successfully execute GET /user/subscriptions (getWatchedRepos)", function(next) { 343 | client.activity.getWatchedRepos( 344 | { 345 | page: "Number", 346 | per_page: "Number" 347 | }, 348 | function(err, res) { 349 | Assert.equal(err, null); 350 | // other assertions go here 351 | next(); 352 | } 353 | ); 354 | }); 355 | 356 | it("should successfully execute GET /users/:user/subscriptions (getWatchedReposForUser)", function(next) { 357 | client.activity.getWatchedReposForUser( 358 | { 359 | user: "String", 360 | page: "Number", 361 | per_page: "Number" 362 | }, 363 | function(err, res) { 364 | Assert.equal(err, null); 365 | // other assertions go here 366 | next(); 367 | } 368 | ); 369 | }); 370 | 371 | it("should successfully execute GET /repos/:user/:repo/subscribers (getWatchersForRepo)", function(next) { 372 | client.activity.getWatchersForRepo( 373 | { 374 | user: "String", 375 | repo: "String", 376 | page: "Number", 377 | per_page: "Number" 378 | }, 379 | function(err, res) { 380 | Assert.equal(err, null); 381 | // other assertions go here 382 | next(); 383 | } 384 | ); 385 | }); 386 | 387 | it("should successfully execute PATCH /notifications/threads/:id (markNotificationThreadAsRead)", function(next) { 388 | client.activity.markNotificationThreadAsRead( 389 | { 390 | id: "String" 391 | }, 392 | function(err, res) { 393 | Assert.equal(err, null); 394 | // other assertions go here 395 | next(); 396 | } 397 | ); 398 | }); 399 | 400 | it("should successfully execute PUT /notifications (markNotificationsAsRead)", function(next) { 401 | client.activity.markNotificationsAsRead( 402 | { 403 | last_read_at: "String" 404 | }, 405 | function(err, res) { 406 | Assert.equal(err, null); 407 | // other assertions go here 408 | next(); 409 | } 410 | ); 411 | }); 412 | 413 | it("should successfully execute PUT /repos/:user/:repo/notifications (markNotificationsAsReadForRepo)", function(next) { 414 | client.activity.markNotificationsAsReadForRepo( 415 | { 416 | last_read_at: "String" 417 | }, 418 | function(err, res) { 419 | Assert.equal(err, null); 420 | // other assertions go here 421 | next(); 422 | } 423 | ); 424 | }); 425 | 426 | it("should successfully execute PUT /notifications/threads/:id/subscription (setNotificationThreadSubscription)", function(next) { 427 | client.activity.setNotificationThreadSubscription( 428 | { 429 | id: "String", 430 | subscribed: "Boolean", 431 | ignored: "Boolean" 432 | }, 433 | function(err, res) { 434 | Assert.equal(err, null); 435 | // other assertions go here 436 | next(); 437 | } 438 | ); 439 | }); 440 | 441 | it("should successfully execute PUT /repos/:user/:repo/subscription (setRepoSubscription)", function(next) { 442 | client.activity.setRepoSubscription( 443 | { 444 | user: "String", 445 | repo: "String", 446 | subscribed: "Boolean", 447 | ignored: "Boolean" 448 | }, 449 | function(err, res) { 450 | Assert.equal(err, null); 451 | // other assertions go here 452 | next(); 453 | } 454 | ); 455 | }); 456 | 457 | it("should successfully execute PUT /user/starred/:user/:repo (starRepo)", function(next) { 458 | client.activity.starRepo( 459 | { 460 | user: "String", 461 | repo: "String" 462 | }, 463 | function(err, res) { 464 | Assert.equal(err, null); 465 | // other assertions go here 466 | next(); 467 | } 468 | ); 469 | }); 470 | 471 | it("should successfully execute DELETE /user/starred/:user/:repo (unstarRepo)", function(next) { 472 | client.activity.unstarRepo( 473 | { 474 | user: "String", 475 | repo: "String" 476 | }, 477 | function(err, res) { 478 | Assert.equal(err, null); 479 | // other assertions go here 480 | next(); 481 | } 482 | ); 483 | }); 484 | 485 | it("should successfully execute DELETE /repos/:user/:repo/subscription (unwatchRepo)", function(next) { 486 | client.activity.unwatchRepo( 487 | { 488 | user: "String", 489 | repo: "String" 490 | }, 491 | function(err, res) { 492 | Assert.equal(err, null); 493 | // other assertions go here 494 | next(); 495 | } 496 | ); 497 | }); 498 | }); 499 | -------------------------------------------------------------------------------- /test/allPagesTest.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 Cloud9 IDE, Inc. 3 | * 4 | * This product includes software developed by 5 | * Cloud9 IDE, Inc (http://c9.io). 6 | * 7 | * Author: Mike de Boer 8 | */ 9 | 10 | "use strict"; 11 | 12 | var Assert = require("assert"); 13 | var Client = require("./../lib/index"); 14 | var testAuth = require("./../testAuth.json"); 15 | 16 | describe("[all_pages]", function() { 17 | var client; 18 | var token = testAuth["token"]; 19 | 20 | beforeEach(function() { 21 | client = new Client(); 22 | client.authenticate({ 23 | type: "oauth", 24 | token: token 25 | }); 26 | }); 27 | 28 | it("should receive all the data of a given list", function(next) { 29 | this.timeout(8000) 30 | client.getAllPages(client.orgs.getTeamMembers, { 31 | id: '1660004' 32 | }, function (err, res) { 33 | Assert.equal(err, null); 34 | Assert.ok(Array.isArray(res)) 35 | console.log(res.length) 36 | Assert.ok(res.length > 200) 37 | next(); 38 | }) 39 | }); 40 | }); 41 | -------------------------------------------------------------------------------- /test/authorizationTest.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 Cloud9 IDE, Inc. 3 | * 4 | * This product includes software developed by 5 | * Cloud9 IDE, Inc (http://c9.io). 6 | * 7 | * Author: Mike de Boer 8 | */ 9 | 10 | "use strict"; 11 | 12 | var Assert = require("assert"); 13 | var Client = require("./../lib/index"); 14 | var testAuth = require("./../testAuth.json"); 15 | 16 | describe("[authorization]", function() { 17 | var client; 18 | var token = testAuth["token"]; 19 | 20 | beforeEach(function() { 21 | client = new Client(); 22 | client.authenticate({ 23 | type: "oauth", 24 | token: token 25 | }); 26 | }); 27 | 28 | it("should successfully execute POST /authorizations (create)", function(next) { 29 | client.authorization.create( 30 | { 31 | scopes: "Array", 32 | note: "String", 33 | note_url: "String" 34 | }, 35 | function(err, res) { 36 | Assert.equal(err, null); 37 | // other assertions go here 38 | next(); 39 | } 40 | ); 41 | }); 42 | 43 | it("should successfully execute DELETE /authorizations/:id (delete)", function(next) { 44 | client.authorization.delete( 45 | { 46 | id: "String" 47 | }, 48 | function(err, res) { 49 | Assert.equal(err, null); 50 | // other assertions go here 51 | next(); 52 | } 53 | ); 54 | }); 55 | 56 | it("should successfully execute GET /authorizations/:id (get)", function(next) { 57 | client.authorization.get( 58 | { 59 | id: "String" 60 | }, 61 | function(err, res) { 62 | Assert.equal(err, null); 63 | // other assertions go here 64 | next(); 65 | } 66 | ); 67 | }); 68 | 69 | it("should successfully execute GET /authorizations (getAll)", function(next) { 70 | client.authorization.getAll( 71 | { 72 | page: "Number", 73 | per_page: "Number" 74 | }, 75 | function(err, res) { 76 | Assert.equal(err, null); 77 | // other assertions go here 78 | next(); 79 | } 80 | ); 81 | }); 82 | 83 | it("should successfully execute PATCH /authorizations/:id (update)", function(next) { 84 | client.authorization.update( 85 | { 86 | id: "String", 87 | scopes: "Array", 88 | add_scopes: "Array", 89 | remove_scopes: "Array", 90 | note: "String", 91 | note_url: "String" 92 | }, 93 | function(err, res) { 94 | Assert.equal(err, null); 95 | // other assertions go here 96 | next(); 97 | } 98 | ); 99 | }); 100 | }); 101 | -------------------------------------------------------------------------------- /test/enterpriseTest.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 Cloud9 IDE, Inc. 3 | * 4 | * This product includes software developed by 5 | * Cloud9 IDE, Inc (http://c9.io). 6 | * 7 | * Author: Mike de Boer 8 | */ 9 | 10 | "use strict"; 11 | 12 | var Assert = require("assert"); 13 | var Client = require("./../lib/index"); 14 | var testAuth = require("./../testAuth.json"); 15 | 16 | describe("[enterprise]", function() { 17 | var client; 18 | var token = testAuth["token"]; 19 | 20 | beforeEach(function() { 21 | client = new Client(); 22 | client.authenticate({ 23 | type: "oauth", 24 | token: token 25 | }); 26 | }); 27 | 28 | it("should successfully execute POST /admin/organizations (createOrg)", function(next) { 29 | client.enterprise.createOrg( 30 | { 31 | login: "String", 32 | admin: "String", 33 | profile_name: "String" 34 | }, 35 | function(err, res) { 36 | Assert.equal(err, null); 37 | // other assertions go here 38 | next(); 39 | } 40 | ); 41 | }); 42 | 43 | it("should successfully execute GET /enterprise/settings/license (getLicense)", function(next) { 44 | client.enterprise.getLicense( 45 | {}, 46 | function(err, res) { 47 | Assert.equal(err, null); 48 | // other assertions go here 49 | next(); 50 | } 51 | ); 52 | }); 53 | 54 | it("should successfully execute GET /enterprise/stats/:type (stats)", function(next) { 55 | client.enterprise.stats( 56 | { 57 | type: "String" 58 | }, 59 | function(err, res) { 60 | Assert.equal(err, null); 61 | // other assertions go here 62 | next(); 63 | } 64 | ); 65 | }); 66 | 67 | it("should successfully execute POST /admin/ldap/teams/:team_id/sync (syncLdapForTeam)", function(next) { 68 | client.enterprise.syncLdapForTeam( 69 | { 70 | team_id: "Number" 71 | }, 72 | function(err, res) { 73 | Assert.equal(err, null); 74 | // other assertions go here 75 | next(); 76 | } 77 | ); 78 | }); 79 | 80 | it("should successfully execute POST /admin/ldap/users/:user/sync (syncLdapForUser)", function(next) { 81 | client.enterprise.syncLdapForUser( 82 | { 83 | user: "String" 84 | }, 85 | function(err, res) { 86 | Assert.equal(err, null); 87 | // other assertions go here 88 | next(); 89 | } 90 | ); 91 | }); 92 | 93 | it("should successfully execute PATCH /admin/ldap/teams/:team_id/mapping (updateLdapForTeam)", function(next) { 94 | client.enterprise.updateLdapForTeam( 95 | { 96 | team_id: "Number" 97 | }, 98 | function(err, res) { 99 | Assert.equal(err, null); 100 | // other assertions go here 101 | next(); 102 | } 103 | ); 104 | }); 105 | 106 | it("should successfully execute PATCH /admin/ldap/users/:user/mapping (updateLdapForUser)", function(next) { 107 | client.enterprise.updateLdapForUser( 108 | { 109 | user: "String" 110 | }, 111 | function(err, res) { 112 | Assert.equal(err, null); 113 | // other assertions go here 114 | next(); 115 | } 116 | ); 117 | }); 118 | }); 119 | -------------------------------------------------------------------------------- /test/gistsTest.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 Cloud9 IDE, Inc. 3 | * 4 | * This product includes software developed by 5 | * Cloud9 IDE, Inc (http://c9.io). 6 | * 7 | * Author: Mike de Boer 8 | */ 9 | 10 | "use strict"; 11 | 12 | var Assert = require("assert"); 13 | var Client = require("./../lib/index"); 14 | var testAuth = require("./../testAuth.json"); 15 | 16 | describe("[gists]", function() { 17 | var client; 18 | var token = testAuth["token"]; 19 | 20 | beforeEach(function() { 21 | client = new Client(); 22 | client.authenticate({ 23 | type: "oauth", 24 | token: token 25 | }); 26 | }); 27 | 28 | it("should successfully execute GET /gists/:id/star (checkStar)", function(next) { 29 | client.gists.checkStar( 30 | { 31 | id: "String" 32 | }, 33 | function(err, res) { 34 | Assert.equal(err, null); 35 | // other assertions go here 36 | next(); 37 | } 38 | ); 39 | }); 40 | 41 | it("should successfully execute POST /gists (create)", function(next) { 42 | client.gists.create( 43 | { 44 | files: "Json", 45 | description: "String", 46 | public: "Boolean" 47 | }, 48 | function(err, res) { 49 | Assert.equal(err, null); 50 | // other assertions go here 51 | next(); 52 | } 53 | ); 54 | }); 55 | 56 | it("should successfully execute POST /gists/:gist_id/comments (createComment)", function(next) { 57 | client.gists.createComment( 58 | { 59 | gist_id: "String", 60 | body: "String" 61 | }, 62 | function(err, res) { 63 | Assert.equal(err, null); 64 | // other assertions go here 65 | next(); 66 | } 67 | ); 68 | }); 69 | 70 | it("should successfully execute DELETE /gists/:id (delete)", function(next) { 71 | client.gists.delete( 72 | { 73 | id: "String" 74 | }, 75 | function(err, res) { 76 | Assert.equal(err, null); 77 | // other assertions go here 78 | next(); 79 | } 80 | ); 81 | }); 82 | 83 | it("should successfully execute DELETE /gists/:gist_id/comments/:id (deleteComment)", function(next) { 84 | client.gists.deleteComment( 85 | { 86 | gist_id: "String", 87 | id: "String" 88 | }, 89 | function(err, res) { 90 | Assert.equal(err, null); 91 | // other assertions go here 92 | next(); 93 | } 94 | ); 95 | }); 96 | 97 | it("should successfully execute PATCH /gists/:id (edit)", function(next) { 98 | client.gists.edit( 99 | { 100 | id: "String", 101 | description: "String", 102 | files: "Json" 103 | }, 104 | function(err, res) { 105 | Assert.equal(err, null); 106 | // other assertions go here 107 | next(); 108 | } 109 | ); 110 | }); 111 | 112 | it("should successfully execute PATCH /gists/:gist_id/comments/:id (editComment)", function(next) { 113 | client.gists.editComment( 114 | { 115 | gist_id: "String", 116 | id: "String", 117 | body: "String" 118 | }, 119 | function(err, res) { 120 | Assert.equal(err, null); 121 | // other assertions go here 122 | next(); 123 | } 124 | ); 125 | }); 126 | 127 | it("should successfully execute POST /gists/:id/forks (fork)", function(next) { 128 | client.gists.fork( 129 | { 130 | id: "String" 131 | }, 132 | function(err, res) { 133 | Assert.equal(err, null); 134 | // other assertions go here 135 | next(); 136 | } 137 | ); 138 | }); 139 | 140 | it("should successfully execute GET /gists/:id (get)", function(next) { 141 | client.gists.get( 142 | { 143 | id: "String" 144 | }, 145 | function(err, res) { 146 | Assert.equal(err, null); 147 | // other assertions go here 148 | next(); 149 | } 150 | ); 151 | }); 152 | 153 | it("should successfully execute GET /gists (getAll)", function(next) { 154 | client.gists.getAll( 155 | { 156 | page: "Number", 157 | per_page: "Number", 158 | since: "Date" 159 | }, 160 | function(err, res) { 161 | Assert.equal(err, null); 162 | // other assertions go here 163 | next(); 164 | } 165 | ); 166 | }); 167 | 168 | it("should successfully execute GET /gists/:gist_id/comments/:id (getComment)", function(next) { 169 | client.gists.getComment( 170 | { 171 | gist_id: "String", 172 | id: "String" 173 | }, 174 | function(err, res) { 175 | Assert.equal(err, null); 176 | // other assertions go here 177 | next(); 178 | } 179 | ); 180 | }); 181 | 182 | it("should successfully execute GET /gists/:gist_id/comments (getComments)", function(next) { 183 | client.gists.getComments( 184 | { 185 | gist_id: "String" 186 | }, 187 | function(err, res) { 188 | Assert.equal(err, null); 189 | // other assertions go here 190 | next(); 191 | } 192 | ); 193 | }); 194 | 195 | it("should successfully execute GET /gists/:id/commits (getCommits)", function(next) { 196 | client.gists.getCommits( 197 | { 198 | id: "String" 199 | }, 200 | function(err, res) { 201 | Assert.equal(err, null); 202 | // other assertions go here 203 | next(); 204 | } 205 | ); 206 | }); 207 | 208 | it("should successfully execute GET /users/:user/gists (getForUser)", function(next) { 209 | client.gists.getForUser( 210 | { 211 | user: "String", 212 | page: "Number", 213 | per_page: "Number", 214 | since: "Date" 215 | }, 216 | function(err, res) { 217 | Assert.equal(err, null); 218 | // other assertions go here 219 | next(); 220 | } 221 | ); 222 | }); 223 | 224 | it("should successfully execute GET /gists/:id/forks (getForks)", function(next) { 225 | client.gists.getForks( 226 | { 227 | id: "String", 228 | page: "Number", 229 | per_page: "Number" 230 | }, 231 | function(err, res) { 232 | Assert.equal(err, null); 233 | // other assertions go here 234 | next(); 235 | } 236 | ); 237 | }); 238 | 239 | it("should successfully execute GET /gists/public (getPublic)", function(next) { 240 | client.gists.getPublic( 241 | { 242 | since: "Date" 243 | }, 244 | function(err, res) { 245 | Assert.equal(err, null); 246 | // other assertions go here 247 | next(); 248 | } 249 | ); 250 | }); 251 | 252 | it("should successfully execute GET /gists/:id/:sha (getRevision)", function(next) { 253 | client.gists.getRevision( 254 | { 255 | id: "String", 256 | sha: "String" 257 | }, 258 | function(err, res) { 259 | Assert.equal(err, null); 260 | // other assertions go here 261 | next(); 262 | } 263 | ); 264 | }); 265 | 266 | it("should successfully execute GET /gists/starred (getStarred)", function(next) { 267 | client.gists.getStarred( 268 | { 269 | since: "Date" 270 | }, 271 | function(err, res) { 272 | Assert.equal(err, null); 273 | // other assertions go here 274 | next(); 275 | } 276 | ); 277 | }); 278 | 279 | it("should successfully execute PUT /gists/:id/star (star)", function(next) { 280 | client.gists.star( 281 | { 282 | id: "String" 283 | }, 284 | function(err, res) { 285 | Assert.equal(err, null); 286 | // other assertions go here 287 | next(); 288 | } 289 | ); 290 | }); 291 | 292 | it("should successfully execute DELETE /gists/:id/star (unstar)", function(next) { 293 | client.gists.unstar( 294 | { 295 | id: "String" 296 | }, 297 | function(err, res) { 298 | Assert.equal(err, null); 299 | // other assertions go here 300 | next(); 301 | } 302 | ); 303 | }); 304 | }); 305 | -------------------------------------------------------------------------------- /test/gitdataTest.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 Cloud9 IDE, Inc. 3 | * 4 | * This product includes software developed by 5 | * Cloud9 IDE, Inc (http://c9.io). 6 | * 7 | * Author: Mike de Boer 8 | */ 9 | 10 | "use strict"; 11 | 12 | var Assert = require("assert"); 13 | var Client = require("./../lib/index"); 14 | var testAuth = require("./../testAuth.json"); 15 | 16 | describe("[gitdata]", function() { 17 | var client; 18 | var token = testAuth["token"]; 19 | 20 | beforeEach(function() { 21 | client = new Client(); 22 | client.authenticate({ 23 | type: "oauth", 24 | token: token 25 | }); 26 | }); 27 | 28 | it("should successfully execute POST /repos/:user/:repo/git/blobs (createBlob)", function(next) { 29 | client.gitdata.createBlob( 30 | { 31 | user: "String", 32 | repo: "String", 33 | content: "String", 34 | encoding: "String" 35 | }, 36 | function(err, res) { 37 | Assert.equal(err, null); 38 | // other assertions go here 39 | next(); 40 | } 41 | ); 42 | }); 43 | 44 | it("should successfully execute POST /repos/:user/:repo/git/commits (createCommit)", function(next) { 45 | client.gitdata.createCommit( 46 | { 47 | user: "String", 48 | repo: "String", 49 | message: "String", 50 | tree: "String", 51 | parents: "Array", 52 | author: "Json", 53 | committer: "Json" 54 | }, 55 | function(err, res) { 56 | Assert.equal(err, null); 57 | // other assertions go here 58 | next(); 59 | } 60 | ); 61 | }); 62 | 63 | it("should successfully execute POST /repos/:user/:repo/git/refs (createReference)", function(next) { 64 | client.gitdata.createReference( 65 | { 66 | user: "String", 67 | repo: "String", 68 | ref: "String", 69 | sha: "String" 70 | }, 71 | function(err, res) { 72 | Assert.equal(err, null); 73 | // other assertions go here 74 | next(); 75 | } 76 | ); 77 | }); 78 | 79 | it("should successfully execute POST /repos/:user/:repo/git/tags (createTag)", function(next) { 80 | client.gitdata.createTag( 81 | { 82 | user: "String", 83 | repo: "String", 84 | tag: "String", 85 | message: "String", 86 | object: "String", 87 | type: "String", 88 | tagger: "Json" 89 | }, 90 | function(err, res) { 91 | Assert.equal(err, null); 92 | // other assertions go here 93 | next(); 94 | } 95 | ); 96 | }); 97 | 98 | it("should successfully execute POST /repos/:user/:repo/git/trees (createTree)", function(next) { 99 | client.gitdata.createTree( 100 | { 101 | user: "String", 102 | repo: "String", 103 | tree: "Json", 104 | base_tree: "String" 105 | }, 106 | function(err, res) { 107 | Assert.equal(err, null); 108 | // other assertions go here 109 | next(); 110 | } 111 | ); 112 | }); 113 | 114 | it("should successfully execute DELETE /repos/:user/:repo/git/refs/:ref (deleteReference)", function(next) { 115 | client.gitdata.deleteReference( 116 | { 117 | user: "String", 118 | repo: "String", 119 | ref: "String" 120 | }, 121 | function(err, res) { 122 | Assert.equal(err, null); 123 | // other assertions go here 124 | next(); 125 | } 126 | ); 127 | }); 128 | 129 | it("should successfully execute GET /repos/:user/:repo/git/blobs/:sha (getBlob)", function(next) { 130 | client.gitdata.getBlob( 131 | { 132 | user: "String", 133 | repo: "String", 134 | sha: "String", 135 | page: "Number", 136 | per_page: "Number" 137 | }, 138 | function(err, res) { 139 | Assert.equal(err, null); 140 | // other assertions go here 141 | next(); 142 | } 143 | ); 144 | }); 145 | 146 | it("should successfully execute GET /repos/:user/:repo/git/commits/:sha (getCommit)", function(next) { 147 | client.gitdata.getCommit( 148 | { 149 | user: "String", 150 | repo: "String", 151 | sha: "String" 152 | }, 153 | function(err, res) { 154 | Assert.equal(err, null); 155 | // other assertions go here 156 | next(); 157 | } 158 | ); 159 | }); 160 | 161 | it("should successfully execute GET /repos/:user/:repo/git/refs/:ref (getReference)", function(next) { 162 | client.gitdata.getReference( 163 | { 164 | user: "String", 165 | repo: "String", 166 | ref: "String" 167 | }, 168 | function(err, res) { 169 | Assert.equal(err, null); 170 | // other assertions go here 171 | next(); 172 | } 173 | ); 174 | }); 175 | 176 | it("should successfully execute GET /repos/:user/:repo/git/refs (getReferences)", function(next) { 177 | client.gitdata.getReferences( 178 | { 179 | user: "String", 180 | repo: "String", 181 | page: "Number", 182 | per_page: "Number" 183 | }, 184 | function(err, res) { 185 | Assert.equal(err, null); 186 | // other assertions go here 187 | next(); 188 | } 189 | ); 190 | }); 191 | 192 | it("should successfully execute GET /repos/:user/:repo/git/tags/:sha (getTag)", function(next) { 193 | client.gitdata.getTag( 194 | { 195 | user: "String", 196 | repo: "String", 197 | sha: "String" 198 | }, 199 | function(err, res) { 200 | Assert.equal(err, null); 201 | // other assertions go here 202 | next(); 203 | } 204 | ); 205 | }); 206 | 207 | it("should successfully execute GET /repos/:user/:repo/git/refs/tags (getTags)", function(next) { 208 | client.gitdata.getTags( 209 | { 210 | user: "String", 211 | repo: "String", 212 | page: "Number", 213 | per_page: "Number" 214 | }, 215 | function(err, res) { 216 | Assert.equal(err, null); 217 | // other assertions go here 218 | next(); 219 | } 220 | ); 221 | }); 222 | 223 | it("should successfully execute GET /repos/:user/:repo/git/trees/:sha (getTree)", function(next) { 224 | client.gitdata.getTree( 225 | { 226 | user: "String", 227 | repo: "String", 228 | sha: "String", 229 | recursive: "Boolean" 230 | }, 231 | function(err, res) { 232 | Assert.equal(err, null); 233 | // other assertions go here 234 | next(); 235 | } 236 | ); 237 | }); 238 | 239 | it("should successfully execute PATCH /repos/:user/:repo/git/refs/:ref (updateReference)", function(next) { 240 | client.gitdata.updateReference( 241 | { 242 | user: "String", 243 | repo: "String", 244 | ref: "String", 245 | sha: "String", 246 | force: "Boolean" 247 | }, 248 | function(err, res) { 249 | Assert.equal(err, null); 250 | // other assertions go here 251 | next(); 252 | } 253 | ); 254 | }); 255 | }); 256 | -------------------------------------------------------------------------------- /test/issuesTest.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 Cloud9 IDE, Inc. 3 | * 4 | * This product includes software developed by 5 | * Cloud9 IDE, Inc (http://c9.io). 6 | * 7 | * Author: Mike de Boer 8 | */ 9 | 10 | "use strict"; 11 | 12 | var Assert = require("assert"); 13 | var Client = require("./../lib/index"); 14 | var testAuth = require("./../testAuth.json"); 15 | 16 | describe("[issues]", function() { 17 | var client; 18 | var token = testAuth["token"]; 19 | 20 | beforeEach(function() { 21 | client = new Client(); 22 | client.authenticate({ 23 | type: "oauth", 24 | token: token 25 | }); 26 | }); 27 | 28 | it("should successfully execute POST /repos/:user/:repo/issues/:number/labels (addLabels)", function(next) { 29 | client.issues.addLabels( 30 | { 31 | user: "String", 32 | repo: "String", 33 | number: "Number", 34 | body: "Array" 35 | }, 36 | function(err, res) { 37 | Assert.equal(err, null); 38 | // other assertions go here 39 | next(); 40 | } 41 | ); 42 | }); 43 | 44 | it("should successfully execute GET /repos/:user/:repo/assignees/:assignee (checkAssignee)", function(next) { 45 | client.issues.checkAssignee( 46 | { 47 | user: "String", 48 | repo: "String", 49 | assignee: "String" 50 | }, 51 | function(err, res) { 52 | Assert.equal(err, null); 53 | // other assertions go here 54 | next(); 55 | } 56 | ); 57 | }); 58 | 59 | it("should successfully execute POST /repos/:user/:repo/issues (create)", function(next) { 60 | client.issues.create( 61 | { 62 | user: "String", 63 | repo: "String", 64 | title: "String", 65 | body: "String", 66 | assignee: "String", 67 | milestone: "Number", 68 | labels: "Json" 69 | }, 70 | function(err, res) { 71 | Assert.equal(err, null); 72 | // other assertions go here 73 | next(); 74 | } 75 | ); 76 | }); 77 | 78 | it("should successfully execute POST /repos/:user/:repo/issues/:number/comments (createComment)", function(next) { 79 | client.issues.createComment( 80 | { 81 | user: "String", 82 | repo: "String", 83 | number: "Number", 84 | body: "String" 85 | }, 86 | function(err, res) { 87 | Assert.equal(err, null); 88 | // other assertions go here 89 | next(); 90 | } 91 | ); 92 | }); 93 | 94 | it("should successfully execute POST /repos/:user/:repo/labels (createLabel)", function(next) { 95 | client.issues.createLabel( 96 | { 97 | user: "String", 98 | repo: "String", 99 | name: "String", 100 | color: "String" 101 | }, 102 | function(err, res) { 103 | Assert.equal(err, null); 104 | // other assertions go here 105 | next(); 106 | } 107 | ); 108 | }); 109 | 110 | it("should successfully execute POST /repos/:user/:repo/milestones (createMilestone)", function(next) { 111 | client.issues.createMilestone( 112 | { 113 | user: "String", 114 | repo: "String", 115 | title: "String", 116 | state: "String", 117 | description: "String", 118 | due_on: "Date" 119 | }, 120 | function(err, res) { 121 | Assert.equal(err, null); 122 | // other assertions go here 123 | next(); 124 | } 125 | ); 126 | }); 127 | 128 | it("should successfully execute DELETE /repos/:user/:repo/issues/comments/:id (deleteComment)", function(next) { 129 | client.issues.deleteComment( 130 | { 131 | user: "String", 132 | repo: "String", 133 | id: "String" 134 | }, 135 | function(err, res) { 136 | Assert.equal(err, null); 137 | // other assertions go here 138 | next(); 139 | } 140 | ); 141 | }); 142 | 143 | it("should successfully execute DELETE /repos/:user/:repo/labels/:name (deleteLabel)", function(next) { 144 | client.issues.deleteLabel( 145 | { 146 | user: "String", 147 | repo: "String", 148 | name: "String" 149 | }, 150 | function(err, res) { 151 | Assert.equal(err, null); 152 | // other assertions go here 153 | next(); 154 | } 155 | ); 156 | }); 157 | 158 | it("should successfully execute DELETE /repos/:user/:repo/milestones/:number (deleteMilestone)", function(next) { 159 | client.issues.deleteMilestone( 160 | { 161 | user: "String", 162 | repo: "String", 163 | number: "Number" 164 | }, 165 | function(err, res) { 166 | Assert.equal(err, null); 167 | // other assertions go here 168 | next(); 169 | } 170 | ); 171 | }); 172 | 173 | it("should successfully execute PATCH /repos/:user/:repo/issues/:number (edit)", function(next) { 174 | client.issues.edit( 175 | { 176 | user: "String", 177 | repo: "String", 178 | number: "Number", 179 | title: "String", 180 | body: "String", 181 | assignee: "String", 182 | milestone: "Number", 183 | labels: "Json", 184 | state: "String" 185 | }, 186 | function(err, res) { 187 | Assert.equal(err, null); 188 | // other assertions go here 189 | next(); 190 | } 191 | ); 192 | }); 193 | 194 | it("should successfully execute PATCH /repos/:user/:repo/issues/comments/:id (editComment)", function(next) { 195 | client.issues.editComment( 196 | { 197 | user: "String", 198 | repo: "String", 199 | id: "String", 200 | body: "String" 201 | }, 202 | function(err, res) { 203 | Assert.equal(err, null); 204 | // other assertions go here 205 | next(); 206 | } 207 | ); 208 | }); 209 | 210 | it("should successfully execute GET /repos/:user/:repo/issues/:number (get)", function(next) { 211 | client.issues.get( 212 | { 213 | user: "String", 214 | repo: "String", 215 | number: "Number" 216 | }, 217 | function(err, res) { 218 | Assert.equal(err, null); 219 | // other assertions go here 220 | next(); 221 | } 222 | ); 223 | }); 224 | 225 | it("should successfully execute GET /issues (getAll)", function(next) { 226 | client.issues.getAll( 227 | { 228 | filter: "String", 229 | state: "String", 230 | labels: "String", 231 | sort: "String", 232 | direction: "String", 233 | since: "Date", 234 | page: "Number", 235 | per_page: "Number" 236 | }, 237 | function(err, res) { 238 | Assert.equal(err, null); 239 | // other assertions go here 240 | next(); 241 | } 242 | ); 243 | }); 244 | 245 | it("should successfully execute GET /repos/:user/:repo/assignees (getAssignees)", function(next) { 246 | client.issues.getAssignees( 247 | { 248 | user: "String", 249 | repo: "String" 250 | }, 251 | function(err, res) { 252 | Assert.equal(err, null); 253 | // other assertions go here 254 | next(); 255 | } 256 | ); 257 | }); 258 | 259 | it("should successfully execute GET /repos/:user/:repo/issues/comments/:id (getComment)", function(next) { 260 | client.issues.getComment( 261 | { 262 | user: "String", 263 | repo: "String", 264 | id: "String" 265 | }, 266 | function(err, res) { 267 | Assert.equal(err, null); 268 | // other assertions go here 269 | next(); 270 | } 271 | ); 272 | }); 273 | 274 | it("should successfully execute GET /repos/:user/:repo/issues/:number/comments (getComments)", function(next) { 275 | client.issues.getComments( 276 | { 277 | user: "String", 278 | repo: "String", 279 | number: "Number", 280 | page: "Number", 281 | per_page: "Number" 282 | }, 283 | function(err, res) { 284 | Assert.equal(err, null); 285 | // other assertions go here 286 | next(); 287 | } 288 | ); 289 | }); 290 | 291 | it("should successfully execute GET /repos/:user/:repo/issues/comments (getCommentsForRepo)", function(next) { 292 | client.issues.getCommentsForRepo( 293 | { 294 | user: "String", 295 | repo: "String", 296 | sort: "String", 297 | direction: "String", 298 | since: "Date", 299 | page: "Number", 300 | per_page: "Number" 301 | }, 302 | function(err, res) { 303 | Assert.equal(err, null); 304 | // other assertions go here 305 | next(); 306 | } 307 | ); 308 | }); 309 | 310 | it("should successfully execute GET /repos/:user/:repo/issues/events/:id (getEvent)", function(next) { 311 | client.issues.getEvent( 312 | { 313 | user: "String", 314 | repo: "String", 315 | id: "String" 316 | }, 317 | function(err, res) { 318 | Assert.equal(err, null); 319 | // other assertions go here 320 | next(); 321 | } 322 | ); 323 | }); 324 | 325 | it("should successfully execute GET /repos/:user/:repo/issues/:number/events (getEvents)", function(next) { 326 | client.issues.getEvents( 327 | { 328 | user: "String", 329 | repo: "String", 330 | number: "Number", 331 | page: "Number", 332 | per_page: "Number" 333 | }, 334 | function(err, res) { 335 | Assert.equal(err, null); 336 | // other assertions go here 337 | next(); 338 | } 339 | ); 340 | }); 341 | 342 | it("should successfully execute GET /repos/:user/:repo/issues/events (getEventsForRepo)", function(next) { 343 | client.issues.getEventsForRepo( 344 | { 345 | user: "String", 346 | repo: "String", 347 | page: "Number", 348 | per_page: "Number" 349 | }, 350 | function(err, res) { 351 | Assert.equal(err, null); 352 | // other assertions go here 353 | next(); 354 | } 355 | ); 356 | }); 357 | 358 | it("should successfully execute GET /orgs/:org/issues (getForOrg)", function(next) { 359 | client.issues.getForOrg( 360 | { 361 | filter: "String", 362 | state: "String", 363 | labels: "String", 364 | sort: "String", 365 | direction: "String", 366 | since: "Date", 367 | page: "Number", 368 | per_page: "Number" 369 | }, 370 | function(err, res) { 371 | Assert.equal(err, null); 372 | // other assertions go here 373 | next(); 374 | } 375 | ); 376 | }); 377 | 378 | it("should successfully execute GET /repos/:user/:repo/issues (getForRepo)", function(next) { 379 | client.issues.getForRepo( 380 | { 381 | user: "String", 382 | repo: "String", 383 | milestone: "String", 384 | state: "String", 385 | assignee: "String", 386 | creator: "String", 387 | mentioned: "String", 388 | labels: "String", 389 | sort: "String", 390 | direction: "String", 391 | since: "Date", 392 | page: "Number", 393 | per_page: "Number" 394 | }, 395 | function(err, res) { 396 | Assert.equal(err, null); 397 | // other assertions go here 398 | next(); 399 | } 400 | ); 401 | }); 402 | 403 | it("should successfully execute GET /user/issues (getForUser)", function(next) { 404 | client.issues.getForUser( 405 | { 406 | filter: "String", 407 | state: "String", 408 | labels: "String", 409 | sort: "String", 410 | direction: "String", 411 | since: "Date", 412 | page: "Number", 413 | per_page: "Number" 414 | }, 415 | function(err, res) { 416 | Assert.equal(err, null); 417 | // other assertions go here 418 | next(); 419 | } 420 | ); 421 | }); 422 | 423 | it("should successfully execute GET /repos/:user/:repo/issues/:number/labels (getIssueLabels)", function(next) { 424 | client.issues.getIssueLabels( 425 | { 426 | user: "String", 427 | repo: "String", 428 | number: "Number" 429 | }, 430 | function(err, res) { 431 | Assert.equal(err, null); 432 | // other assertions go here 433 | next(); 434 | } 435 | ); 436 | }); 437 | 438 | it("should successfully execute GET /repos/:user/:repo/labels/:name (getLabel)", function(next) { 439 | client.issues.getLabel( 440 | { 441 | user: "String", 442 | repo: "String", 443 | name: "String" 444 | }, 445 | function(err, res) { 446 | Assert.equal(err, null); 447 | // other assertions go here 448 | next(); 449 | } 450 | ); 451 | }); 452 | 453 | it("should successfully execute GET /repos/:user/:repo/labels (getLabels)", function(next) { 454 | client.issues.getLabels( 455 | { 456 | user: "String", 457 | repo: "String", 458 | page: "Number", 459 | per_page: "Number" 460 | }, 461 | function(err, res) { 462 | Assert.equal(err, null); 463 | // other assertions go here 464 | next(); 465 | } 466 | ); 467 | }); 468 | 469 | it("should successfully execute GET /repos/:user/:repo/milestones/:number (getMilestone)", function(next) { 470 | client.issues.getMilestone( 471 | { 472 | user: "String", 473 | repo: "String", 474 | number: "Number" 475 | }, 476 | function(err, res) { 477 | Assert.equal(err, null); 478 | // other assertions go here 479 | next(); 480 | } 481 | ); 482 | }); 483 | 484 | it("should successfully execute GET /repos/:user/:repo/milestones/:number/labels (getMilestoneLabels)", function(next) { 485 | client.issues.getMilestoneLabels( 486 | { 487 | user: "String", 488 | repo: "String", 489 | number: "Number" 490 | }, 491 | function(err, res) { 492 | Assert.equal(err, null); 493 | // other assertions go here 494 | next(); 495 | } 496 | ); 497 | }); 498 | 499 | it("should successfully execute GET /repos/:user/:repo/milestones (getMilestones)", function(next) { 500 | client.issues.getMilestones( 501 | { 502 | user: "String", 503 | repo: "String", 504 | state: "String", 505 | sort: "String", 506 | direction: "String", 507 | page: "Number", 508 | per_page: "Number" 509 | }, 510 | function(err, res) { 511 | Assert.equal(err, null); 512 | // other assertions go here 513 | next(); 514 | } 515 | ); 516 | }); 517 | 518 | it("should successfully execute DELETE /repos/:user/:repo/issues/:number/labels (removeAllLabels)", function(next) { 519 | client.issues.removeAllLabels( 520 | { 521 | user: "String", 522 | repo: "String", 523 | number: "Number" 524 | }, 525 | function(err, res) { 526 | Assert.equal(err, null); 527 | // other assertions go here 528 | next(); 529 | } 530 | ); 531 | }); 532 | 533 | it("should successfully execute DELETE /repos/:user/:repo/issues/:number/labels/:name (removeLabel)", function(next) { 534 | client.issues.removeLabel( 535 | { 536 | user: "String", 537 | repo: "String", 538 | number: "Number", 539 | name: "String" 540 | }, 541 | function(err, res) { 542 | Assert.equal(err, null); 543 | // other assertions go here 544 | next(); 545 | } 546 | ); 547 | }); 548 | 549 | it("should successfully execute PUT /repos/:user/:repo/issues/:number/labels (replaceAllLabels)", function(next) { 550 | client.issues.replaceAllLabels( 551 | { 552 | user: "String", 553 | repo: "String", 554 | number: "Number", 555 | body: "Array" 556 | }, 557 | function(err, res) { 558 | Assert.equal(err, null); 559 | // other assertions go here 560 | next(); 561 | } 562 | ); 563 | }); 564 | 565 | it("should successfully execute PATCH /repos/:user/:repo/labels/:name (updateLabel)", function(next) { 566 | client.issues.updateLabel( 567 | { 568 | user: "String", 569 | repo: "String", 570 | name: "String", 571 | color: "String" 572 | }, 573 | function(err, res) { 574 | Assert.equal(err, null); 575 | // other assertions go here 576 | next(); 577 | } 578 | ); 579 | }); 580 | 581 | it("should successfully execute PATCH /repos/:user/:repo/milestones/:number (updateMilestone)", function(next) { 582 | client.issues.updateMilestone( 583 | { 584 | user: "String", 585 | repo: "String", 586 | number: "Number", 587 | title: "String", 588 | state: "String", 589 | description: "String", 590 | due_on: "Date" 591 | }, 592 | function(err, res) { 593 | Assert.equal(err, null); 594 | // other assertions go here 595 | next(); 596 | } 597 | ); 598 | }); 599 | }); 600 | -------------------------------------------------------------------------------- /test/miscTest.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 Cloud9 IDE, Inc. 3 | * 4 | * This product includes software developed by 5 | * Cloud9 IDE, Inc (http://c9.io). 6 | * 7 | * Author: Mike de Boer 8 | */ 9 | 10 | "use strict"; 11 | 12 | var Assert = require("assert"); 13 | var Client = require("./../lib/index"); 14 | var testAuth = require("./../testAuth.json"); 15 | 16 | describe("[misc]", function() { 17 | var client; 18 | var token = testAuth["token"]; 19 | 20 | beforeEach(function() { 21 | client = new Client(); 22 | client.authenticate({ 23 | type: "oauth", 24 | token: token 25 | }); 26 | }); 27 | 28 | it("should successfully execute GET /emojis (getEmojis)", function(next) { 29 | client.misc.getEmojis( 30 | {}, 31 | function(err, res) { 32 | Assert.equal(err, null); 33 | // other assertions go here 34 | next(); 35 | } 36 | ); 37 | }); 38 | 39 | it("should successfully execute GET /gitignore/templates/:name (getGitignoreTemplate)", function(next) { 40 | client.misc.getGitignoreTemplate( 41 | { 42 | name: "String" 43 | }, 44 | function(err, res) { 45 | Assert.equal(err, null); 46 | // other assertions go here 47 | next(); 48 | } 49 | ); 50 | }); 51 | 52 | it("should successfully execute GET /gitignore/templates (getGitignoreTemplates)", function(next) { 53 | client.misc.getGitignoreTemplates( 54 | {}, 55 | function(err, res) { 56 | Assert.equal(err, null); 57 | // other assertions go here 58 | next(); 59 | } 60 | ); 61 | }); 62 | 63 | it("should successfully execute GET /licenses/:license (getLicense)", function(next) { 64 | client.misc.getLicense( 65 | { 66 | license: "String" 67 | }, 68 | function(err, res) { 69 | Assert.equal(err, null); 70 | // other assertions go here 71 | next(); 72 | } 73 | ); 74 | }); 75 | 76 | it("should successfully execute GET /licenses (getLicenses)", function(next) { 77 | client.misc.getLicenses( 78 | {}, 79 | function(err, res) { 80 | Assert.equal(err, null); 81 | // other assertions go here 82 | next(); 83 | } 84 | ); 85 | }); 86 | 87 | it("should successfully execute GET /meta (getMeta)", function(next) { 88 | client.misc.getMeta( 89 | {}, 90 | function(err, res) { 91 | Assert.equal(err, null); 92 | // other assertions go here 93 | next(); 94 | } 95 | ); 96 | }); 97 | 98 | it("should successfully execute GET /rate_limit (getRateLimit)", function(next) { 99 | client.misc.getRateLimit( 100 | {}, 101 | function(err, res) { 102 | Assert.equal(err, null); 103 | // other assertions go here 104 | next(); 105 | } 106 | ); 107 | }); 108 | 109 | it("should successfully execute GET /repos/:user/:repo/license (getRepoLicense)", function(next) { 110 | client.misc.getRepoLicense( 111 | { 112 | user: "String", 113 | repo: "String" 114 | }, 115 | function(err, res) { 116 | Assert.equal(err, null); 117 | // other assertions go here 118 | next(); 119 | } 120 | ); 121 | }); 122 | 123 | it("should successfully execute POST /markdown (renderMarkdown)", function(next) { 124 | client.misc.renderMarkdown( 125 | { 126 | text: "String", 127 | mode: "String", 128 | context: "String" 129 | }, 130 | function(err, res) { 131 | Assert.equal(err, null); 132 | // other assertions go here 133 | next(); 134 | } 135 | ); 136 | }); 137 | 138 | it("should successfully execute POST /markdown/raw (renderMarkdownRaw)", function(next) { 139 | client.misc.renderMarkdownRaw( 140 | { 141 | data: "String" 142 | }, 143 | function(err, res) { 144 | Assert.equal(err, null); 145 | // other assertions go here 146 | next(); 147 | } 148 | ); 149 | }); 150 | }); 151 | -------------------------------------------------------------------------------- /test/orgsTest.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 Cloud9 IDE, Inc. 3 | * 4 | * This product includes software developed by 5 | * Cloud9 IDE, Inc (http://c9.io). 6 | * 7 | * Author: Mike de Boer 8 | */ 9 | 10 | "use strict"; 11 | 12 | var Assert = require("assert"); 13 | var Client = require("./../lib/index"); 14 | var testAuth = require("./../testAuth.json"); 15 | 16 | describe("[orgs]", function() { 17 | var client; 18 | var token = testAuth["token"]; 19 | 20 | beforeEach(function() { 21 | client = new Client(); 22 | client.authenticate({ 23 | type: "oauth", 24 | token: token 25 | }); 26 | }); 27 | 28 | it("should successfully execute PUT /orgs/:org/memberships/:user (addOrganizationMembership)", function(next) { 29 | client.orgs.addOrganizationMembership( 30 | { 31 | org: "String", 32 | user: "String", 33 | role: "String" 34 | }, 35 | function(err, res) { 36 | Assert.equal(err, null); 37 | // other assertions go here 38 | next(); 39 | } 40 | ); 41 | }); 42 | 43 | it("should successfully execute PUT /teams/:id/memberships/:user (addTeamMembership)", function(next) { 44 | client.orgs.addTeamMembership( 45 | { 46 | id: "String", 47 | user: "String", 48 | role: "String" 49 | }, 50 | function(err, res) { 51 | Assert.equal(err, null); 52 | // other assertions go here 53 | next(); 54 | } 55 | ); 56 | }); 57 | 58 | it("should successfully execute PUT /teams/:id/repos/:user/:repo (addTeamRepo)", function(next) { 59 | client.orgs.addTeamRepo( 60 | { 61 | id: "String", 62 | user: "String", 63 | repo: "String" 64 | }, 65 | function(err, res) { 66 | Assert.equal(err, null); 67 | // other assertions go here 68 | next(); 69 | } 70 | ); 71 | }); 72 | 73 | it("should successfully execute GET /orgs/:org/members/:user (checkMembership)", function(next) { 74 | client.orgs.checkMembership( 75 | { 76 | org: "String", 77 | user: "String" 78 | }, 79 | function(err, res) { 80 | Assert.equal(err, null); 81 | // other assertions go here 82 | next(); 83 | } 84 | ); 85 | }); 86 | 87 | it("should successfully execute GET /orgs/:org/public_members/:user (checkPublicMembership)", function(next) { 88 | client.orgs.checkPublicMembership( 89 | { 90 | org: "String", 91 | user: "String" 92 | }, 93 | function(err, res) { 94 | Assert.equal(err, null); 95 | // other assertions go here 96 | next(); 97 | } 98 | ); 99 | }); 100 | 101 | it("should successfully execute GET /teams/:id/repos/:user/:repo (checkTeamRepo)", function(next) { 102 | client.orgs.checkTeamRepo( 103 | { 104 | id: "String", 105 | user: "String", 106 | repo: "String" 107 | }, 108 | function(err, res) { 109 | Assert.equal(err, null); 110 | // other assertions go here 111 | next(); 112 | } 113 | ); 114 | }); 115 | 116 | it("should successfully execute DELETE /orgs/:org/public_members/:user (concealMembership)", function(next) { 117 | client.orgs.concealMembership( 118 | { 119 | org: "String", 120 | user: "String" 121 | }, 122 | function(err, res) { 123 | Assert.equal(err, null); 124 | // other assertions go here 125 | next(); 126 | } 127 | ); 128 | }); 129 | 130 | it("should successfully execute POST /orgs/:org/hooks (createHook)", function(next) { 131 | client.orgs.createHook( 132 | { 133 | org: "String", 134 | name: "String", 135 | config: "Json", 136 | events: "Array", 137 | active: "Boolean" 138 | }, 139 | function(err, res) { 140 | Assert.equal(err, null); 141 | // other assertions go here 142 | next(); 143 | } 144 | ); 145 | }); 146 | 147 | it("should successfully execute POST /orgs/:org/teams (createTeam)", function(next) { 148 | client.orgs.createTeam( 149 | { 150 | org: "String", 151 | name: "String", 152 | description: "String", 153 | repo_names: "Array", 154 | privacy: "String" 155 | }, 156 | function(err, res) { 157 | Assert.equal(err, null); 158 | // other assertions go here 159 | next(); 160 | } 161 | ); 162 | }); 163 | 164 | it("should successfully execute DELETE /orgs/:org/hooks/:id (deleteHook)", function(next) { 165 | client.orgs.deleteHook( 166 | { 167 | org: "String", 168 | id: "String" 169 | }, 170 | function(err, res) { 171 | Assert.equal(err, null); 172 | // other assertions go here 173 | next(); 174 | } 175 | ); 176 | }); 177 | 178 | it("should successfully execute DELETE /orgs/:org/migrations/:id/archive (deleteMigrationArchive)", function(next) { 179 | client.orgs.deleteMigrationArchive( 180 | { 181 | org: "String", 182 | id: "String" 183 | }, 184 | function(err, res) { 185 | Assert.equal(err, null); 186 | // other assertions go here 187 | next(); 188 | } 189 | ); 190 | }); 191 | 192 | it("should successfully execute DELETE /teams/:id (deleteTeam)", function(next) { 193 | client.orgs.deleteTeam( 194 | { 195 | id: "String" 196 | }, 197 | function(err, res) { 198 | Assert.equal(err, null); 199 | // other assertions go here 200 | next(); 201 | } 202 | ); 203 | }); 204 | 205 | it("should successfully execute DELETE /teams/:id/repos/:user/:repo (deleteTeamRepo)", function(next) { 206 | client.orgs.deleteTeamRepo( 207 | { 208 | id: "String", 209 | user: "String", 210 | repo: "String" 211 | }, 212 | function(err, res) { 213 | Assert.equal(err, null); 214 | // other assertions go here 215 | next(); 216 | } 217 | ); 218 | }); 219 | 220 | it("should successfully execute PATCH /orgs/:org/hooks/:id (editHook)", function(next) { 221 | client.orgs.editHook( 222 | { 223 | org: "String", 224 | id: "String", 225 | config: "Json", 226 | events: "Array", 227 | active: "Boolean" 228 | }, 229 | function(err, res) { 230 | Assert.equal(err, null); 231 | // other assertions go here 232 | next(); 233 | } 234 | ); 235 | }); 236 | 237 | it("should successfully execute PATCH /teams/:id (editTeam)", function(next) { 238 | client.orgs.editTeam( 239 | { 240 | id: "String", 241 | name: "String", 242 | description: "String", 243 | privacy: "String" 244 | }, 245 | function(err, res) { 246 | Assert.equal(err, null); 247 | // other assertions go here 248 | next(); 249 | } 250 | ); 251 | }); 252 | 253 | it("should successfully execute GET /orgs/:org (get)", function(next) { 254 | client.orgs.get( 255 | { 256 | org: "String", 257 | page: "Number", 258 | per_page: "Number" 259 | }, 260 | function(err, res) { 261 | Assert.equal(err, null); 262 | // other assertions go here 263 | next(); 264 | } 265 | ); 266 | }); 267 | 268 | it("should successfully execute GET /organizations (getAll)", function(next) { 269 | client.orgs.getAll( 270 | { 271 | since: "String", 272 | page: "Number", 273 | per_page: "Number" 274 | }, 275 | function(err, res) { 276 | Assert.equal(err, null); 277 | // other assertions go here 278 | next(); 279 | } 280 | ); 281 | }); 282 | 283 | it("should successfully execute GET /users/:user/orgs (getForUser)", function(next) { 284 | client.orgs.getForUser( 285 | { 286 | user: "String", 287 | page: "Number", 288 | per_page: "Number" 289 | }, 290 | function(err, res) { 291 | Assert.equal(err, null); 292 | // other assertions go here 293 | next(); 294 | } 295 | ); 296 | }); 297 | 298 | it("should successfully execute GET /orgs/:org/hooks/:id (getHook)", function(next) { 299 | client.orgs.getHook( 300 | { 301 | org: "String", 302 | id: "String" 303 | }, 304 | function(err, res) { 305 | Assert.equal(err, null); 306 | // other assertions go here 307 | next(); 308 | } 309 | ); 310 | }); 311 | 312 | it("should successfully execute GET /orgs/:org/hooks (getHooks)", function(next) { 313 | client.orgs.getHooks( 314 | { 315 | org: "String", 316 | page: "Number", 317 | per_page: "Number" 318 | }, 319 | function(err, res) { 320 | Assert.equal(err, null); 321 | // other assertions go here 322 | next(); 323 | } 324 | ); 325 | }); 326 | 327 | it("should successfully execute GET /orgs/:org/members (getMembers)", function(next) { 328 | client.orgs.getMembers( 329 | { 330 | org: "String", 331 | filter: "String", 332 | role: "String", 333 | page: "Number", 334 | per_page: "Number" 335 | }, 336 | function(err, res) { 337 | Assert.equal(err, null); 338 | // other assertions go here 339 | next(); 340 | } 341 | ); 342 | }); 343 | 344 | it("should successfully execute GET /orgs/:org/migrations/:id/archive (getMigrationArchiveLink)", function(next) { 345 | client.orgs.getMigrationArchiveLink( 346 | { 347 | org: "String", 348 | id: "String" 349 | }, 350 | function(err, res) { 351 | Assert.equal(err, null); 352 | // other assertions go here 353 | next(); 354 | } 355 | ); 356 | }); 357 | 358 | it("should successfully execute GET /orgs/:org/migrations/:id (getMigrationStatus)", function(next) { 359 | client.orgs.getMigrationStatus( 360 | { 361 | org: "String", 362 | id: "String" 363 | }, 364 | function(err, res) { 365 | Assert.equal(err, null); 366 | // other assertions go here 367 | next(); 368 | } 369 | ); 370 | }); 371 | 372 | it("should successfully execute GET /orgs/:org/migrations (getMigrations)", function(next) { 373 | client.orgs.getMigrations( 374 | { 375 | org: "String", 376 | page: "Number", 377 | per_page: "Number" 378 | }, 379 | function(err, res) { 380 | Assert.equal(err, null); 381 | // other assertions go here 382 | next(); 383 | } 384 | ); 385 | }); 386 | 387 | it("should successfully execute GET /orgs/:org/memberships/:user (getOrganizationMembership)", function(next) { 388 | client.orgs.getOrganizationMembership( 389 | { 390 | org: "String", 391 | user: "String" 392 | }, 393 | function(err, res) { 394 | Assert.equal(err, null); 395 | // other assertions go here 396 | next(); 397 | } 398 | ); 399 | }); 400 | 401 | it("should successfully execute GET /user/memberships/orgs (getOrganizationMemberships)", function(next) { 402 | client.orgs.getOrganizationMemberships( 403 | { 404 | state: "String" 405 | }, 406 | function(err, res) { 407 | Assert.equal(err, null); 408 | // other assertions go here 409 | next(); 410 | } 411 | ); 412 | }); 413 | 414 | it("should successfully execute GET /orgs/:org/public_members (getPublicMembers)", function(next) { 415 | client.orgs.getPublicMembers( 416 | { 417 | org: "String" 418 | }, 419 | function(err, res) { 420 | Assert.equal(err, null); 421 | // other assertions go here 422 | next(); 423 | } 424 | ); 425 | }); 426 | 427 | it("should successfully execute GET /teams/:id (getTeam)", function(next) { 428 | client.orgs.getTeam( 429 | { 430 | id: "String" 431 | }, 432 | function(err, res) { 433 | Assert.equal(err, null); 434 | // other assertions go here 435 | next(); 436 | } 437 | ); 438 | }); 439 | 440 | it("should successfully execute GET /teams/:id/members (getTeamMembers)", function(next) { 441 | client.orgs.getTeamMembers( 442 | { 443 | id: "String", 444 | role: "String", 445 | page: "Number", 446 | per_page: "Number" 447 | }, 448 | function(err, res) { 449 | Assert.equal(err, null); 450 | // other assertions go here 451 | next(); 452 | } 453 | ); 454 | }); 455 | 456 | it("should successfully execute GET /teams/:id/memberships/:user (getTeamMembership)", function(next) { 457 | client.orgs.getTeamMembership( 458 | { 459 | id: "String", 460 | user: "String" 461 | }, 462 | function(err, res) { 463 | Assert.equal(err, null); 464 | // other assertions go here 465 | next(); 466 | } 467 | ); 468 | }); 469 | 470 | it("should successfully execute GET /teams/:id/repos (getTeamRepos)", function(next) { 471 | client.orgs.getTeamRepos( 472 | { 473 | id: "String", 474 | page: "Number", 475 | per_page: "Number" 476 | }, 477 | function(err, res) { 478 | Assert.equal(err, null); 479 | // other assertions go here 480 | next(); 481 | } 482 | ); 483 | }); 484 | 485 | it("should successfully execute GET /orgs/:org/teams (getTeams)", function(next) { 486 | client.orgs.getTeams( 487 | { 488 | org: "String", 489 | page: "Number", 490 | per_page: "Number" 491 | }, 492 | function(err, res) { 493 | Assert.equal(err, null); 494 | // other assertions go here 495 | next(); 496 | } 497 | ); 498 | }); 499 | 500 | it("should successfully execute POST /orgs/:org/hooks/:id/pings (pingHook)", function(next) { 501 | client.orgs.pingHook( 502 | { 503 | org: "String", 504 | id: "String" 505 | }, 506 | function(err, res) { 507 | Assert.equal(err, null); 508 | // other assertions go here 509 | next(); 510 | } 511 | ); 512 | }); 513 | 514 | it("should successfully execute PUT /orgs/:org/public_members/:user (publicizeMembership)", function(next) { 515 | client.orgs.publicizeMembership( 516 | { 517 | org: "String", 518 | user: "String" 519 | }, 520 | function(err, res) { 521 | Assert.equal(err, null); 522 | // other assertions go here 523 | next(); 524 | } 525 | ); 526 | }); 527 | 528 | it("should successfully execute DELETE /orgs/:org/members/:user (removeMember)", function(next) { 529 | client.orgs.removeMember( 530 | { 531 | org: "String", 532 | user: "String" 533 | }, 534 | function(err, res) { 535 | Assert.equal(err, null); 536 | // other assertions go here 537 | next(); 538 | } 539 | ); 540 | }); 541 | 542 | it("should successfully execute DELETE /orgs/:org/memberships/:user (removeOrganizationMembership)", function(next) { 543 | client.orgs.removeOrganizationMembership( 544 | { 545 | org: "String", 546 | user: "String" 547 | }, 548 | function(err, res) { 549 | Assert.equal(err, null); 550 | // other assertions go here 551 | next(); 552 | } 553 | ); 554 | }); 555 | 556 | it("should successfully execute DELETE /teams/:id/memberships/:user (removeTeamMembership)", function(next) { 557 | client.orgs.removeTeamMembership( 558 | { 559 | id: "String", 560 | user: "String" 561 | }, 562 | function(err, res) { 563 | Assert.equal(err, null); 564 | // other assertions go here 565 | next(); 566 | } 567 | ); 568 | }); 569 | 570 | it("should successfully execute POST /orgs/:org/migrations (startMigration)", function(next) { 571 | client.orgs.startMigration( 572 | { 573 | org: "String", 574 | repositories: "Array", 575 | lock_repositories: "Boolean", 576 | exclude_attachments: "Boolean" 577 | }, 578 | function(err, res) { 579 | Assert.equal(err, null); 580 | // other assertions go here 581 | next(); 582 | } 583 | ); 584 | }); 585 | 586 | it("should successfully execute DELETE /orgs/:org/migrations/:id/repos/:repo/lock (unlockRepoLockedForMigration)", function(next) { 587 | client.orgs.unlockRepoLockedForMigration( 588 | { 589 | org: "String", 590 | id: "String", 591 | repo: "String" 592 | }, 593 | function(err, res) { 594 | Assert.equal(err, null); 595 | // other assertions go here 596 | next(); 597 | } 598 | ); 599 | }); 600 | 601 | it("should successfully execute PATCH /orgs/:org (update)", function(next) { 602 | client.orgs.update( 603 | { 604 | org: "String", 605 | billing_email: "String", 606 | company: "String", 607 | email: "String", 608 | location: "String", 609 | name: "String", 610 | description: "String" 611 | }, 612 | function(err, res) { 613 | Assert.equal(err, null); 614 | // other assertions go here 615 | next(); 616 | } 617 | ); 618 | }); 619 | }); 620 | -------------------------------------------------------------------------------- /test/pullRequestsTest.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 Cloud9 IDE, Inc. 3 | * 4 | * This product includes software developed by 5 | * Cloud9 IDE, Inc (http://c9.io). 6 | * 7 | * Author: Mike de Boer 8 | */ 9 | 10 | "use strict"; 11 | 12 | var Assert = require("assert"); 13 | var Client = require("./../lib/index"); 14 | var testAuth = require("./../testAuth.json"); 15 | 16 | describe("[pullRequests]", function() { 17 | var client; 18 | var token = testAuth["token"]; 19 | 20 | beforeEach(function() { 21 | client = new Client(); 22 | client.authenticate({ 23 | type: "oauth", 24 | token: token 25 | }); 26 | }); 27 | 28 | it("should successfully execute GET /repos/:user/:repo/pulls/:number/merge (checkMerged)", function(next) { 29 | client.pullRequests.checkMerged( 30 | { 31 | user: "String", 32 | repo: "String", 33 | number: "Number", 34 | page: "Number", 35 | per_page: "Number" 36 | }, 37 | function(err, res) { 38 | Assert.equal(err, null); 39 | // other assertions go here 40 | next(); 41 | } 42 | ); 43 | }); 44 | 45 | it("should successfully execute POST /repos/:user/:repo/pulls (create)", function(next) { 46 | client.pullRequests.create( 47 | { 48 | user: "String", 49 | repo: "String", 50 | title: "String", 51 | head: "String", 52 | base: "String", 53 | body: "String" 54 | }, 55 | function(err, res) { 56 | Assert.equal(err, null); 57 | // other assertions go here 58 | next(); 59 | } 60 | ); 61 | }); 62 | 63 | it("should successfully execute POST /repos/:user/:repo/pulls/:number/comments (createComment)", function(next) { 64 | client.pullRequests.createComment( 65 | { 66 | user: "String", 67 | repo: "String", 68 | number: "Number", 69 | body: "String", 70 | commit_id: "String", 71 | path: "String", 72 | position: "Number" 73 | }, 74 | function(err, res) { 75 | Assert.equal(err, null); 76 | // other assertions go here 77 | next(); 78 | } 79 | ); 80 | }); 81 | 82 | it("should successfully execute POST /repos/:user/:repo/pulls/:number/comments (createCommentReply)", function(next) { 83 | client.pullRequests.createCommentReply( 84 | { 85 | user: "String", 86 | repo: "String", 87 | number: "Number", 88 | body: "String", 89 | in_reply_to: "Number" 90 | }, 91 | function(err, res) { 92 | Assert.equal(err, null); 93 | // other assertions go here 94 | next(); 95 | } 96 | ); 97 | }); 98 | 99 | it("should successfully execute POST /repos/:user/:repo/pulls (createFromIssue)", function(next) { 100 | client.pullRequests.createFromIssue( 101 | { 102 | user: "String", 103 | repo: "String", 104 | issue: "Number", 105 | head: "String", 106 | base: "String" 107 | }, 108 | function(err, res) { 109 | Assert.equal(err, null); 110 | // other assertions go here 111 | next(); 112 | } 113 | ); 114 | }); 115 | 116 | it("should successfully execute DELETE /repos/:user/:repo/pulls/comments/:number (deleteComment)", function(next) { 117 | client.pullRequests.deleteComment( 118 | { 119 | user: "String", 120 | repo: "String", 121 | number: "Number" 122 | }, 123 | function(err, res) { 124 | Assert.equal(err, null); 125 | // other assertions go here 126 | next(); 127 | } 128 | ); 129 | }); 130 | 131 | it("should successfully execute PATCH /repos/:user/:repo/pulls/comments/:number (editComment)", function(next) { 132 | client.pullRequests.editComment( 133 | { 134 | user: "String", 135 | repo: "String", 136 | number: "Number", 137 | body: "String" 138 | }, 139 | function(err, res) { 140 | Assert.equal(err, null); 141 | // other assertions go here 142 | next(); 143 | } 144 | ); 145 | }); 146 | 147 | it("should successfully execute GET /repos/:user/:repo/pulls/:number (get)", function(next) { 148 | client.pullRequests.get( 149 | { 150 | user: "String", 151 | repo: "String", 152 | number: "Number" 153 | }, 154 | function(err, res) { 155 | Assert.equal(err, null); 156 | // other assertions go here 157 | next(); 158 | } 159 | ); 160 | }); 161 | 162 | it("should successfully execute GET /repos/:user/:repo/pulls (getAll)", function(next) { 163 | client.pullRequests.getAll( 164 | { 165 | user: "String", 166 | repo: "String", 167 | state: "String", 168 | head: "String", 169 | base: "String", 170 | sort: "String", 171 | direction: "String", 172 | page: "Number", 173 | per_page: "Number" 174 | }, 175 | function(err, res) { 176 | Assert.equal(err, null); 177 | // other assertions go here 178 | next(); 179 | } 180 | ); 181 | }); 182 | 183 | it("should successfully execute GET /repos/:user/:repo/pulls/comments/:number (getComment)", function(next) { 184 | client.pullRequests.getComment( 185 | { 186 | user: "String", 187 | repo: "String", 188 | number: "Number" 189 | }, 190 | function(err, res) { 191 | Assert.equal(err, null); 192 | // other assertions go here 193 | next(); 194 | } 195 | ); 196 | }); 197 | 198 | it("should successfully execute GET /repos/:user/:repo/pulls/:number/comments (getComments)", function(next) { 199 | client.pullRequests.getComments( 200 | { 201 | user: "String", 202 | repo: "String", 203 | number: "Number", 204 | page: "Number", 205 | per_page: "Number" 206 | }, 207 | function(err, res) { 208 | Assert.equal(err, null); 209 | // other assertions go here 210 | next(); 211 | } 212 | ); 213 | }); 214 | 215 | it("should successfully execute GET /repos/:user/:repo/pulls/comments (getCommentsForRepo)", function(next) { 216 | client.pullRequests.getCommentsForRepo( 217 | { 218 | user: "String", 219 | repo: "String", 220 | sort: "String", 221 | direction: "String", 222 | since: "Date", 223 | page: "Number", 224 | per_page: "Number" 225 | }, 226 | function(err, res) { 227 | Assert.equal(err, null); 228 | // other assertions go here 229 | next(); 230 | } 231 | ); 232 | }); 233 | 234 | it("should successfully execute GET /repos/:user/:repo/pulls/:number/commits (getCommits)", function(next) { 235 | client.pullRequests.getCommits( 236 | { 237 | user: "String", 238 | repo: "String", 239 | number: "Number", 240 | page: "Number", 241 | per_page: "Number" 242 | }, 243 | function(err, res) { 244 | Assert.equal(err, null); 245 | // other assertions go here 246 | next(); 247 | } 248 | ); 249 | }); 250 | 251 | it("should successfully execute GET /repos/:user/:repo/pulls/:number/files (getFiles)", function(next) { 252 | client.pullRequests.getFiles( 253 | { 254 | user: "String", 255 | repo: "String", 256 | number: "Number", 257 | page: "Number", 258 | per_page: "Number" 259 | }, 260 | function(err, res) { 261 | Assert.equal(err, null); 262 | // other assertions go here 263 | next(); 264 | } 265 | ); 266 | }); 267 | 268 | it("should successfully execute PUT /repos/:user/:repo/pulls/:number/merge (merge)", function(next) { 269 | client.pullRequests.merge( 270 | { 271 | user: "String", 272 | repo: "String", 273 | number: "Number", 274 | commit_message: "String", 275 | sha: "String" 276 | }, 277 | function(err, res) { 278 | Assert.equal(err, null); 279 | // other assertions go here 280 | next(); 281 | } 282 | ); 283 | }); 284 | 285 | it("should successfully execute PATCH /repos/:user/:repo/pulls/:number (update)", function(next) { 286 | client.pullRequests.update( 287 | { 288 | user: "String", 289 | repo: "String", 290 | number: "Number", 291 | title: "String", 292 | body: "String", 293 | state: "String" 294 | }, 295 | function(err, res) { 296 | Assert.equal(err, null); 297 | // other assertions go here 298 | next(); 299 | } 300 | ); 301 | }); 302 | }); 303 | -------------------------------------------------------------------------------- /test/reposTest.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 Cloud9 IDE, Inc. 3 | * 4 | * This product includes software developed by 5 | * Cloud9 IDE, Inc (http://c9.io). 6 | * 7 | * Author: Mike de Boer 8 | */ 9 | 10 | "use strict"; 11 | 12 | var Assert = require("assert"); 13 | var Client = require("./../lib/index"); 14 | var testAuth = require("./../testAuth.json"); 15 | 16 | describe("[repos]", function() { 17 | var client; 18 | var token = testAuth["token"]; 19 | 20 | beforeEach(function() { 21 | client = new Client(); 22 | client.authenticate({ 23 | type: "oauth", 24 | token: token 25 | }); 26 | }); 27 | 28 | it("should successfully execute PUT /repos/:user/:repo/collaborators/:collabuser (addCollaborator)", function(next) { 29 | client.repos.addCollaborator( 30 | { 31 | user: "String", 32 | repo: "String", 33 | collabuser: "String" 34 | }, 35 | function(err, res) { 36 | Assert.equal(err, null); 37 | // other assertions go here 38 | next(); 39 | } 40 | ); 41 | }); 42 | 43 | it("should successfully execute GET /repos/:user/:repo/collaborators/:collabuser (checkCollaborator)", function(next) { 44 | client.repos.checkCollaborator( 45 | { 46 | user: "String", 47 | repo: "String", 48 | collabuser: "String" 49 | }, 50 | function(err, res) { 51 | Assert.equal(err, null); 52 | // other assertions go here 53 | next(); 54 | } 55 | ); 56 | }); 57 | 58 | it("should successfully execute GET /repos/:user/:repo/compare/:base...:head (compareCommits)", function(next) { 59 | client.repos.compareCommits( 60 | { 61 | user: "String", 62 | repo: "String", 63 | base: "String", 64 | head: "String" 65 | }, 66 | function(err, res) { 67 | Assert.equal(err, null); 68 | // other assertions go here 69 | next(); 70 | } 71 | ); 72 | }); 73 | 74 | it("should successfully execute POST /user/repos (create)", function(next) { 75 | client.repos.create( 76 | { 77 | name: "String", 78 | description: "String", 79 | homepage: "String", 80 | private: "Boolean", 81 | has_issues: "Boolean", 82 | has_wiki: "Boolean", 83 | has_downloads: "Boolean", 84 | auto_init: "Boolean", 85 | gitignore_template: "String", 86 | license_template: "String" 87 | }, 88 | function(err, res) { 89 | Assert.equal(err, null); 90 | // other assertions go here 91 | next(); 92 | } 93 | ); 94 | }); 95 | 96 | it("should successfully execute POST /repos/:user/:repo/commits/:sha/comments (createCommitComment)", function(next) { 97 | client.repos.createCommitComment( 98 | { 99 | user: "String", 100 | repo: "String", 101 | sha: "String", 102 | body: "String", 103 | path: "String", 104 | position: "Number", 105 | line: "Number" 106 | }, 107 | function(err, res) { 108 | Assert.equal(err, null); 109 | // other assertions go here 110 | next(); 111 | } 112 | ); 113 | }); 114 | 115 | it("should successfully execute POST /repos/:user/:repo/deployments (createDeployment)", function(next) { 116 | client.repos.createDeployment( 117 | { 118 | user: "String", 119 | repo: "String", 120 | ref: "String", 121 | task: "String", 122 | auto_merge: "Boolean", 123 | required_contexts: "Array", 124 | payload: "String", 125 | environment: "String", 126 | description: "String" 127 | }, 128 | function(err, res) { 129 | Assert.equal(err, null); 130 | // other assertions go here 131 | next(); 132 | } 133 | ); 134 | }); 135 | 136 | it("should successfully execute POST /repos/:user/:repo/deployments/:id/statuses (createDeploymentStatus)", function(next) { 137 | client.repos.createDeploymentStatus( 138 | { 139 | user: "String", 140 | repo: "String", 141 | id: "String", 142 | state: "String", 143 | target_url: "String", 144 | description: "String" 145 | }, 146 | function(err, res) { 147 | Assert.equal(err, null); 148 | // other assertions go here 149 | next(); 150 | } 151 | ); 152 | }); 153 | 154 | it("should successfully execute PUT /repos/:user/:repo/contents/:path (createFile)", function(next) { 155 | client.repos.createFile( 156 | { 157 | user: "String", 158 | repo: "String", 159 | path: "String", 160 | message: "String", 161 | content: "String", 162 | branch: "String", 163 | committer: "Json" 164 | }, 165 | function(err, res) { 166 | Assert.equal(err, null); 167 | // other assertions go here 168 | next(); 169 | } 170 | ); 171 | }); 172 | 173 | it("should successfully execute POST /orgs/:org/repos (createForOrg)", function(next) { 174 | client.repos.createForOrg( 175 | { 176 | org: "String", 177 | name: "String", 178 | description: "String", 179 | homepage: "String", 180 | private: "Boolean", 181 | has_issues: "Boolean", 182 | has_wiki: "Boolean", 183 | has_downloads: "Boolean", 184 | team_id: "Number", 185 | auto_init: "Boolean", 186 | gitignore_template: "String", 187 | license_template: "String" 188 | }, 189 | function(err, res) { 190 | Assert.equal(err, null); 191 | // other assertions go here 192 | next(); 193 | } 194 | ); 195 | }); 196 | 197 | it("should successfully execute POST /repos/:user/:repo/hooks (createHook)", function(next) { 198 | client.repos.createHook( 199 | { 200 | user: "String", 201 | repo: "String", 202 | name: "String", 203 | config: "Json", 204 | events: "Array", 205 | active: "Boolean" 206 | }, 207 | function(err, res) { 208 | Assert.equal(err, null); 209 | // other assertions go here 210 | next(); 211 | } 212 | ); 213 | }); 214 | 215 | it("should successfully execute POST /repos/:user/:repo/keys (createKey)", function(next) { 216 | client.repos.createKey( 217 | { 218 | user: "String", 219 | repo: "String", 220 | title: "String", 221 | key: "String", 222 | read_only: "Boolean" 223 | }, 224 | function(err, res) { 225 | Assert.equal(err, null); 226 | // other assertions go here 227 | next(); 228 | } 229 | ); 230 | }); 231 | 232 | it("should successfully execute POST /repos/:user/:repo/releases (createRelease)", function(next) { 233 | client.repos.createRelease( 234 | { 235 | user: "String", 236 | repo: "String", 237 | tag_name: "String", 238 | target_commitish: "String", 239 | name: "String", 240 | body: "String", 241 | draft: "Boolean", 242 | prerelease: "Boolean" 243 | }, 244 | function(err, res) { 245 | Assert.equal(err, null); 246 | // other assertions go here 247 | next(); 248 | } 249 | ); 250 | }); 251 | 252 | it("should successfully execute POST /repos/:user/:repo/statuses/:sha (createStatus)", function(next) { 253 | client.repos.createStatus( 254 | { 255 | user: "String", 256 | repo: "String", 257 | sha: "String", 258 | state: "String", 259 | target_url: "String", 260 | description: "String", 261 | context: "String" 262 | }, 263 | function(err, res) { 264 | Assert.equal(err, null); 265 | // other assertions go here 266 | next(); 267 | } 268 | ); 269 | }); 270 | 271 | it("should successfully execute DELETE /repos/:user/:repo (delete)", function(next) { 272 | client.repos.delete( 273 | { 274 | user: "String", 275 | repo: "String" 276 | }, 277 | function(err, res) { 278 | Assert.equal(err, null); 279 | // other assertions go here 280 | next(); 281 | } 282 | ); 283 | }); 284 | 285 | it("should successfully execute DELETE /repos/:user/:repo/releases/assets/:id (deleteAsset)", function(next) { 286 | client.repos.deleteAsset( 287 | { 288 | user: "String", 289 | repo: "String", 290 | id: "String" 291 | }, 292 | function(err, res) { 293 | Assert.equal(err, null); 294 | // other assertions go here 295 | next(); 296 | } 297 | ); 298 | }); 299 | 300 | it("should successfully execute DELETE /repos/:user/:repo/comments/:id (deleteCommitComment)", function(next) { 301 | client.repos.deleteCommitComment( 302 | { 303 | user: "String", 304 | repo: "String", 305 | id: "String" 306 | }, 307 | function(err, res) { 308 | Assert.equal(err, null); 309 | // other assertions go here 310 | next(); 311 | } 312 | ); 313 | }); 314 | 315 | it("should successfully execute DELETE /repos/:user/:repo/downloads/:id (deleteDownload)", function(next) { 316 | client.repos.deleteDownload( 317 | { 318 | user: "String", 319 | repo: "String", 320 | id: "String" 321 | }, 322 | function(err, res) { 323 | Assert.equal(err, null); 324 | // other assertions go here 325 | next(); 326 | } 327 | ); 328 | }); 329 | 330 | it("should successfully execute DELETE /repos/:user/:repo/contents/:path (deleteFile)", function(next) { 331 | client.repos.deleteFile( 332 | { 333 | user: "String", 334 | repo: "String", 335 | path: "String", 336 | message: "String", 337 | sha: "String", 338 | branch: "String", 339 | committer: "Json" 340 | }, 341 | function(err, res) { 342 | Assert.equal(err, null); 343 | // other assertions go here 344 | next(); 345 | } 346 | ); 347 | }); 348 | 349 | it("should successfully execute DELETE /repos/:user/:repo/hooks/:id (deleteHook)", function(next) { 350 | client.repos.deleteHook( 351 | { 352 | user: "String", 353 | repo: "String", 354 | id: "String" 355 | }, 356 | function(err, res) { 357 | Assert.equal(err, null); 358 | // other assertions go here 359 | next(); 360 | } 361 | ); 362 | }); 363 | 364 | it("should successfully execute DELETE /repos/:user/:repo/keys/:id (deleteKey)", function(next) { 365 | client.repos.deleteKey( 366 | { 367 | user: "String", 368 | repo: "String", 369 | id: "String" 370 | }, 371 | function(err, res) { 372 | Assert.equal(err, null); 373 | // other assertions go here 374 | next(); 375 | } 376 | ); 377 | }); 378 | 379 | it("should successfully execute DELETE /repos/:user/:repo/releases/:id (deleteRelease)", function(next) { 380 | client.repos.deleteRelease( 381 | { 382 | user: "String", 383 | repo: "String", 384 | id: "String" 385 | }, 386 | function(err, res) { 387 | Assert.equal(err, null); 388 | // other assertions go here 389 | next(); 390 | } 391 | ); 392 | }); 393 | 394 | it("should successfully execute PATCH /repos/:user/:repo (edit)", function(next) { 395 | client.repos.edit( 396 | { 397 | user: "String", 398 | repo: "String", 399 | name: "String", 400 | description: "String", 401 | homepage: "String", 402 | private: "Boolean", 403 | has_issues: "Boolean", 404 | has_wiki: "Boolean", 405 | has_downloads: "Boolean", 406 | default_branch: "String" 407 | }, 408 | function(err, res) { 409 | Assert.equal(err, null); 410 | // other assertions go here 411 | next(); 412 | } 413 | ); 414 | }); 415 | 416 | it("should successfully execute PATCH /repos/:user/:repo/releases/assets/:id (editAsset)", function(next) { 417 | client.repos.editAsset( 418 | { 419 | user: "String", 420 | repo: "String", 421 | id: "String", 422 | name: "String", 423 | label: "String" 424 | }, 425 | function(err, res) { 426 | Assert.equal(err, null); 427 | // other assertions go here 428 | next(); 429 | } 430 | ); 431 | }); 432 | 433 | it("should successfully execute PATCH /repos/:user/:repo/hooks/:id (editHook)", function(next) { 434 | client.repos.editHook( 435 | { 436 | user: "String", 437 | repo: "String", 438 | id: "String", 439 | name: "String", 440 | config: "Json", 441 | events: "Array", 442 | add_events: "Array", 443 | remove_events: "Array", 444 | active: "Boolean" 445 | }, 446 | function(err, res) { 447 | Assert.equal(err, null); 448 | // other assertions go here 449 | next(); 450 | } 451 | ); 452 | }); 453 | 454 | it("should successfully execute PATCH /repos/:user/:repo/releases/:id (editRelease)", function(next) { 455 | client.repos.editRelease( 456 | { 457 | user: "String", 458 | repo: "String", 459 | id: "String", 460 | tag_name: "String", 461 | target_commitish: "String", 462 | name: "String", 463 | body: "String", 464 | draft: "Boolean", 465 | prerelease: "Boolean" 466 | }, 467 | function(err, res) { 468 | Assert.equal(err, null); 469 | // other assertions go here 470 | next(); 471 | } 472 | ); 473 | }); 474 | 475 | it("should successfully execute POST /repos/:user/:repo/forks (fork)", function(next) { 476 | client.repos.fork( 477 | { 478 | user: "String", 479 | repo: "String", 480 | organization: "String" 481 | }, 482 | function(err, res) { 483 | Assert.equal(err, null); 484 | // other assertions go here 485 | next(); 486 | } 487 | ); 488 | }); 489 | 490 | it("should successfully execute GET /repos/:user/:repo (get)", function(next) { 491 | client.repos.get( 492 | { 493 | user: "String", 494 | repo: "String" 495 | }, 496 | function(err, res) { 497 | Assert.equal(err, null); 498 | // other assertions go here 499 | next(); 500 | } 501 | ); 502 | }); 503 | 504 | it("should successfully execute GET /user/repos (getAll)", function(next) { 505 | client.repos.getAll( 506 | { 507 | visibility: "String", 508 | affiliation: "String", 509 | type: "String", 510 | sort: "String", 511 | direction: "String", 512 | page: "Number", 513 | per_page: "Number" 514 | }, 515 | function(err, res) { 516 | Assert.equal(err, null); 517 | // other assertions go here 518 | next(); 519 | } 520 | ); 521 | }); 522 | 523 | it("should successfully execute GET /repos/:user/:repo/comments (getAllCommitComments)", function(next) { 524 | client.repos.getAllCommitComments( 525 | { 526 | user: "String", 527 | repo: "String", 528 | page: "Number", 529 | per_page: "Number" 530 | }, 531 | function(err, res) { 532 | Assert.equal(err, null); 533 | // other assertions go here 534 | next(); 535 | } 536 | ); 537 | }); 538 | 539 | it("should successfully execute GET /repos/:user/:repo/:archive_format/:ref (getArchiveLink)", function(next) { 540 | client.repos.getArchiveLink( 541 | { 542 | user: "String", 543 | repo: "String", 544 | archive_format: "String", 545 | ref: "String" 546 | }, 547 | function(err, res) { 548 | Assert.equal(err, null); 549 | // other assertions go here 550 | next(); 551 | } 552 | ); 553 | }); 554 | 555 | it("should successfully execute GET /repos/:user/:repo/releases/assets/:id (getAsset)", function(next) { 556 | client.repos.getAsset( 557 | { 558 | user: "String", 559 | repo: "String", 560 | id: "String" 561 | }, 562 | function(err, res) { 563 | Assert.equal(err, null); 564 | // other assertions go here 565 | next(); 566 | } 567 | ); 568 | }); 569 | 570 | it("should successfully execute GET /repos/:user/:repo/branches/:branch (getBranch)", function(next) { 571 | client.repos.getBranch( 572 | { 573 | user: "String", 574 | repo: "String", 575 | branch: "String", 576 | page: "Number", 577 | per_page: "Number" 578 | }, 579 | function(err, res) { 580 | Assert.equal(err, null); 581 | // other assertions go here 582 | next(); 583 | } 584 | ); 585 | }); 586 | 587 | it("should successfully execute GET /repos/:user/:repo/branches (getBranches)", function(next) { 588 | client.repos.getBranches( 589 | { 590 | user: "String", 591 | repo: "String", 592 | page: "Number", 593 | per_page: "Number" 594 | }, 595 | function(err, res) { 596 | Assert.equal(err, null); 597 | // other assertions go here 598 | next(); 599 | } 600 | ); 601 | }); 602 | 603 | it("should successfully execute GET /repos/:user/:repo/collaborators (getCollaborators)", function(next) { 604 | client.repos.getCollaborators( 605 | { 606 | user: "String", 607 | repo: "String", 608 | page: "Number", 609 | per_page: "Number" 610 | }, 611 | function(err, res) { 612 | Assert.equal(err, null); 613 | // other assertions go here 614 | next(); 615 | } 616 | ); 617 | }); 618 | 619 | it("should successfully execute GET /repos/:user/:repo/commits/:sha/status (getCombinedStatus)", function(next) { 620 | client.repos.getCombinedStatus( 621 | { 622 | user: "String", 623 | repo: "String", 624 | sha: "String" 625 | }, 626 | function(err, res) { 627 | Assert.equal(err, null); 628 | // other assertions go here 629 | next(); 630 | } 631 | ); 632 | }); 633 | 634 | it("should successfully execute GET /repos/:user/:repo/commits/:sha (getCommit)", function(next) { 635 | client.repos.getCommit( 636 | { 637 | user: "String", 638 | repo: "String", 639 | sha: "String" 640 | }, 641 | function(err, res) { 642 | Assert.equal(err, null); 643 | // other assertions go here 644 | next(); 645 | } 646 | ); 647 | }); 648 | 649 | it("should successfully execute GET /repos/:user/:repo/comments/:id (getCommitComment)", function(next) { 650 | client.repos.getCommitComment( 651 | { 652 | user: "String", 653 | repo: "String", 654 | id: "String" 655 | }, 656 | function(err, res) { 657 | Assert.equal(err, null); 658 | // other assertions go here 659 | next(); 660 | } 661 | ); 662 | }); 663 | 664 | it("should successfully execute GET /repos/:user/:repo/commits/:sha/comments (getCommitComments)", function(next) { 665 | client.repos.getCommitComments( 666 | { 667 | user: "String", 668 | repo: "String", 669 | sha: "String", 670 | page: "Number", 671 | per_page: "Number" 672 | }, 673 | function(err, res) { 674 | Assert.equal(err, null); 675 | // other assertions go here 676 | next(); 677 | } 678 | ); 679 | }); 680 | 681 | it("should successfully execute GET /repos/:user/:repo/commits (getCommits)", function(next) { 682 | client.repos.getCommits( 683 | { 684 | user: "String", 685 | repo: "String", 686 | sha: "String", 687 | path: "String", 688 | author: "String", 689 | since: "Date", 690 | until: "Date", 691 | page: "Number", 692 | per_page: "Number" 693 | }, 694 | function(err, res) { 695 | Assert.equal(err, null); 696 | // other assertions go here 697 | next(); 698 | } 699 | ); 700 | }); 701 | 702 | it("should successfully execute GET /repos/:user/:repo/contents/:path (getContent)", function(next) { 703 | client.repos.getContent( 704 | { 705 | user: "String", 706 | repo: "String", 707 | path: "String", 708 | ref: "String" 709 | }, 710 | function(err, res) { 711 | Assert.equal(err, null); 712 | // other assertions go here 713 | next(); 714 | } 715 | ); 716 | }); 717 | 718 | it("should successfully execute GET /repos/:user/:repo/contributors (getContributors)", function(next) { 719 | client.repos.getContributors( 720 | { 721 | user: "String", 722 | repo: "String", 723 | anon: "Boolean", 724 | page: "Number", 725 | per_page: "Number" 726 | }, 727 | function(err, res) { 728 | Assert.equal(err, null); 729 | // other assertions go here 730 | next(); 731 | } 732 | ); 733 | }); 734 | 735 | it("should successfully execute GET /repos/:user/:repo/deployments/:id/statuses (getDeploymentStatuses)", function(next) { 736 | client.repos.getDeploymentStatuses( 737 | { 738 | user: "String", 739 | repo: "String", 740 | id: "String" 741 | }, 742 | function(err, res) { 743 | Assert.equal(err, null); 744 | // other assertions go here 745 | next(); 746 | } 747 | ); 748 | }); 749 | 750 | it("should successfully execute GET /repos/:user/:repo/deployments (getDeployments)", function(next) { 751 | client.repos.getDeployments( 752 | { 753 | user: "String", 754 | repo: "String", 755 | sha: "String", 756 | ref: "String", 757 | task: "String", 758 | environment: "String", 759 | page: "Number", 760 | per_page: "Number" 761 | }, 762 | function(err, res) { 763 | Assert.equal(err, null); 764 | // other assertions go here 765 | next(); 766 | } 767 | ); 768 | }); 769 | 770 | it("should successfully execute GET /repos/:user/:repo/downloads/:id (getDownload)", function(next) { 771 | client.repos.getDownload( 772 | { 773 | user: "String", 774 | repo: "String", 775 | id: "String" 776 | }, 777 | function(err, res) { 778 | Assert.equal(err, null); 779 | // other assertions go here 780 | next(); 781 | } 782 | ); 783 | }); 784 | 785 | it("should successfully execute GET /repos/:user/:repo/downloads (getDownloads)", function(next) { 786 | client.repos.getDownloads( 787 | { 788 | user: "String", 789 | repo: "String", 790 | page: "Number", 791 | per_page: "Number" 792 | }, 793 | function(err, res) { 794 | Assert.equal(err, null); 795 | // other assertions go here 796 | next(); 797 | } 798 | ); 799 | }); 800 | 801 | it("should successfully execute GET /orgs/:org/repos (getForOrg)", function(next) { 802 | client.repos.getForOrg( 803 | { 804 | org: "String", 805 | type: "String", 806 | page: "Number", 807 | per_page: "Number" 808 | }, 809 | function(err, res) { 810 | Assert.equal(err, null); 811 | // other assertions go here 812 | next(); 813 | } 814 | ); 815 | }); 816 | 817 | it("should successfully execute GET /users/:user/repos (getForUser)", function(next) { 818 | client.repos.getForUser( 819 | { 820 | user: "String", 821 | type: "String", 822 | sort: "String", 823 | direction: "String", 824 | page: "Number", 825 | per_page: "Number" 826 | }, 827 | function(err, res) { 828 | Assert.equal(err, null); 829 | // other assertions go here 830 | next(); 831 | } 832 | ); 833 | }); 834 | 835 | it("should successfully execute GET /repos/:user/:repo/forks (getForks)", function(next) { 836 | client.repos.getForks( 837 | { 838 | user: "String", 839 | repo: "String", 840 | sort: "String", 841 | page: "Number", 842 | per_page: "Number" 843 | }, 844 | function(err, res) { 845 | Assert.equal(err, null); 846 | // other assertions go here 847 | next(); 848 | } 849 | ); 850 | }); 851 | 852 | it("should successfully execute GET /repos/:user/:repo/hooks/:id (getHook)", function(next) { 853 | client.repos.getHook( 854 | { 855 | user: "String", 856 | repo: "String", 857 | id: "String" 858 | }, 859 | function(err, res) { 860 | Assert.equal(err, null); 861 | // other assertions go here 862 | next(); 863 | } 864 | ); 865 | }); 866 | 867 | it("should successfully execute GET /repos/:user/:repo/hooks (getHooks)", function(next) { 868 | client.repos.getHooks( 869 | { 870 | user: "String", 871 | repo: "String", 872 | page: "Number", 873 | per_page: "Number" 874 | }, 875 | function(err, res) { 876 | Assert.equal(err, null); 877 | // other assertions go here 878 | next(); 879 | } 880 | ); 881 | }); 882 | 883 | it("should successfully execute GET /repos/:user/:repo/keys/:id (getKey)", function(next) { 884 | client.repos.getKey( 885 | { 886 | user: "String", 887 | repo: "String", 888 | id: "String" 889 | }, 890 | function(err, res) { 891 | Assert.equal(err, null); 892 | // other assertions go here 893 | next(); 894 | } 895 | ); 896 | }); 897 | 898 | it("should successfully execute GET /repos/:user/:repo/keys (getKeys)", function(next) { 899 | client.repos.getKeys( 900 | { 901 | user: "String", 902 | repo: "String", 903 | page: "Number", 904 | per_page: "Number" 905 | }, 906 | function(err, res) { 907 | Assert.equal(err, null); 908 | // other assertions go here 909 | next(); 910 | } 911 | ); 912 | }); 913 | 914 | it("should successfully execute GET /repos/:user/:repo/languages (getLanguages)", function(next) { 915 | client.repos.getLanguages( 916 | { 917 | user: "String", 918 | repo: "String", 919 | page: "Number", 920 | per_page: "Number" 921 | }, 922 | function(err, res) { 923 | Assert.equal(err, null); 924 | // other assertions go here 925 | next(); 926 | } 927 | ); 928 | }); 929 | 930 | it("should successfully execute GET /repos/:user/:repo/pages/builds/latest (getLatestPagesBuild)", function(next) { 931 | client.repos.getLatestPagesBuild( 932 | { 933 | user: "String", 934 | repo: "String" 935 | }, 936 | function(err, res) { 937 | Assert.equal(err, null); 938 | // other assertions go here 939 | next(); 940 | } 941 | ); 942 | }); 943 | 944 | it("should successfully execute GET /repos/:user/:repo/releases/latest (getLatestRelease)", function(next) { 945 | client.repos.getLatestRelease( 946 | { 947 | user: "String", 948 | repo: "String" 949 | }, 950 | function(err, res) { 951 | Assert.equal(err, null); 952 | // other assertions go here 953 | next(); 954 | } 955 | ); 956 | }); 957 | 958 | it("should successfully execute GET /repos/:user/:repo/pages (getPages)", function(next) { 959 | client.repos.getPages( 960 | { 961 | user: "String", 962 | repo: "String", 963 | page: "Number", 964 | per_page: "Number" 965 | }, 966 | function(err, res) { 967 | Assert.equal(err, null); 968 | // other assertions go here 969 | next(); 970 | } 971 | ); 972 | }); 973 | 974 | it("should successfully execute GET /repos/:user/:repo/pages/builds (getPagesBuilds)", function(next) { 975 | client.repos.getPagesBuilds( 976 | { 977 | user: "String", 978 | repo: "String", 979 | page: "Number", 980 | per_page: "Number" 981 | }, 982 | function(err, res) { 983 | Assert.equal(err, null); 984 | // other assertions go here 985 | next(); 986 | } 987 | ); 988 | }); 989 | 990 | it("should successfully execute GET /repositories (getPublic)", function(next) { 991 | client.repos.getPublic( 992 | { 993 | since: "String" 994 | }, 995 | function(err, res) { 996 | Assert.equal(err, null); 997 | // other assertions go here 998 | next(); 999 | } 1000 | ); 1001 | }); 1002 | 1003 | it("should successfully execute GET /repos/:user/:repo/readme (getReadme)", function(next) { 1004 | client.repos.getReadme( 1005 | { 1006 | user: "String", 1007 | repo: "String", 1008 | ref: "String" 1009 | }, 1010 | function(err, res) { 1011 | Assert.equal(err, null); 1012 | // other assertions go here 1013 | next(); 1014 | } 1015 | ); 1016 | }); 1017 | 1018 | it("should successfully execute GET /repos/:user/:repo/releases/:id (getRelease)", function(next) { 1019 | client.repos.getRelease( 1020 | { 1021 | user: "String", 1022 | repo: "String", 1023 | id: "String" 1024 | }, 1025 | function(err, res) { 1026 | Assert.equal(err, null); 1027 | // other assertions go here 1028 | next(); 1029 | } 1030 | ); 1031 | }); 1032 | 1033 | it("should successfully execute GET /repos/:user/:repo/releases/tags/:tag (getReleaseByTag)", function(next) { 1034 | client.repos.getReleaseByTag( 1035 | { 1036 | user: "String", 1037 | repo: "String", 1038 | tag: "String" 1039 | }, 1040 | function(err, res) { 1041 | Assert.equal(err, null); 1042 | // other assertions go here 1043 | next(); 1044 | } 1045 | ); 1046 | }); 1047 | 1048 | it("should successfully execute GET /repos/:user/:repo/releases (getReleases)", function(next) { 1049 | client.repos.getReleases( 1050 | { 1051 | user: "String", 1052 | repo: "String", 1053 | page: "Number", 1054 | per_page: "Number" 1055 | }, 1056 | function(err, res) { 1057 | Assert.equal(err, null); 1058 | // other assertions go here 1059 | next(); 1060 | } 1061 | ); 1062 | }); 1063 | 1064 | it("should successfully execute GET /repos/:user/:repo/stats/code_frequency (getStatsCodeFrequency)", function(next) { 1065 | client.repos.getStatsCodeFrequency( 1066 | { 1067 | user: "String", 1068 | repo: "String" 1069 | }, 1070 | function(err, res) { 1071 | Assert.equal(err, null); 1072 | // other assertions go here 1073 | next(); 1074 | } 1075 | ); 1076 | }); 1077 | 1078 | it("should successfully execute GET /repos/:user/:repo/stats/commit_activity (getStatsCommitActivity)", function(next) { 1079 | client.repos.getStatsCommitActivity( 1080 | { 1081 | user: "String", 1082 | repo: "String" 1083 | }, 1084 | function(err, res) { 1085 | Assert.equal(err, null); 1086 | // other assertions go here 1087 | next(); 1088 | } 1089 | ); 1090 | }); 1091 | 1092 | it("should successfully execute GET /repos/:user/:repo/stats/contributors (getStatsContributors)", function(next) { 1093 | client.repos.getStatsContributors( 1094 | { 1095 | user: "String", 1096 | repo: "String" 1097 | }, 1098 | function(err, res) { 1099 | Assert.equal(err, null); 1100 | // other assertions go here 1101 | next(); 1102 | } 1103 | ); 1104 | }); 1105 | 1106 | it("should successfully execute GET /repos/:user/:repo/stats/participation (getStatsParticipation)", function(next) { 1107 | client.repos.getStatsParticipation( 1108 | { 1109 | user: "String", 1110 | repo: "String" 1111 | }, 1112 | function(err, res) { 1113 | Assert.equal(err, null); 1114 | // other assertions go here 1115 | next(); 1116 | } 1117 | ); 1118 | }); 1119 | 1120 | it("should successfully execute GET /repos/:user/:repo/stats/punch_card (getStatsPunchCard)", function(next) { 1121 | client.repos.getStatsPunchCard( 1122 | { 1123 | user: "String", 1124 | repo: "String" 1125 | }, 1126 | function(err, res) { 1127 | Assert.equal(err, null); 1128 | // other assertions go here 1129 | next(); 1130 | } 1131 | ); 1132 | }); 1133 | 1134 | it("should successfully execute GET /repos/:user/:repo/commits/:sha/statuses (getStatuses)", function(next) { 1135 | client.repos.getStatuses( 1136 | { 1137 | user: "String", 1138 | repo: "String", 1139 | sha: "String" 1140 | }, 1141 | function(err, res) { 1142 | Assert.equal(err, null); 1143 | // other assertions go here 1144 | next(); 1145 | } 1146 | ); 1147 | }); 1148 | 1149 | it("should successfully execute GET /repos/:user/:repo/tags (getTags)", function(next) { 1150 | client.repos.getTags( 1151 | { 1152 | user: "String", 1153 | repo: "String", 1154 | page: "Number", 1155 | per_page: "Number" 1156 | }, 1157 | function(err, res) { 1158 | Assert.equal(err, null); 1159 | // other assertions go here 1160 | next(); 1161 | } 1162 | ); 1163 | }); 1164 | 1165 | it("should successfully execute GET /repos/:user/:repo/teams (getTeams)", function(next) { 1166 | client.repos.getTeams( 1167 | { 1168 | user: "String", 1169 | repo: "String", 1170 | page: "Number", 1171 | per_page: "Number" 1172 | }, 1173 | function(err, res) { 1174 | Assert.equal(err, null); 1175 | // other assertions go here 1176 | next(); 1177 | } 1178 | ); 1179 | }); 1180 | 1181 | it("should successfully execute GET /repos/:user/:repo/releases/:id/assets (listAssets)", function(next) { 1182 | client.repos.listAssets( 1183 | { 1184 | user: "String", 1185 | repo: "String", 1186 | id: "String" 1187 | }, 1188 | function(err, res) { 1189 | Assert.equal(err, null); 1190 | // other assertions go here 1191 | next(); 1192 | } 1193 | ); 1194 | }); 1195 | 1196 | it("should successfully execute POST /repos/:user/:repo/merges (merge)", function(next) { 1197 | client.repos.merge( 1198 | { 1199 | user: "String", 1200 | repo: "String", 1201 | base: "String", 1202 | head: "String", 1203 | commit_message: "String" 1204 | }, 1205 | function(err, res) { 1206 | Assert.equal(err, null); 1207 | // other assertions go here 1208 | next(); 1209 | } 1210 | ); 1211 | }); 1212 | 1213 | it("should successfully execute GET /repositories/:id (one)", function(next) { 1214 | client.repos.one( 1215 | { 1216 | id: "String" 1217 | }, 1218 | function(err, res) { 1219 | Assert.equal(err, null); 1220 | // other assertions go here 1221 | next(); 1222 | } 1223 | ); 1224 | }); 1225 | 1226 | it("should successfully execute POST /repos/:user/:repo/hooks/:id/pings (pingHook)", function(next) { 1227 | client.repos.pingHook( 1228 | { 1229 | user: "String", 1230 | repo: "String", 1231 | id: "String" 1232 | }, 1233 | function(err, res) { 1234 | Assert.equal(err, null); 1235 | // other assertions go here 1236 | next(); 1237 | } 1238 | ); 1239 | }); 1240 | 1241 | it("should successfully execute DELETE /repos/:user/:repo/collaborators/:collabuser (removeCollaborator)", function(next) { 1242 | client.repos.removeCollaborator( 1243 | { 1244 | user: "String", 1245 | repo: "String", 1246 | collabuser: "String" 1247 | }, 1248 | function(err, res) { 1249 | Assert.equal(err, null); 1250 | // other assertions go here 1251 | next(); 1252 | } 1253 | ); 1254 | }); 1255 | 1256 | it("should successfully execute POST /repos/:user/:repo/hooks/:id/test (testHook)", function(next) { 1257 | client.repos.testHook( 1258 | { 1259 | user: "String", 1260 | repo: "String", 1261 | id: "String" 1262 | }, 1263 | function(err, res) { 1264 | Assert.equal(err, null); 1265 | // other assertions go here 1266 | next(); 1267 | } 1268 | ); 1269 | }); 1270 | 1271 | it("should successfully execute PATCH /repos/:user/:repo/comments/:id (updateCommitComment)", function(next) { 1272 | client.repos.updateCommitComment( 1273 | { 1274 | user: "String", 1275 | repo: "String", 1276 | id: "String", 1277 | body: "String" 1278 | }, 1279 | function(err, res) { 1280 | Assert.equal(err, null); 1281 | // other assertions go here 1282 | next(); 1283 | } 1284 | ); 1285 | }); 1286 | 1287 | it("should successfully execute PUT /repos/:user/:repo/contents/:path (updateFile)", function(next) { 1288 | client.repos.updateFile( 1289 | { 1290 | user: "String", 1291 | repo: "String", 1292 | path: "String", 1293 | message: "String", 1294 | content: "String", 1295 | sha: "String", 1296 | branch: "String", 1297 | committer: "Json" 1298 | }, 1299 | function(err, res) { 1300 | Assert.equal(err, null); 1301 | // other assertions go here 1302 | next(); 1303 | } 1304 | ); 1305 | }); 1306 | 1307 | it("should successfully execute POST /repos/:user/:repo/releases/:id/assets (uploadAsset)", function(next) { 1308 | client.repos.uploadAsset( 1309 | { 1310 | user: "String", 1311 | repo: "String", 1312 | id: "String", 1313 | name: "String", 1314 | label: "String" 1315 | }, 1316 | function(err, res) { 1317 | Assert.equal(err, null); 1318 | // other assertions go here 1319 | next(); 1320 | } 1321 | ); 1322 | }); 1323 | }); 1324 | -------------------------------------------------------------------------------- /test/searchTest.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 Cloud9 IDE, Inc. 3 | * 4 | * This product includes software developed by 5 | * Cloud9 IDE, Inc (http://c9.io). 6 | * 7 | * Author: Mike de Boer 8 | */ 9 | 10 | "use strict"; 11 | 12 | var Assert = require("assert"); 13 | var Client = require("./../lib/index"); 14 | var testAuth = require("./../testAuth.json"); 15 | 16 | describe("[search]", function() { 17 | var client; 18 | var token = testAuth["token"]; 19 | 20 | beforeEach(function() { 21 | client = new Client(); 22 | client.authenticate({ 23 | type: "oauth", 24 | token: token 25 | }); 26 | }); 27 | 28 | it("should successfully execute GET /search/code (code)", function(next) { 29 | client.search.code( 30 | { 31 | q: "String", 32 | sort: "String", 33 | order: "String", 34 | page: "Number", 35 | per_page: "Number" 36 | }, 37 | function(err, res) { 38 | Assert.equal(err, null); 39 | // other assertions go here 40 | next(); 41 | } 42 | ); 43 | }); 44 | 45 | it("should successfully execute GET /legacy/user/email/:email (email)", function(next) { 46 | client.search.email( 47 | { 48 | email: "String" 49 | }, 50 | function(err, res) { 51 | Assert.equal(err, null); 52 | // other assertions go here 53 | next(); 54 | } 55 | ); 56 | }); 57 | 58 | it("should successfully execute GET /search/issues (issues)", function(next) { 59 | client.search.issues( 60 | { 61 | q: "String", 62 | sort: "String", 63 | order: "String", 64 | page: "Number", 65 | per_page: "Number" 66 | }, 67 | function(err, res) { 68 | Assert.equal(err, null); 69 | // other assertions go here 70 | next(); 71 | } 72 | ); 73 | }); 74 | 75 | it("should successfully execute GET /search/repositories (repos)", function(next) { 76 | client.search.repos( 77 | { 78 | q: "String", 79 | sort: "String", 80 | order: "String", 81 | page: "Number", 82 | per_page: "Number" 83 | }, 84 | function(err, res) { 85 | Assert.equal(err, null); 86 | // other assertions go here 87 | next(); 88 | } 89 | ); 90 | }); 91 | 92 | it("should successfully execute GET /search/users (users)", function(next) { 93 | client.search.users( 94 | { 95 | q: "String", 96 | sort: "String", 97 | order: "String", 98 | page: "Number", 99 | per_page: "Number" 100 | }, 101 | function(err, res) { 102 | Assert.equal(err, null); 103 | // other assertions go here 104 | next(); 105 | } 106 | ); 107 | }); 108 | }); 109 | -------------------------------------------------------------------------------- /test/usersTest.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 Cloud9 IDE, Inc. 3 | * 4 | * This product includes software developed by 5 | * Cloud9 IDE, Inc (http://c9.io). 6 | * 7 | * Author: Mike de Boer 8 | */ 9 | 10 | "use strict"; 11 | 12 | var Assert = require("assert"); 13 | var Client = require("./../lib/index"); 14 | var testAuth = require("./../testAuth.json"); 15 | 16 | describe("[users]", function() { 17 | var client; 18 | var token = testAuth["token"]; 19 | 20 | beforeEach(function() { 21 | client = new Client(); 22 | client.authenticate({ 23 | type: "oauth", 24 | token: token 25 | }); 26 | }); 27 | 28 | it("should successfully execute POST /user/emails (addEmails)", function(next) { 29 | client.users.addEmails( 30 | { 31 | body: "Array" 32 | }, 33 | function(err, res) { 34 | Assert.equal(err, null); 35 | // other assertions go here 36 | next(); 37 | } 38 | ); 39 | }); 40 | 41 | it("should successfully execute GET /user/following/:user (checkFollowing)", function(next) { 42 | client.users.checkFollowing( 43 | { 44 | user: "String" 45 | }, 46 | function(err, res) { 47 | Assert.equal(err, null); 48 | // other assertions go here 49 | next(); 50 | } 51 | ); 52 | }); 53 | 54 | it("should successfully execute GET /users/:user/following/:other_user (checkIfOneFollowersOther)", function(next) { 55 | client.users.checkIfOneFollowersOther( 56 | { 57 | user: "String", 58 | other_user: "String" 59 | }, 60 | function(err, res) { 61 | Assert.equal(err, null); 62 | // other assertions go here 63 | next(); 64 | } 65 | ); 66 | }); 67 | 68 | it("should successfully execute POST /user/keys (createKey)", function(next) { 69 | client.users.createKey( 70 | { 71 | title: "String", 72 | key: "String" 73 | }, 74 | function(err, res) { 75 | Assert.equal(err, null); 76 | // other assertions go here 77 | next(); 78 | } 79 | ); 80 | }); 81 | 82 | it("should successfully execute DELETE /user/emails (deleteEmails)", function(next) { 83 | client.users.deleteEmails( 84 | { 85 | body: "Array" 86 | }, 87 | function(err, res) { 88 | Assert.equal(err, null); 89 | // other assertions go here 90 | next(); 91 | } 92 | ); 93 | }); 94 | 95 | it("should successfully execute DELETE /user/keys/:id (deleteKey)", function(next) { 96 | client.users.deleteKey( 97 | { 98 | id: "String" 99 | }, 100 | function(err, res) { 101 | Assert.equal(err, null); 102 | // other assertions go here 103 | next(); 104 | } 105 | ); 106 | }); 107 | 108 | it("should successfully execute DELETE /users/:user/site_admin (demote)", function(next) { 109 | client.users.demote( 110 | { 111 | user: "String" 112 | }, 113 | function(err, res) { 114 | Assert.equal(err, null); 115 | // other assertions go here 116 | next(); 117 | } 118 | ); 119 | }); 120 | 121 | it("should successfully execute PATCH /user/memberships/orgs/:org (editOrganizationMembership)", function(next) { 122 | client.users.editOrganizationMembership( 123 | { 124 | org: "String", 125 | state: "String" 126 | }, 127 | function(err, res) { 128 | Assert.equal(err, null); 129 | // other assertions go here 130 | next(); 131 | } 132 | ); 133 | }); 134 | 135 | it("should successfully execute PUT /user/following/:user (followUser)", function(next) { 136 | client.users.followUser( 137 | { 138 | user: "String" 139 | }, 140 | function(err, res) { 141 | Assert.equal(err, null); 142 | // other assertions go here 143 | next(); 144 | } 145 | ); 146 | }); 147 | 148 | it("should successfully execute GET /user (get)", function(next) { 149 | client.users.get( 150 | {}, 151 | function(err, res) { 152 | Assert.equal(err, null); 153 | // other assertions go here 154 | next(); 155 | } 156 | ); 157 | }); 158 | 159 | it("should successfully execute GET /users (getAll)", function(next) { 160 | client.users.getAll( 161 | { 162 | since: "Number" 163 | }, 164 | function(err, res) { 165 | Assert.equal(err, null); 166 | // other assertions go here 167 | next(); 168 | } 169 | ); 170 | }); 171 | 172 | it("should successfully execute GET /user/:id (getById)", function(next) { 173 | client.users.getById( 174 | { 175 | id: "String" 176 | }, 177 | function(err, res) { 178 | Assert.equal(err, null); 179 | // other assertions go here 180 | next(); 181 | } 182 | ); 183 | }); 184 | 185 | it("should successfully execute GET /user/emails (getEmails)", function(next) { 186 | client.users.getEmails( 187 | { 188 | page: "Number", 189 | per_page: "Number" 190 | }, 191 | function(err, res) { 192 | Assert.equal(err, null); 193 | // other assertions go here 194 | next(); 195 | } 196 | ); 197 | }); 198 | 199 | it("should successfully execute GET /users/followers (getFollowers)", function(next) { 200 | client.users.getFollowers( 201 | { 202 | page: "Number", 203 | per_page: "Number" 204 | }, 205 | function(err, res) { 206 | Assert.equal(err, null); 207 | // other assertions go here 208 | next(); 209 | } 210 | ); 211 | }); 212 | 213 | it("should successfully execute GET /users/:user/followers (getFollowersForUser)", function(next) { 214 | client.users.getFollowersForUser( 215 | { 216 | user: "String", 217 | page: "Number", 218 | per_page: "Number" 219 | }, 220 | function(err, res) { 221 | Assert.equal(err, null); 222 | // other assertions go here 223 | next(); 224 | } 225 | ); 226 | }); 227 | 228 | it("should successfully execute GET /user/following (getFollowing)", function(next) { 229 | client.users.getFollowing( 230 | { 231 | page: "Number", 232 | per_page: "Number" 233 | }, 234 | function(err, res) { 235 | Assert.equal(err, null); 236 | // other assertions go here 237 | next(); 238 | } 239 | ); 240 | }); 241 | 242 | it("should successfully execute GET /users/:user/following (getFollowingForUser)", function(next) { 243 | client.users.getFollowingForUser( 244 | { 245 | user: "String", 246 | page: "Number", 247 | per_page: "Number" 248 | }, 249 | function(err, res) { 250 | Assert.equal(err, null); 251 | // other assertions go here 252 | next(); 253 | } 254 | ); 255 | }); 256 | 257 | it("should successfully execute GET /users/:user (getForUser)", function(next) { 258 | client.users.getForUser( 259 | { 260 | user: "String" 261 | }, 262 | function(err, res) { 263 | Assert.equal(err, null); 264 | // other assertions go here 265 | next(); 266 | } 267 | ); 268 | }); 269 | 270 | it("should successfully execute GET /user/keys/:id (getKey)", function(next) { 271 | client.users.getKey( 272 | { 273 | id: "String" 274 | }, 275 | function(err, res) { 276 | Assert.equal(err, null); 277 | // other assertions go here 278 | next(); 279 | } 280 | ); 281 | }); 282 | 283 | it("should successfully execute GET /user/keys (getKeys)", function(next) { 284 | client.users.getKeys( 285 | { 286 | page: "Number", 287 | per_page: "Number" 288 | }, 289 | function(err, res) { 290 | Assert.equal(err, null); 291 | // other assertions go here 292 | next(); 293 | } 294 | ); 295 | }); 296 | 297 | it("should successfully execute GET /users/:user/keys (getKeysForUser)", function(next) { 298 | client.users.getKeysForUser( 299 | { 300 | user: "String", 301 | page: "Number", 302 | per_page: "Number" 303 | }, 304 | function(err, res) { 305 | Assert.equal(err, null); 306 | // other assertions go here 307 | next(); 308 | } 309 | ); 310 | }); 311 | 312 | it("should successfully execute GET /user/memberships/orgs/:org (getOrganizationMembership)", function(next) { 313 | client.users.getOrganizationMembership( 314 | { 315 | org: "String" 316 | }, 317 | function(err, res) { 318 | Assert.equal(err, null); 319 | // other assertions go here 320 | next(); 321 | } 322 | ); 323 | }); 324 | 325 | it("should successfully execute GET /user/orgs (getOrgs)", function(next) { 326 | client.users.getOrgs( 327 | { 328 | page: "Number", 329 | per_page: "Number" 330 | }, 331 | function(err, res) { 332 | Assert.equal(err, null); 333 | // other assertions go here 334 | next(); 335 | } 336 | ); 337 | }); 338 | 339 | it("should successfully execute GET /user/teams (getTeams)", function(next) { 340 | client.users.getTeams( 341 | { 342 | page: "Number", 343 | per_page: "Number" 344 | }, 345 | function(err, res) { 346 | Assert.equal(err, null); 347 | // other assertions go here 348 | next(); 349 | } 350 | ); 351 | }); 352 | 353 | it("should successfully execute PUT /users/:user/site_admin (promote)", function(next) { 354 | client.users.promote( 355 | { 356 | user: "String" 357 | }, 358 | function(err, res) { 359 | Assert.equal(err, null); 360 | // other assertions go here 361 | next(); 362 | } 363 | ); 364 | }); 365 | 366 | it("should successfully execute PUT /users/:user/suspended (suspend)", function(next) { 367 | client.users.suspend( 368 | { 369 | user: "String" 370 | }, 371 | function(err, res) { 372 | Assert.equal(err, null); 373 | // other assertions go here 374 | next(); 375 | } 376 | ); 377 | }); 378 | 379 | it("should successfully execute DELETE /user/following/:user (unfollowUser)", function(next) { 380 | client.users.unfollowUser( 381 | { 382 | user: "String" 383 | }, 384 | function(err, res) { 385 | Assert.equal(err, null); 386 | // other assertions go here 387 | next(); 388 | } 389 | ); 390 | }); 391 | 392 | it("should successfully execute DELETE /users/:user/suspended (unsuspend)", function(next) { 393 | client.users.unsuspend( 394 | { 395 | user: "String" 396 | }, 397 | function(err, res) { 398 | Assert.equal(err, null); 399 | // other assertions go here 400 | next(); 401 | } 402 | ); 403 | }); 404 | 405 | it("should successfully execute PATCH /user (update)", function(next) { 406 | client.users.update( 407 | { 408 | name: "String", 409 | email: "String", 410 | blog: "String", 411 | company: "String", 412 | location: "String", 413 | hireable: "Boolean", 414 | bio: "String" 415 | }, 416 | function(err, res) { 417 | Assert.equal(err, null); 418 | // other assertions go here 419 | next(); 420 | } 421 | ); 422 | }); 423 | }); 424 | --------------------------------------------------------------------------------