-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgithub.js
More file actions
56 lines (51 loc) · 1.79 KB
/
github.js
File metadata and controls
56 lines (51 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
'use strict';
let GitHubApi = require('github-api');
/**
* Instantiate a new GitHub object.
*
* @param {Object} config An object containing the username, password, type of auth, and the repository to use.
*
* @constructor
*/
function GitHub(config) {
let gitHubApi = new GitHubApi({
username: config.username,
password: config.password,
auth: config.auth
});
this.repository = gitHubApi.getRepo(config.username, config.repository);
}
/**
* Update a file of the repository (or create a new if it didn't exist). The method returns a Promise that,
* when resolved returns the repository object. This is the same as the <code>repository</code> property of the
* <code>data</code> parameter.
*
* @param {Object} data An object containing the data to update (or create) the new file. The object must contain
* the following properties:
* - {string} <code>branchName</code>: The name of the branch in which the file should be updated (or create)
* - {string} <code>commitTitle</code>: The commit message for the change
* - {string} <code>content</code>: The content of the file
* - {string} <code>filename</code>: The path of the file to update (or create)
* - {Object} <code>repository</code>: The object representing the repository to update
*
* @returns {Promise}
*/
GitHub.prototype.saveFile = function(data) {
return new Promise(function(resolve, reject) {
data.repository.writeFile(
data.branchName,
data.filename,
data.content,
data.commitTitle,
data.options,
function(err) {
if (err) {
reject(err);
} else {
resolve(data.repository);
}
}
);
});
};
module.exports = GitHub;