MCPcopy Index your code
hub / github.com/github-tools/github / writeFile

Method writeFile

lib/Repository.js:768–791  ·  view source on GitHub ↗

* Write a file to the repository * @see https://developer.github.com/v3/repos/contents/#update-a-file * @param {string} branch - the name of the branch * @param {string} path - the path for the file * @param {string} content - the contents of the file * @param {string} message -

(branch, path, content, message, options, cb)

Source from the content-addressed store, hash-verified

766 * @return {Promise} - the promise for the http request
767 */
768 writeFile(branch, path, content, message, options, cb) {
769 options = options || {};
770 if (typeof options === 'function') {
771 cb = options;
772 options = {};
773 }
774 let filePath = path ? encodeURI(path) : '';
775 let shouldEncode = options.encode !== false;
776 let commit = {
777 branch,
778 message,
779 author: options.author,
780 committer: options.committer,
781 content: shouldEncode ? Base64.encode(content) : content,
782 };
783
784 return this.getSha(branch, filePath)
785 .then((response) => {
786 commit.sha = response.data.sha;
787 return this._request('PUT', `/repos/${this.__fullname}/contents/${filePath}`, commit, cb);
788 }, () => {
789 return this._request('PUT', `/repos/${this.__fullname}/contents/${filePath}`, commit, cb);
790 });
791 }
792
793 /**
794 * Check if a repository is starred by you

Callers 1

repository.spec.jsFile · 0.80

Calls 2

getShaMethod · 0.95
_requestMethod · 0.80

Tested by

no test coverage detected