UNPKG

38.3 kBSource Map (JSON)View Raw
1{"version":3,"names":[],"mappings":"","sources":["Repository.js"],"sourcesContent":["/**\n * @file\n * @copyright 2013 Michael Aufreiter (Development Seed) and 2016 Yahoo Inc.\n * @license Licensed under {@link https://spdx.org/licenses/BSD-3-Clause-Clear.html BSD-3-Clause-Clear}.\n * Github.js is freely distributable.\n */\n\nimport Requestable from './Requestable';\nimport Utf8 from 'utf8';\nimport {\n Base64,\n} from 'js-base64';\nimport debug from 'debug';\nconst log = debug('github:repository');\n\n/**\n * Repository encapsulates the functionality to create, query, and modify files.\n */\nclass Repository extends Requestable {\n /**\n * Create a Repository.\n * @param {string} fullname - the full name of the repository\n * @param {Requestable.auth} [auth] - information required to authenticate to Github\n * @param {string} [apiBase=https://api.github.com] - the base Github API URL\n */\n constructor(fullname, auth, apiBase) {\n super(auth, apiBase);\n this.__fullname = fullname;\n this.__currentTree = {\n branch: null,\n sha: null,\n };\n }\n\n /**\n * Get a reference\n * @see https://developer.github.com/v3/git/refs/#get-a-reference\n * @param {string} ref - the reference to get\n * @param {Requestable.callback} [cb] - will receive the reference's refSpec or a list of refSpecs that match `ref`\n * @return {Promise} - the promise for the http request\n */\n getRef(ref, cb) {\n return this._request('GET', `/repos/${this.__fullname}/git/refs/${ref}`, null, cb);\n }\n\n /**\n * Create a reference\n * @see https://developer.github.com/v3/git/refs/#create-a-reference\n * @param {Object} options - the object describing the ref\n * @param {Requestable.callback} [cb] - will receive the ref\n * @return {Promise} - the promise for the http request\n */\n createRef(options, cb) {\n return this._request('POST', `/repos/${this.__fullname}/git/refs`, options, cb);\n }\n\n /**\n * Delete a reference\n * @see https://developer.github.com/v3/git/refs/#delete-a-reference\n * @param {string} ref - the name of the ref to delte\n * @param {Requestable.callback} [cb] - will receive true if the request is successful\n * @return {Promise} - the promise for the http request\n */\n deleteRef(ref, cb) {\n return this._request('DELETE', `/repos/${this.__fullname}/git/refs/${ref}`, null, cb);\n }\n\n /**\n * Delete a repository\n * @see https://developer.github.com/v3/repos/#delete-a-repository\n * @param {Requestable.callback} [cb] - will receive true if the request is successful\n * @return {Promise} - the promise for the http request\n */\n deleteRepo(cb) {\n return this._request('DELETE', `/repos/${this.__fullname}`, null, cb);\n }\n\n /**\n * List the tags on a repository\n * @see https://developer.github.com/v3/repos/#list-tags\n * @param {Requestable.callback} [cb] - will receive the tag data\n * @return {Promise} - the promise for the http request\n */\n listTags(cb) {\n return this._request('GET', `/repos/${this.__fullname}/tags`, null, cb);\n }\n\n /**\n * List the open pull requests on the repository\n * @see https://developer.github.com/v3/pulls/#list-pull-requests\n * @param {Object} options - options to filter the search\n * @param {Requestable.callback} [cb] - will receive the list of PRs\n * @return {Promise} - the promise for the http request\n */\n listPullRequests(options, cb) {\n options = options || {};\n return this._request('GET', `/repos/${this.__fullname}/pulls`, options, cb);\n }\n\n /**\n * Get information about a specific pull request\n * @see https://developer.github.com/v3/pulls/#get-a-single-pull-request\n * @param {number} number - the PR you wish to fetch\n * @param {Requestable.callback} [cb] - will receive the PR from the API\n * @return {Promise} - the promise for the http request\n */\n getPullRequest(number, cb) {\n return this._request('GET', `/repos/${this.__fullname}/pulls/${number}`, null, cb);\n }\n\n /**\n * List the files of a specific pull request\n * @see https://developer.github.com/v3/pulls/#list-pull-requests-files\n * @param {number|string} number - the PR you wish to fetch\n * @param {Requestable.callback} [cb] - will receive the list of files from the API\n * @return {Promise} - the promise for the http request\n */\n listPullRequestFiles(number, cb) {\n return this._request('GET', `/repos/${this.__fullname}/pulls/${number}/files`, null, cb);\n }\n\n /**\n * Compare two branches/commits/repositories\n * @see https://developer.github.com/v3/repos/commits/#compare-two-commits\n * @param {string} base - the base commit\n * @param {string} head - the head commit\n * @param {Requestable.callback} cb - will receive the comparison\n * @return {Promise} - the promise for the http request\n */\n compareBranches(base, head, cb) {\n return this._request('GET', `/repos/${this.__fullname}/compare/${base}...${head}`, null, cb);\n }\n\n /**\n * List all the branches for the repository\n * @see https://developer.github.com/v3/repos/#list-branches\n * @param {Requestable.callback} cb - will receive the list of branches\n * @return {Promise} - the promise for the http request\n */\n listBranches(cb) {\n return this._request('GET', `/repos/${this.__fullname}/branches`, null, cb);\n }\n\n /**\n * Get a raw blob from the repository\n * @see https://developer.github.com/v3/git/blobs/#get-a-blob\n * @param {string} sha - the sha of the blob to fetch\n * @param {Requestable.callback} cb - will receive the blob from the API\n * @return {Promise} - the promise for the http request\n */\n getBlob(sha, cb) {\n return this._request('GET', `/repos/${this.__fullname}/git/blobs/${sha}`, null, cb, 'raw');\n }\n\n /**\n * Get a single branch\n * @see https://developer.github.com/v3/repos/branches/#get-branch\n * @param {string} branch - the name of the branch to fetch\n * @param {Requestable.callback} cb - will receive the branch from the API\n * @returns {Promise} - the promise for the http request\n */\n getBranch(branch, cb) {\n return this._request('GET', `/repos/${this.__fullname}/branches/${branch}`, null, cb);\n }\n\n /**\n * Get a commit from the repository\n * @see https://developer.github.com/v3/repos/commits/#get-a-single-commit\n * @param {string} sha - the sha for the commit to fetch\n * @param {Requestable.callback} cb - will receive the commit data\n * @return {Promise} - the promise for the http request\n */\n getCommit(sha, cb) {\n return this._request('GET', `/repos/${this.__fullname}/git/commits/${sha}`, null, cb);\n }\n\n /**\n * List the commits on a repository, optionally filtering by path, author or time range\n * @see https://developer.github.com/v3/repos/commits/#list-commits-on-a-repository\n * @param {Object} [options] - the filtering options for commits\n * @param {string} [options.sha] - the SHA or branch to start from\n * @param {string} [options.path] - the path to search on\n * @param {string} [options.author] - the commit author\n * @param {(Date|string)} [options.since] - only commits after this date will be returned\n * @param {(Date|string)} [options.until] - only commits before this date will be returned\n * @param {Requestable.callback} cb - will receive the list of commits found matching the criteria\n * @return {Promise} - the promise for the http request\n */\n listCommits(options, cb) {\n options = options || {};\n if (typeof options === 'function') {\n cb = options;\n options = {};\n }\n options.since = this._dateToISO(options.since);\n options.until = this._dateToISO(options.until);\n\n return this._request('GET', `/repos/${this.__fullname}/commits`, options, cb);\n }\n\n /**\n * List the commits on a pull request\n * @see https://developer.github.com/v3/repos/commits/#list-commits-on-a-repository\n * @param {number|string} number - the number of the pull request to list the commits\n * @param {Object} [options] - the filtering options for commits\n * @param {Requestable.callback} [cb] - will receive the commits information\n * @return {Promise} - the promise for the http request\n */\n listCommitsOnPR(number, options, cb) {\n options = options || {};\n if (typeof options === 'function') {\n cb = options;\n options = {};\n }\n return this._request('GET', `/repos/${this.__fullname}/pulls/${number}/commits`, options, cb);\n }\n\n /**\n * Gets a single commit information for a repository\n * @see https://developer.github.com/v3/repos/commits/#get-a-single-commit\n * @param {string} ref - the reference for the commit-ish\n * @param {Requestable.callback} cb - will receive the commit information\n * @return {Promise} - the promise for the http request\n */\n getSingleCommit(ref, cb) {\n ref = ref || '';\n return this._request('GET', `/repos/${this.__fullname}/commits/${ref}`, null, cb);\n }\n\n /**\n * Get tha sha for a particular object in the repository. This is a convenience function\n * @see https://developer.github.com/v3/repos/contents/#get-contents\n * @param {string} [branch] - the branch to look in, or the repository's default branch if omitted\n * @param {string} path - the path of the file or directory\n * @param {Requestable.callback} cb - will receive a description of the requested object, including a `SHA` property\n * @return {Promise} - the promise for the http request\n */\n getSha(branch, path, cb) {\n branch = branch ? `?ref=${branch}` : '';\n return this._request('GET', `/repos/${this.__fullname}/contents/${path}${branch}`, null, cb);\n }\n\n /**\n * List the commit statuses for a particular sha, branch, or tag\n * @see https://developer.github.com/v3/repos/statuses/#list-statuses-for-a-specific-ref\n * @param {string} sha - the sha, branch, or tag to get statuses for\n * @param {Requestable.callback} cb - will receive the list of statuses\n * @return {Promise} - the promise for the http request\n */\n listStatuses(sha, cb) {\n return this._request('GET', `/repos/${this.__fullname}/commits/${sha}/statuses`, null, cb);\n }\n\n /**\n * Get the combined view of commit statuses for a particular sha, branch, or tag\n * @see https://developer.github.com/v3/repos/statuses/#get-the-combined-status-for-a-specific-ref\n * @param {string} sha - the sha, branch, or tag to get the combined status for\n * @param {Requestable.callback} cb - will receive the combined status\n * @returns {Promise} - the promise for the http request\n */\n getCombinedStatus(sha, cb) {\n return this._request('GET', `/repos/${this.__fullname}/commits/${sha}/status`, null, cb);\n }\n\n /**\n * Get a description of a git tree\n * @see https://developer.github.com/v3/git/trees/#get-a-tree\n * @param {string} treeSHA - the SHA of the tree to fetch\n * @param {Requestable.callback} cb - will receive the callback data\n * @return {Promise} - the promise for the http request\n */\n getTree(treeSHA, cb) {\n return this._request('GET', `/repos/${this.__fullname}/git/trees/${treeSHA}`, null, cb);\n }\n\n /**\n * Create a blob\n * @see https://developer.github.com/v3/git/blobs/#create-a-blob\n * @param {(string|Buffer|Blob)} content - the content to add to the repository\n * @param {Requestable.callback} cb - will receive the details of the created blob\n * @return {Promise} - the promise for the http request\n */\n createBlob(content, cb) {\n let postBody = this._getContentObject(content);\n\n log('sending content', postBody);\n return this._request('POST', `/repos/${this.__fullname}/git/blobs`, postBody, cb);\n }\n\n /**\n * Get the object that represents the provided content\n * @param {string|Buffer|Blob} content - the content to send to the server\n * @return {Object} the representation of `content` for the GitHub API\n */\n _getContentObject(content) {\n if (typeof content === 'string') {\n log('contet is a string');\n return {\n content: Utf8.encode(content),\n encoding: 'utf-8',\n };\n\n } else if (typeof Buffer !== 'undefined' && content instanceof Buffer) {\n log('We appear to be in Node');\n return {\n content: content.toString('base64'),\n encoding: 'base64',\n };\n\n } else if (typeof Blob !== 'undefined' && content instanceof Blob) {\n log('We appear to be in the browser');\n return {\n content: Base64.encode(content),\n encoding: 'base64',\n };\n\n } else { // eslint-disable-line\n log(`Not sure what this content is: ${typeof content}, ${JSON.stringify(content)}`);\n throw new Error('Unknown content passed to postBlob. Must be string or Buffer (node) or Blob (web)');\n }\n }\n\n /**\n * Update a tree in Git\n * @see https://developer.github.com/v3/git/trees/#create-a-tree\n * @param {string} baseTreeSHA - the SHA of the tree to update\n * @param {string} path - the path for the new file\n * @param {string} blobSHA - the SHA for the blob to put at `path`\n * @param {Requestable.callback} cb - will receive the new tree that is created\n * @return {Promise} - the promise for the http request\n * @deprecated use {@link Repository#createTree} instead\n */\n updateTree(baseTreeSHA, path, blobSHA, cb) {\n let newTree = {\n base_tree: baseTreeSHA, // eslint-disable-line\n tree: [{\n path: path,\n sha: blobSHA,\n mode: '100644',\n type: 'blob',\n }],\n };\n\n return this._request('POST', `/repos/${this.__fullname}/git/trees`, newTree, cb);\n }\n\n /**\n * Create a new tree in git\n * @see https://developer.github.com/v3/git/trees/#create-a-tree\n * @param {Object} tree - the tree to create\n * @param {string} baseSHA - the root sha of the tree\n * @param {Requestable.callback} cb - will receive the new tree that is created\n * @return {Promise} - the promise for the http request\n */\n createTree(tree, baseSHA, cb) {\n return this._request('POST', `/repos/${this.__fullname}/git/trees`, {\n tree,\n base_tree: baseSHA, // eslint-disable-line camelcase\n }, cb);\n }\n\n /**\n * Add a commit to the repository\n * @see https://developer.github.com/v3/git/commits/#create-a-commit\n * @param {string} parent - the SHA of the parent commit\n * @param {string} tree - the SHA of the tree for this commit\n * @param {string} message - the commit message\n * @param {Object} [options] - commit options\n * @param {Object} [options.author] - the author of the commit\n * @param {Object} [options.commiter] - the committer\n * @param {Requestable.callback} cb - will receive the commit that is created\n * @return {Promise} - the promise for the http request\n */\n commit(parent, tree, message, options, cb) {\n if (typeof options === 'function') {\n cb = options;\n options = {};\n }\n\n let data = {\n message,\n tree,\n parents: [parent],\n };\n\n data = Object.assign({}, options, data);\n\n return this._request('POST', `/repos/${this.__fullname}/git/commits`, data, cb)\n .then((response) => {\n this.__currentTree.sha = response.data.sha; // Update latest commit\n return response;\n });\n }\n\n /**\n * Update a ref\n * @see https://developer.github.com/v3/git/refs/#update-a-reference\n * @param {string} ref - the ref to update\n * @param {string} commitSHA - the SHA to point the reference to\n * @param {boolean} force - indicates whether to force or ensure a fast-forward update\n * @param {Requestable.callback} cb - will receive the updated ref back\n * @return {Promise} - the promise for the http request\n */\n updateHead(ref, commitSHA, force, cb) {\n return this._request('PATCH', `/repos/${this.__fullname}/git/refs/${ref}`, {\n sha: commitSHA,\n force: force,\n }, cb);\n }\n\n /**\n * Update commit status\n * @see https://developer.github.com/v3/repos/statuses/\n * @param {string} commitSHA - the SHA of the commit that should be updated\n * @param {object} options - Commit status parameters\n * @param {string} options.state - The state of the status. Can be one of: pending, success, error, or failure.\n * @param {string} [options.target_url] - The target URL to associate with this status.\n * @param {string} [options.description] - A short description of the status.\n * @param {string} [options.context] - A string label to differentiate this status among CI systems.\n * @param {Requestable.callback} cb - will receive the updated commit back\n * @return {Promise} - the promise for the http request\n */\n updateStatus(commitSHA, options, cb) {\n return this._request('POST', `/repos/${this.__fullname}/statuses/${commitSHA}`, options, cb);\n }\n\n /**\n * Update repository information\n * @see https://developer.github.com/v3/repos/#edit\n * @param {object} options - New parameters that will be set to the repository\n * @param {string} options.name - Name of the repository\n * @param {string} [options.description] - A short description of the repository\n * @param {string} [options.homepage] - A URL with more information about the repository\n * @param {boolean} [options.private] - Either true to make the repository private, or false to make it public.\n * @param {boolean} [options.has_issues] - Either true to enable issues for this repository, false to disable them.\n * @param {boolean} [options.has_wiki] - Either true to enable the wiki for this repository, false to disable it.\n * @param {boolean} [options.has_downloads] - Either true to enable downloads, false to disable them.\n * @param {string} [options.default_branch] - Updates the default branch for this repository.\n * @param {Requestable.callback} cb - will receive the updated repository back\n * @return {Promise} - the promise for the http request\n */\n updateRepository(options, cb) {\n return this._request('PATCH', `/repos/${this.__fullname}`, options, cb);\n }\n\n /**\n * Get information about the repository\n * @see https://developer.github.com/v3/repos/#get\n * @param {Requestable.callback} cb - will receive the information about the repository\n * @return {Promise} - the promise for the http request\n */\n getDetails(cb) {\n return this._request('GET', `/repos/${this.__fullname}`, null, cb);\n }\n\n /**\n * List the contributors to the repository\n * @see https://developer.github.com/v3/repos/#list-contributors\n * @param {Requestable.callback} cb - will receive the list of contributors\n * @return {Promise} - the promise for the http request\n */\n getContributors(cb) {\n return this._request('GET', `/repos/${this.__fullname}/contributors`, null, cb);\n }\n\n /**\n * List the contributor stats to the repository\n * @see https://developer.github.com/v3/repos/#list-contributors\n * @param {Requestable.callback} cb - will receive the list of contributors\n * @return {Promise} - the promise for the http request\n */\n getContributorStats(cb) {\n return this._request('GET', `/repos/${this.__fullname}/stats/contributors`, null, cb);\n }\n\n /**\n * List the users who are collaborators on the repository. The currently authenticated user must have\n * push access to use this method\n * @see https://developer.github.com/v3/repos/collaborators/#list-collaborators\n * @param {Requestable.callback} cb - will receive the list of collaborators\n * @return {Promise} - the promise for the http request\n */\n getCollaborators(cb) {\n return this._request('GET', `/repos/${this.__fullname}/collaborators`, null, cb);\n }\n\n /**\n * Check if a user is a collaborator on the repository\n * @see https://developer.github.com/v3/repos/collaborators/#check-if-a-user-is-a-collaborator\n * @param {string} username - the user to check\n * @param {Requestable.callback} cb - will receive true if the user is a collaborator and false if they are not\n * @return {Promise} - the promise for the http request {Boolean} [description]\n */\n isCollaborator(username, cb) {\n return this._request('GET', `/repos/${this.__fullname}/collaborators/${username}`, null, cb);\n }\n\n /**\n * Get the contents of a repository\n * @see https://developer.github.com/v3/repos/contents/#get-contents\n * @param {string} ref - the ref to check\n * @param {string} path - the path containing the content to fetch\n * @param {boolean} raw - `true` if the results should be returned raw instead of GitHub's normalized format\n * @param {Requestable.callback} cb - will receive the fetched data\n * @return {Promise} - the promise for the http request\n */\n getContents(ref, path, raw, cb) {\n path = path ? `${encodeURI(path)}` : '';\n return this._request('GET', `/repos/${this.__fullname}/contents/${path}`, {\n ref,\n }, cb, raw);\n }\n\n /**\n * Get the README of a repository\n * @see https://developer.github.com/v3/repos/contents/#get-the-readme\n * @param {string} ref - the ref to check\n * @param {boolean} raw - `true` if the results should be returned raw instead of GitHub's normalized format\n * @param {Requestable.callback} cb - will receive the fetched data\n * @return {Promise} - the promise for the http request\n */\n getReadme(ref, raw, cb) {\n return this._request('GET', `/repos/${this.__fullname}/readme`, {\n ref,\n }, cb, raw);\n }\n\n /**\n * Fork a repository\n * @see https://developer.github.com/v3/repos/forks/#create-a-fork\n * @param {Requestable.callback} cb - will receive the information about the newly created fork\n * @return {Promise} - the promise for the http request\n */\n fork(cb) {\n return this._request('POST', `/repos/${this.__fullname}/forks`, null, cb);\n }\n\n /**\n * Fork a repository to an organization\n * @see https://developer.github.com/v3/repos/forks/#create-a-fork\n * @param {String} org - organization where you'd like to create the fork.\n * @param {Requestable.callback} cb - will receive the information about the newly created fork\n * @return {Promise} - the promise for the http request\n *\n */\n forkToOrg(org, cb) {\n return this._request('POST', `/repos/${this.__fullname}/forks?organization=${org}`, null, cb);\n }\n\n /**\n * List a repository's forks\n * @see https://developer.github.com/v3/repos/forks/#list-forks\n * @param {Requestable.callback} cb - will receive the list of repositories forked from this one\n * @return {Promise} - the promise for the http request\n */\n listForks(cb) {\n return this._request('GET', `/repos/${this.__fullname}/forks`, null, cb);\n }\n\n /**\n * Create a new branch from an existing branch.\n * @param {string} [oldBranch=master] - the name of the existing branch\n * @param {string} newBranch - the name of the new branch\n * @param {Requestable.callback} cb - will receive the commit data for the head of the new branch\n * @return {Promise} - the promise for the http request\n */\n createBranch(oldBranch, newBranch, cb) {\n if (typeof newBranch === 'function') {\n cb = newBranch;\n newBranch = oldBranch;\n oldBranch = 'master';\n }\n\n return this.getRef(`heads/${oldBranch}`)\n .then((response) => {\n let sha = response.data.object.sha;\n return this.createRef({\n sha,\n ref: `refs/heads/${newBranch}`,\n }, cb);\n });\n }\n\n /**\n * Create a new pull request\n * @see https://developer.github.com/v3/pulls/#create-a-pull-request\n * @param {Object} options - the pull request description\n * @param {Requestable.callback} cb - will receive the new pull request\n * @return {Promise} - the promise for the http request\n */\n createPullRequest(options, cb) {\n return this._request('POST', `/repos/${this.__fullname}/pulls`, options, cb);\n }\n\n /**\n * Update a pull request\n * @see https://developer.github.com/v3/pulls/#update-a-pull-request\n * @param {number|string} number - the number of the pull request to update\n * @param {Object} options - the pull request description\n * @param {Requestable.callback} [cb] - will receive the pull request information\n * @return {Promise} - the promise for the http request\n */\n updatePullRequest(number, options, cb) {\n return this._request('PATCH', `/repos/${this.__fullname}/pulls/${number}`, options, cb);\n }\n\n /**\n * List the hooks for the repository\n * @see https://developer.github.com/v3/repos/hooks/#list-hooks\n * @param {Requestable.callback} cb - will receive the list of hooks\n * @return {Promise} - the promise for the http request\n */\n listHooks(cb) {\n return this._request('GET', `/repos/${this.__fullname}/hooks`, null, cb);\n }\n\n /**\n * Get a hook for the repository\n * @see https://developer.github.com/v3/repos/hooks/#get-single-hook\n * @param {number} id - the id of the webook\n * @param {Requestable.callback} cb - will receive the details of the webook\n * @return {Promise} - the promise for the http request\n */\n getHook(id, cb) {\n return this._request('GET', `/repos/${this.__fullname}/hooks/${id}`, null, cb);\n }\n\n /**\n * Add a new hook to the repository\n * @see https://developer.github.com/v3/repos/hooks/#create-a-hook\n * @param {Object} options - the configuration describing the new hook\n * @param {Requestable.callback} cb - will receive the new webhook\n * @return {Promise} - the promise for the http request\n */\n createHook(options, cb) {\n return this._request('POST', `/repos/${this.__fullname}/hooks`, options, cb);\n }\n\n /**\n * Edit an existing webhook\n * @see https://developer.github.com/v3/repos/hooks/#edit-a-hook\n * @param {number} id - the id of the webhook\n * @param {Object} options - the new description of the webhook\n * @param {Requestable.callback} cb - will receive the updated webhook\n * @return {Promise} - the promise for the http request\n */\n updateHook(id, options, cb) {\n return this._request('PATCH', `/repos/${this.__fullname}/hooks/${id}`, options, cb);\n }\n\n /**\n * Delete a webhook\n * @see https://developer.github.com/v3/repos/hooks/#delete-a-hook\n * @param {number} id - the id of the webhook to be deleted\n * @param {Requestable.callback} cb - will receive true if the call is successful\n * @return {Promise} - the promise for the http request\n */\n deleteHook(id, cb) {\n return this._request('DELETE', `/repos/${this.__fullname}/hooks/${id}`, null, cb);\n }\n\n /**\n * List the deploy keys for the repository\n * @see https://developer.github.com/v3/repos/keys/#list-deploy-keys\n * @param {Requestable.callback} cb - will receive the list of deploy keys\n * @return {Promise} - the promise for the http request\n */\n listKeys(cb) {\n return this._request('GET', `/repos/${this.__fullname}/keys`, null, cb);\n }\n\n /**\n * Get a deploy key for the repository\n * @see https://developer.github.com/v3/repos/keys/#get-a-deploy-key\n * @param {number} id - the id of the deploy key\n * @param {Requestable.callback} cb - will receive the details of the deploy key\n * @return {Promise} - the promise for the http request\n */\n getKey(id, cb) {\n return this._request('GET', `/repos/${this.__fullname}/keys/${id}`, null, cb);\n }\n\n /**\n * Add a new deploy key to the repository\n * @see https://developer.github.com/v3/repos/keys/#add-a-new-deploy-key\n * @param {Object} options - the configuration describing the new deploy key\n * @param {Requestable.callback} cb - will receive the new deploy key\n * @return {Promise} - the promise for the http request\n */\n createKey(options, cb) {\n return this._request('POST', `/repos/${this.__fullname}/keys`, options, cb);\n }\n\n /**\n * Delete a deploy key\n * @see https://developer.github.com/v3/repos/keys/#remove-a-deploy-key\n * @param {number} id - the id of the deploy key to be deleted\n * @param {Requestable.callback} cb - will receive true if the call is successful\n * @return {Promise} - the promise for the http request\n */\n deleteKey(id, cb) {\n return this._request('DELETE', `/repos/${this.__fullname}/keys/${id}`, null, cb);\n }\n\n /**\n * Delete a file from a branch\n * @see https://developer.github.com/v3/repos/contents/#delete-a-file\n * @param {string} branch - the branch to delete from, or the default branch if not specified\n * @param {string} path - the path of the file to remove\n * @param {Requestable.callback} cb - will receive the commit in which the delete occurred\n * @return {Promise} - the promise for the http request\n */\n deleteFile(branch, path, cb) {\n return this.getSha(branch, path)\n .then((response) => {\n const deleteCommit = {\n message: `Delete the file at '${path}'`,\n sha: response.data.sha,\n branch,\n };\n return this._request('DELETE', `/repos/${this.__fullname}/contents/${path}`, deleteCommit, cb);\n });\n }\n\n /**\n * Change all references in a repo from oldPath to new_path\n * @param {string} branch - the branch to carry out the reference change, or the default branch if not specified\n * @param {string} oldPath - original path\n * @param {string} newPath - new reference path\n * @param {Requestable.callback} cb - will receive the commit in which the move occurred\n * @return {Promise} - the promise for the http request\n */\n move(branch, oldPath, newPath, cb) {\n let oldSha;\n return this.getRef(`heads/${branch}`)\n .then(({data: {object}}) => this.getTree(`${object.sha}?recursive=true`))\n .then(({data: {tree, sha}}) => {\n oldSha = sha;\n let newTree = tree.map((ref) => {\n if (ref.path === oldPath) {\n ref.path = newPath;\n }\n if (ref.type === 'tree') {\n delete ref.sha;\n }\n return ref;\n });\n return this.createTree(newTree);\n })\n .then(({data: tree}) => this.commit(oldSha, tree.sha, `Renamed '${oldPath}' to '${newPath}'`))\n .then(({data: commit}) => this.updateHead(`heads/${branch}`, commit.sha, true, cb));\n }\n\n /**\n * Write a file to the repository\n * @see https://developer.github.com/v3/repos/contents/#update-a-file\n * @param {string} branch - the name of the branch\n * @param {string} path - the path for the file\n * @param {string} content - the contents of the file\n * @param {string} message - the commit message\n * @param {Object} [options] - commit options\n * @param {Object} [options.author] - the author of the commit\n * @param {Object} [options.commiter] - the committer\n * @param {boolean} [options.encode] - true if the content should be base64 encoded\n * @param {Requestable.callback} cb - will receive the new commit\n * @return {Promise} - the promise for the http request\n */\n writeFile(branch, path, content, message, options, cb) {\n options = options || {};\n if (typeof options === 'function') {\n cb = options;\n options = {};\n }\n let filePath = path ? encodeURI(path) : '';\n let shouldEncode = options.encode !== false;\n let commit = {\n branch,\n message,\n author: options.author,\n committer: options.committer,\n content: shouldEncode ? Base64.encode(content) : content,\n };\n\n return this.getSha(branch, filePath)\n .then((response) => {\n commit.sha = response.data.sha;\n return this._request('PUT', `/repos/${this.__fullname}/contents/${filePath}`, commit, cb);\n }, () => {\n return this._request('PUT', `/repos/${this.__fullname}/contents/${filePath}`, commit, cb);\n });\n }\n\n /**\n * Check if a repository is starred by you\n * @see https://developer.github.com/v3/activity/starring/#check-if-you-are-starring-a-repository\n * @param {Requestable.callback} cb - will receive true if the repository is starred and false if the repository\n * is not starred\n * @return {Promise} - the promise for the http request {Boolean} [description]\n */\n isStarred(cb) {\n return this._request204or404(`/user/starred/${this.__fullname}`, null, cb);\n }\n\n /**\n * Star a repository\n * @see https://developer.github.com/v3/activity/starring/#star-a-repository\n * @param {Requestable.callback} cb - will receive true if the repository is starred\n * @return {Promise} - the promise for the http request\n */\n star(cb) {\n return this._request('PUT', `/user/starred/${this.__fullname}`, null, cb);\n }\n\n /**\n * Unstar a repository\n * @see https://developer.github.com/v3/activity/starring/#unstar-a-repository\n * @param {Requestable.callback} cb - will receive true if the repository is unstarred\n * @return {Promise} - the promise for the http request\n */\n unstar(cb) {\n return this._request('DELETE', `/user/starred/${this.__fullname}`, null, cb);\n }\n\n /**\n * Create a new release\n * @see https://developer.github.com/v3/repos/releases/#create-a-release\n * @param {Object} options - the description of the release\n * @param {Requestable.callback} cb - will receive the newly created release\n * @return {Promise} - the promise for the http request\n */\n createRelease(options, cb) {\n return this._request('POST', `/repos/${this.__fullname}/releases`, options, cb);\n }\n\n /**\n * Edit a release\n * @see https://developer.github.com/v3/repos/releases/#edit-a-release\n * @param {string} id - the id of the release\n * @param {Object} options - the description of the release\n * @param {Requestable.callback} cb - will receive the modified release\n * @return {Promise} - the promise for the http request\n */\n updateRelease(id, options, cb) {\n return this._request('PATCH', `/repos/${this.__fullname}/releases/${id}`, options, cb);\n }\n\n /**\n * Get information about all releases\n * @see https://developer.github.com/v3/repos/releases/#list-releases-for-a-repository\n * @param {Requestable.callback} cb - will receive the release information\n * @return {Promise} - the promise for the http request\n */\n listReleases(cb) {\n return this._request('GET', `/repos/${this.__fullname}/releases`, null, cb);\n }\n\n /**\n * Get information about a release\n * @see https://developer.github.com/v3/repos/releases/#get-a-single-release\n * @param {string} id - the id of the release\n * @param {Requestable.callback} cb - will receive the release information\n * @return {Promise} - the promise for the http request\n */\n getRelease(id, cb) {\n return this._request('GET', `/repos/${this.__fullname}/releases/${id}`, null, cb);\n }\n\n /**\n * Delete a release\n * @see https://developer.github.com/v3/repos/releases/#delete-a-release\n * @param {string} id - the release to be deleted\n * @param {Requestable.callback} cb - will receive true if the operation is successful\n * @return {Promise} - the promise for the http request\n */\n deleteRelease(id, cb) {\n return this._request('DELETE', `/repos/${this.__fullname}/releases/${id}`, null, cb);\n }\n\n /**\n * Merge a pull request\n * @see https://developer.github.com/v3/pulls/#merge-a-pull-request-merge-button\n * @param {number|string} number - the number of the pull request to merge\n * @param {Object} options - the merge options for the pull request\n * @param {Requestable.callback} [cb] - will receive the merge information if the operation is successful\n * @return {Promise} - the promise for the http request\n */\n mergePullRequest(number, options, cb) {\n return this._request('PUT', `/repos/${this.__fullname}/pulls/${number}/merge`, options, cb);\n }\n\n /**\n * Get information about all projects\n * @see https://developer.github.com/v3/projects/#list-repository-projects\n * @param {Requestable.callback} [cb] - will receive the list of projects\n * @return {Promise} - the promise for the http request\n */\n listProjects(cb) {\n return this._requestAllPages(`/repos/${this.__fullname}/projects`, {AcceptHeader: 'inertia-preview'}, cb);\n }\n\n /**\n * Create a new project\n * @see https://developer.github.com/v3/projects/#create-a-repository-project\n * @param {Object} options - the description of the project\n * @param {Requestable.callback} cb - will receive the newly created project\n * @return {Promise} - the promise for the http request\n */\n createProject(options, cb) {\n options = options || {};\n options.AcceptHeader = 'inertia-preview';\n return this._request('POST', `/repos/${this.__fullname}/projects`, options, cb);\n }\n\n}\n\nmodule.exports = Repository;\n"],"file":"Repository.js"}
\No newline at end of file