Skip to content

Commit b7955b0

Browse files
committed
All The Things
1 parent 6ad266a commit b7955b0

File tree

3 files changed

+969
-33
lines changed

3 files changed

+969
-33
lines changed

index.js

Lines changed: 48 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
1-
// let addChangesetUrl = `${
2-
// github.context.payload.pull_request!.head.repo.html_url
3-
// }/new/${
4-
// github.context.payload.pull_request!.head.ref
5-
// }?filename=.changeset/${humanId({
6-
// separator: "-",
7-
// capitalize: false
8-
// })}.md`;
1+
import humanId from "human-id";
92

10-
const getAbsentMessage = commitSha => `### 💥 No Changeset
3+
const getAbsentMessage = (commitSha, addChangesetUrl) => `### 💥 No Changeset
114
125
Latest commit: ${commitSha}
136
@@ -17,15 +10,24 @@ Merging this PR will not cause any packages to be released. If these changes sho
1710
1811
[Click here to learn what changesets are, and how to add one](https://github.com/Noviny/changesets/blob/master/docs/adding-a-changeset.md).
1912
13+
[Click here if you're a maintainer who wants to add a changeset to this PR](${addChangesetUrl})
14+
2015
`;
2116

22-
const getApproveMessage = commitSha => `### 🦋 Changeset is good to go
17+
const getApproveMessage = (
18+
commitSha,
19+
addChangesetUrl
20+
) => `### 🦋 Changeset is good to go
2321
2422
Latest commit: ${commitSha}
2523
2624
**We got this.**
2725
28-
Not sure what this means? [Click here to learn what changesets are](https://github.com/Noviny/changesets/blob/master/docs/adding-a-changeset.md).`;
26+
Not sure what this means? [Click here to learn what changesets are](https://github.com/Noviny/changesets/blob/master/docs/adding-a-changeset.md).
27+
28+
[Click here if you're a maintainer who wants to add another changeset to this PR](${addChangesetUrl})
29+
30+
`;
2931

3032
const getCommentId = (context, params) =>
3133
context.github.issues.listComments(params).then(comments => {
@@ -64,22 +66,50 @@ module.exports = app => {
6466
app.on(["pull_request.opened", "pull_request.synchronize"], async context => {
6567
const params = context.issue();
6668

67-
console.log(JSON.stringify(context.payload));
68-
69-
const commentId = await getCommentId(context, params);
70-
const hasChangeset = await getChangesetId(context, params);
71-
const latestCommit = await getLatestCommit(context, params);
69+
let number = context.payload;
70+
let repo = {
71+
owner: context.payload.repository.name,
72+
repository: context.payload.repository.owner.login
73+
};
74+
75+
let addChangesetUrl = `${
76+
context.payload.pull_request.head.repo.html_url
77+
}/new/${
78+
context.payload.pull_request.head.ref
79+
}?filename=.changeset/${humanId({
80+
separator: "-",
81+
capitalize: false
82+
})}.md`;
83+
84+
const latestCommitSha = context.payload.pull_request.head.sha;
85+
86+
const [commentId, hasChangeset] = await Promise.all([
87+
// we know the comment won't exist on opened events
88+
// ok, well like technically that's wrong
89+
// but reducing time is nice here so that
90+
// deploying this doesn't cost money
91+
context.payload.action === "synchronize"
92+
? getCommentId(context, {
93+
issue_number: number,
94+
...repo
95+
})
96+
: null,
97+
getChangesetId(context, {
98+
pull_number: number,
99+
...repo
100+
})
101+
]);
72102

73103
let prComment;
74104
if (!hasChangeset) {
75105
prComment = context.issue({
76106
comment_id: commentId,
77-
body: getAbsentMessage(latestCommit.sha)
107+
body: getAbsentMessage(latestCommitSha, addChangesetUrl)
78108
});
79109
} else {
80110
prComment = context.issue({
81111
comment_id: commentId,
82-
body: getApproveMessage(latestCommit.sha)
112+
body: getApproveMessage(latestCommitSha, addChangesetUrl)
83113
});
84114
}
85115

0 commit comments

Comments
 (0)