1
1
import * as core from "@actions/core" ;
2
2
import * as fs from "fs" ;
3
3
import * as os from "os" ;
4
+ import typia from "typia" ;
4
5
import * as util from "util" ;
5
6
import { spawnSync } from "child_process" ;
6
7
import addressparser from "nodemailer/lib/addressparser/index.js" ;
@@ -53,8 +54,24 @@ export class CIHelper {
53
54
return configFile ? await getExternalConfig ( configFile ) : getConfig ( ) ;
54
55
}
55
56
57
+ public static validateConfig = typia . createValidate < IConfig > ( ) ;
58
+
59
+ protected static getConfigAsGitHubActionInput ( ) : IConfig | undefined {
60
+ if ( process . env . GITHUB_ACTIONS !== "true" ) return undefined ;
61
+ const json = core . getInput ( "config" ) ;
62
+ if ( ! json ) return undefined ;
63
+ const config = JSON . parse ( json ) as IConfig | undefined ;
64
+ const result = CIHelper . validateConfig ( config ) ;
65
+ if ( result . success ) return config ;
66
+ throw new Error (
67
+ `Invalid config:\n- ${ result . errors
68
+ . map ( ( e ) => `${ e . path } (value: ${ e . value } , expected: ${ e . expected } ): ${ e . description } ` )
69
+ . join ( "\n- " ) } `,
70
+ ) ;
71
+ }
72
+
56
73
public constructor ( workDir : string = "pr-repo.git" , config ?: IConfig , skipUpdate ?: boolean , gggConfigDir = "." ) {
57
- this . config = config !== undefined ? setConfig ( config ) : getConfig ( ) ;
74
+ this . config = config !== undefined ? setConfig ( config ) : CIHelper . getConfigAsGitHubActionInput ( ) || getConfig ( ) ;
58
75
this . gggConfigDir = gggConfigDir ;
59
76
this . workDir = workDir ;
60
77
this . notes = new GitNotes ( workDir ) ;
@@ -101,7 +118,7 @@ export class CIHelper {
101
118
102
119
// get the access tokens via the inputs of the GitHub Action
103
120
this . setAccessToken ( this . config . repo . owner , core . getInput ( "pr-repo-token" ) ) ;
104
- this . setAccessToken ( this . config . repo . baseOwner , core . getInput ( "upstream-repo-token" ) ) ;
121
+ this . setAccessToken ( this . config . repo . upstreamOwner , core . getInput ( "upstream-repo-token" ) ) ;
105
122
if ( this . config . repo . testOwner ) {
106
123
this . setAccessToken ( this . config . repo . testOwner , core . getInput ( "test-repo-token" ) ) ;
107
124
}
@@ -128,7 +145,7 @@ export class CIHelper {
128
145
[ "remote.origin.url" , `https://github.com/${ this . config . repo . owner } /${ this . config . repo . name } ` ] ,
129
146
[ "remote.origin.promisor" , "true" ] ,
130
147
[ "remote.origin.partialCloneFilter" , "blob:none" ] ,
131
- [ "remote.upstream.url" , `https://github.com/${ this . config . repo . baseOwner } /${ this . config . repo . name } ` ] ,
148
+ [ "remote.upstream.url" , `https://github.com/${ this . config . repo . upstreamOwner } /${ this . config . repo . name } ` ] ,
132
149
[ "remote.upstream.promisor" , "true" ] ,
133
150
[ "remote.upstream.partialCloneFilter" , "blob:none" ] ,
134
151
] ) {
@@ -175,7 +192,7 @@ export class CIHelper {
175
192
console . time ( "get open PR head commits" ) ;
176
193
const openPRCommits = (
177
194
await Promise . all (
178
- this . config . repo . owners . map ( async ( repositoryOwner ) => {
195
+ this . config . app . installedOn . map ( async ( repositoryOwner ) => {
179
196
return await this . github . getOpenPRs ( repositoryOwner ) ;
180
197
} ) ,
181
198
)
@@ -256,7 +273,7 @@ export class CIHelper {
256
273
const prCommentUrl = core . getInput ( "pr-comment-url" ) ;
257
274
const [ , owner , repo , prNumber , commentId ] =
258
275
prCommentUrl . match ( / ^ h t t p s : \/ \/ g i t h u b \. c o m \/ ( [ ^ / ] + ) \/ ( [ ^ / ] + ) \/ p u l l \/ ( \d + ) # i s s u e c o m m e n t - ( \d + ) $ / ) || [ ] ;
259
- if ( ! this . config . repo . owners . includes ( owner ) || repo !== this . config . repo . name ) {
276
+ if ( ! this . config . app . installedOn . includes ( owner ) || repo !== this . config . repo . name ) {
260
277
throw new Error ( `Invalid PR comment URL: ${ prCommentUrl } ` ) ;
261
278
}
262
279
return { owner, repo, prNumber : parseInt ( prNumber , 10 ) , commentId : parseInt ( commentId , 10 ) } ;
@@ -266,7 +283,7 @@ export class CIHelper {
266
283
const prUrl = core . getInput ( "pr-url" ) ;
267
284
268
285
const [ , owner , repo , prNumber ] = prUrl . match ( / ^ h t t p s : \/ \/ g i t h u b \. c o m \/ ( [ ^ / ] + ) \/ ( [ ^ / ] + ) \/ p u l l \/ ( \d + ) $ / ) || [ ] ;
269
- if ( ! this . config . repo . owners . includes ( owner ) || repo !== this . config . repo . name ) {
286
+ if ( ! this . config . app . installedOn . includes ( owner ) || repo !== this . config . repo . name ) {
270
287
throw new Error ( `Invalid PR URL: ${ prUrl } ` ) ;
271
288
}
272
289
return { owner, repo, prNumber : parseInt ( prNumber , 10 ) } ;
@@ -411,7 +428,7 @@ export class CIHelper {
411
428
mailMeta . originalCommit ,
412
429
upstreamCommit ,
413
430
this . config . repo . owner ,
414
- this . config . repo . baseOwner ,
431
+ this . config . repo . upstreamOwner ,
415
432
) ;
416
433
}
417
434
@@ -654,7 +671,7 @@ export class CIHelper {
654
671
655
672
// Add comment on GitHub
656
673
const comment = `This patch series was integrated into ${ branch } via https://github.com/${
657
- this . config . repo . baseOwner
674
+ this . config . repo . upstreamOwner
658
675
} /${ this . config . repo . name } /commit/${ mergeCommit } .`;
659
676
const url = await this . github . addPRComment ( prKey , comment ) ;
660
677
console . log ( `Added comment ${ url . id } about ${ branch } : ${ url . url } ` ) ;
@@ -892,7 +909,7 @@ export class CIHelper {
892
909
await addComment (
893
910
`Submitted as [${
894
911
metadata ?. coverLetterMessageId
895
- } ](https:// ${ this . config . mailrepo . host } / ${ this . config . mailrepo . name } /${
912
+ } ](${ this . config . mailrepo . url . replace ( / \/ + $ / , "" ) } /${
896
913
metadata ?. coverLetterMessageId
897
914
} )\n\nTo fetch this version into \`FETCH_HEAD\`:${
898
915
code
@@ -1139,7 +1156,7 @@ export class CIHelper {
1139
1156
const handledPRs = new Set < string > ( ) ;
1140
1157
const handledMessageIDs = new Set < string > ( ) ;
1141
1158
1142
- for ( const repositoryOwner of this . config . repo . owners ) {
1159
+ for ( const repositoryOwner of this . config . app . installedOn ) {
1143
1160
const pullRequests = await this . github . getOpenPRs ( repositoryOwner ) ;
1144
1161
1145
1162
for ( const pr of pullRequests ) {
@@ -1197,7 +1214,7 @@ export class CIHelper {
1197
1214
private async getPRInfo ( prKey : pullRequestKey ) : Promise < IPullRequestInfo > {
1198
1215
const pr = await this . github . getPRInfo ( prKey ) ;
1199
1216
1200
- if ( ! this . config . repo . owners . includes ( pr . baseOwner ) || pr . baseRepo !== this . config . repo . name ) {
1217
+ if ( ! this . config . app . installedOn . includes ( pr . baseOwner ) || pr . baseRepo !== this . config . repo . name ) {
1201
1218
throw new Error ( `Unsupported repository: ${ pr . pullRequestURL } ` ) ;
1202
1219
}
1203
1220
0 commit comments