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