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" ;
9
2
10
- const getAbsentMessage = commitSha => `### 💥 No Changeset
3
+ const getAbsentMessage = ( commitSha , addChangesetUrl ) => `### 💥 No Changeset
11
4
12
5
Latest commit: ${ commitSha }
13
6
@@ -17,15 +10,24 @@ Merging this PR will not cause any packages to be released. If these changes sho
17
10
18
11
[Click here to learn what changesets are, and how to add one](https://github.com/Noviny/changesets/blob/master/docs/adding-a-changeset.md).
19
12
13
+ [Click here if you're a maintainer who wants to add a changeset to this PR](${ addChangesetUrl } )
14
+
20
15
` ;
21
16
22
- const getApproveMessage = commitSha => `### 🦋 Changeset is good to go
17
+ const getApproveMessage = (
18
+ commitSha ,
19
+ addChangesetUrl
20
+ ) => `### 🦋 Changeset is good to go
23
21
24
22
Latest commit: ${ commitSha }
25
23
26
24
**We got this.**
27
25
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
+ ` ;
29
31
30
32
const getCommentId = ( context , params ) =>
31
33
context . github . issues . listComments ( params ) . then ( comments => {
@@ -64,22 +66,50 @@ module.exports = app => {
64
66
app . on ( [ "pull_request.opened" , "pull_request.synchronize" ] , async context => {
65
67
const params = context . issue ( ) ;
66
68
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
+ ] ) ;
72
102
73
103
let prComment ;
74
104
if ( ! hasChangeset ) {
75
105
prComment = context . issue ( {
76
106
comment_id : commentId ,
77
- body : getAbsentMessage ( latestCommit . sha )
107
+ body : getAbsentMessage ( latestCommitSha , addChangesetUrl )
78
108
} ) ;
79
109
} else {
80
110
prComment = context . issue ( {
81
111
comment_id : commentId ,
82
- body : getApproveMessage ( latestCommit . sha )
112
+ body : getApproveMessage ( latestCommitSha , addChangesetUrl )
83
113
} ) ;
84
114
}
85
115
0 commit comments