forked from codinasion/codinasion
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubmitProgramCommentClose.js
More file actions
53 lines (50 loc) · 1.52 KB
/
Copy pathsubmitProgramCommentClose.js
File metadata and controls
53 lines (50 loc) · 1.52 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
// Why this extra file ?
// In many cases, 'git commit' fails due to some reason. But, submit program action still
// comments success message and closes the issue. This script is to prevent this kind of issue.
// By this we will first commit the changes and then comment and close the issue.
import fetch from "node-fetch";
export default async function submitProgramCommentClose(
OWNER,
REPO,
TOKEN,
ISSUE_NUMBER,
ISSUE_LABEL
) {
// create comment on issue
const commentResponse = await fetch(
`https://api.github.com/repos/${OWNER}/${REPO}/issues/${ISSUE_NUMBER}/comments`,
{
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `token ${TOKEN}`,
},
body: JSON.stringify({
body: `Program added successfully :tada:
Thanks for your contribution :hugs:
`,
}),
}
)
.then((res) => res.json())
.catch((e) => console.log("e => ", e));
await console.log("commentResponse => ", commentResponse);
// close issue
const closeIssueResponse = await fetch(
`https://api.github.com/repos/${OWNER}/${REPO}/issues/${ISSUE_NUMBER}`,
{
method: "PATCH",
headers: {
"Content-Type": "application/json",
Authorization: `token ${TOKEN}`,
},
body: JSON.stringify({
state: "closed",
labels: [`${ISSUE_LABEL}`, "submitted"],
}),
}
)
.then((res) => res.json())
.catch((e) => console.log("e => ", e));
await console.log("closeIssueResponse => ", closeIssueResponse);
}