1
1
// @ts -ignore
2
2
import humanId from "human-id" ;
3
- import { Application , Context , Octokit } from "probot" ;
3
+ import { Application , Context } from "probot" ;
4
4
import Webhooks from "@octokit/webhooks" ;
5
5
import { getChangedPackages } from "./get-changed-packages" ;
6
- import { ReleasePlan , ComprehensiveRelease , VersionType } from "@changesets/types" ;
6
+ import {
7
+ ReleasePlan ,
8
+ ComprehensiveRelease ,
9
+ VersionType ,
10
+ } from "@changesets/types" ;
7
11
import markdownTable from "markdown-table" ;
12
+ import { captureException } from "@sentry/node" ;
8
13
9
14
const getReleasePlanMessage = ( releasePlan : ReleasePlan | null ) => {
10
15
if ( ! releasePlan ) return "" ;
11
16
12
17
let table = markdownTable ( [
13
18
[ "Name" , "Type" ] ,
14
19
...releasePlan . releases
15
- . filter ( ( x ) : x is ComprehensiveRelease & { type : Exclude < VersionType , 'none' > } => x . type !== 'none' )
16
- . map ( x => {
20
+ . filter (
21
+ (
22
+ x
23
+ ) : x is ComprehensiveRelease & { type : Exclude < VersionType , "none" > } =>
24
+ x . type !== "none"
25
+ )
26
+ . map ( ( x ) => {
17
27
return [
18
28
x . name ,
19
29
{
20
30
major : "Major" ,
21
31
minor : "Minor" ,
22
- patch : "Patch"
23
- } [ x . type ]
32
+ patch : "Patch" ,
33
+ } [ x . type ] ,
24
34
] ;
25
- } )
35
+ } ) ,
26
36
] ) ;
27
37
28
38
return `<details><summary>This PR includes ${
@@ -82,37 +92,36 @@ Not sure what this means? [Click here to learn what changesets are](https://git
82
92
83
93
const getNewChangesetTemplate = ( changedPackages : string [ ] , title : string ) =>
84
94
encodeURIComponent ( `---
85
- ${ changedPackages . map ( x => `"${ x } ": patch` ) . join ( "\n" ) }
95
+ ${ changedPackages . map ( ( x ) => `"${ x } ": patch` ) . join ( "\n" ) }
86
96
---
87
97
88
98
${ title }
89
99
` ) ;
90
100
91
- type PRContext = Context < Webhooks . WebhookPayloadPullRequest > ;
101
+ type PRContext = Context < Webhooks . EventPayloads . WebhookPayloadPullRequest > ;
92
102
93
103
const getCommentId = (
94
104
context : PRContext ,
95
105
params : { repo : string ; owner : string ; issue_number : number }
96
106
) =>
97
- context . github . issues . listComments ( params ) . then ( comments => {
107
+ context . github . issues . listComments ( params ) . then ( ( comments ) => {
98
108
const changesetBotComment = comments . data . find (
99
109
// TODO: find what the current user is in some way or something
100
- comment =>
110
+ ( comment ) =>
101
111
comment . user . login === "changeset-bot[bot]" ||
102
112
comment . user . login === "changesets-test-bot[bot]"
103
113
) ;
104
114
return changesetBotComment ? changesetBotComment . id : null ;
105
115
} ) ;
106
116
107
117
const getChangesetId = (
108
- changedFilesPromise : Promise <
109
- Octokit . Response < Octokit . PullsListFilesResponse >
110
- > ,
118
+ changedFilesPromise : ReturnType < PRContext [ "github" ] [ "pulls" ] [ "listFiles" ] > ,
111
119
params : { repo : string ; owner : string ; pull_number : number }
112
120
) =>
113
- changedFilesPromise . then ( files =>
121
+ changedFilesPromise . then ( ( files ) =>
114
122
files . data . some (
115
- file => file . filename . startsWith ( ".changeset" ) && file . status === "added"
123
+ ( file ) =>
124
+ file . filename . startsWith ( ".changeset" ) && file . status === "added"
116
125
)
117
126
) ;
118
127
@@ -121,7 +130,7 @@ async function fetchJsonFile(context: PRContext, path: string) {
121
130
owner : context . payload . pull_request . head . repo . owner . login ,
122
131
repo : context . payload . pull_request . head . repo . name ,
123
132
path,
124
- ref : context . payload . pull_request . head . ref
133
+ ref : context . payload . pull_request . head . ref ,
125
134
} ) ;
126
135
// @ts -ignore
127
136
let buffer = Buffer . from ( output . data . content , "base64" ) ;
@@ -148,22 +157,21 @@ export default (app: Application) => {
148
157
149
158
let repo = {
150
159
repo : context . payload . repository . name ,
151
- owner : context . payload . repository . owner . login
160
+ owner : context . payload . repository . owner . login ,
152
161
} ;
153
162
154
163
const latestCommitSha = context . payload . pull_request . head . sha ;
155
-
156
164
let changedFilesPromise = context . github . pulls . listFiles ( {
157
165
...repo ,
158
- pull_number : number
166
+ pull_number : number ,
159
167
} ) ;
160
168
161
169
console . log ( context . payload ) ;
162
170
163
171
const [
164
172
commentId ,
165
173
hasChangeset ,
166
- { changedPackages, releasePlan }
174
+ { changedPackages, releasePlan } ,
167
175
] = await Promise . all ( [
168
176
// we know the comment won't exist on opened events
169
177
// ok, well like technically that's wrong
@@ -177,20 +185,23 @@ export default (app: Application) => {
177
185
repo : context . payload . pull_request . head . repo . name ,
178
186
owner : context . payload . pull_request . head . repo . owner . login ,
179
187
ref : context . payload . pull_request . head . ref ,
180
- changedFiles : changedFilesPromise . then ( x =>
181
- x . data . map ( x => x . filename )
188
+ changedFiles : changedFilesPromise . then ( ( x ) =>
189
+ x . data . map ( ( x ) => x . filename )
182
190
) ,
183
191
octokit : context . github ,
184
- installationToken : await app . app . getInstallationAccessToken ( {
185
- installationId : ( context . payload as any ) . installation . id
186
- } )
187
- } ) . catch ( err => {
192
+ installationToken : (
193
+ await ( await app . auth ( ) ) . apps . createInstallationAccessToken ( {
194
+ installation_id : context . payload . installation ! . id ,
195
+ } )
196
+ ) . data . token ,
197
+ } ) . catch ( ( err ) => {
188
198
console . error ( err ) ;
199
+ captureException ( err ) ;
189
200
return {
190
201
changedPackages : [ "@fake-scope/fake-pkg" ] ,
191
- releasePlan : null
202
+ releasePlan : null ,
192
203
} ;
193
- } )
204
+ } ) ,
194
205
] as const ) ;
195
206
196
207
let addChangesetUrl = `${
@@ -199,7 +210,7 @@ export default (app: Application) => {
199
210
context . payload . pull_request . head . ref
200
211
} ?filename=.changeset/${ humanId ( {
201
212
separator : "-" ,
202
- capitalize : false
213
+ capitalize : false ,
203
214
} ) } .md&value=${ getNewChangesetTemplate (
204
215
changedPackages ,
205
216
context . payload . pull_request . title
@@ -211,7 +222,7 @@ export default (app: Application) => {
211
222
issue_number : number ,
212
223
body : hasChangeset
213
224
? getApproveMessage ( latestCommitSha , addChangesetUrl , releasePlan )
214
- : getAbsentMessage ( latestCommitSha , addChangesetUrl , releasePlan )
225
+ : getAbsentMessage ( latestCommitSha , addChangesetUrl , releasePlan ) ,
215
226
} ;
216
227
217
228
if ( prComment . comment_id != null ) {
0 commit comments