-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathcontents.js
More file actions
81 lines (61 loc) · 1.67 KB
/
contents.js
File metadata and controls
81 lines (61 loc) · 1.67 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
# Contents features
## Setup
```javascript
const GitHubClient = require('../libs/GitHubClient.js').GitHubClient;
const contents = require('../libs/features/contents');
let githubCli = new GitHubClient({
baseUri: "http://github.at.home/api/v3",
token: process.env.TOKEN_GHITHUB_ENTERPRISE
}, contents); //<-- add contents features
```
*/
/*
## fetchContent
- parameter: `path, owner, repository, decode`
- return: `Promise`
### Description
`fetchContent` gets the text content of a source file
*/
function fetchContent({path, owner, repository, decode}){
return this.getData({path:`/repos/${owner}/${repository}/contents/${path}`})
.then(response => {
if(decode==true) {
response.data.contentText = new Buffer(response.data.content, response.data.encoding).toString("ascii")
}
return response.data;
});
}
/*
## createFile
- parameter: `file, content, message, branch, owner, repository`
- return: `Promise`
### Description
`createFile` creates a source file
*/
function createFile({file, content, message, branch, owner, repository}) {
let contentB64 = (new Buffer(content)).toString('base64');
return this.putData({path:`/repos/${owner}/${repository}/contents/${file}`, data:{
message, branch, content: contentB64
}}).then(response => {
return response.data;
});
}
/*
## searchCode
- parameter: `q` (query parameters)
- return: `Promise`
### Description
`searchCode` executes a search
*/
function searchCode({q}) {
return this.getData({path:`/search/code?q=${q}`})
.then(response => {
return response.data;
});
}
module.exports = {
fetchContent: fetchContent,
createFile: createFile,
searchCode: searchCode
};