* 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)
| 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 |
no test coverage detected