forked from raycast/extensions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreward.js
51 lines (47 loc) · 1.75 KB
/
reward.js
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
module.exports = async ({ github, context, fetch }) => {
try {
const pr = (
await github.rest.repos.listPullRequestsAssociatedWithCommit({
owner: context.repo.owner,
repo: context.repo.repo,
commit_sha: context.sha,
})
).data[0];
if (!pr) {
console.log("No PR found for commit " + context.sha);
return;
}
const result = await (
await fetch("https://www.raycast.com/api/v1/dev_contributions", {
method: "POST",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
Authorization: "Bearer " + process.env.PUBLISHING_BOT_TOKEN,
},
body: JSON.stringify({
github_user_id: pr.user.id,
credits: 1,
}),
})
).json();
if (!result.user_id) {
console.log("Could not find user", pr.user.login);
await github.rest.issues.createComment({
issue_number: pr.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `:tada: :tada: :tada:\n\nSuch a great contribution deserves a reward, but unfortunately we couldn't find your Raycast account based on your GitHub username (@${pr.user.login}).\nPlease [link your GitHub account to your Raycast account](https://www.raycast.com/settings/account) to receive your credits and soon be able to exchange them for some swag.`,
});
} else {
await github.rest.issues.createComment({
issue_number: pr.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: ":tada: :tada: :tada:\n\nWe've rewarded your Raycast account with some credits. You will soon be able to exchange them for some swag.",
});
}
} catch (error) {
console.log(error);
}
};