forked from mParticle/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithubComments.js
More file actions
58 lines (51 loc) · 1.41 KB
/
githubComments.js
File metadata and controls
58 lines (51 loc) · 1.41 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
const axios = require('axios');
const args = process.argv.slice(2);
const issueId = args[0];
const message = args[1];
const token = args[2];
if (!message) {
throw new Error('Message is required');
}
if (!issueId) {
throw new Error('IssueID is required');
}
if (!token) {
throw new Error('Github Token is required');
}
const githubCommentsUrl = `https://git.corp.mparticle.com/api/v3/repos/mParticle/docsite/issues/${issueId}/comments`;
const config = {
headers: {
Authorization: 'Bearer ' + token,
'Content-Type': 'application/json',
},
};
console.log('url', githubCommentsUrl);
axios
.get(githubCommentsUrl)
.then(({ data }) => {
const comment = data.filter((d) => d.body === message)[0];
if (comment) {
console.log('update url', comment.url);
axios
.patch(comment.url, { body: message }, config)
.then(({ data }) => {
console.log('updated comment', message);
})
.catch((error) => {
console.error(error.response.statusText);
});
} else {
console.log('create url', githubCommentsUrl);
axios
.post(githubCommentsUrl, { body: message }, config)
.then(({ data }) => {
console.log('created comment', message);
})
.catch((error) => {
console.error(error.response.statusText);
});
}
})
.catch((error) => {
console.error(error.response.statusText);
});