@@ -3,24 +3,23 @@ import path from 'path';
3
3
import { Context } from '@actions/github/lib/context' ;
4
4
import { PaginateInterface } from '@octokit/plugin-paginate-rest' ;
5
5
import { RestEndpointMethods } from '@octokit/plugin-rest-endpoint-methods/dist-types/generated/method-types' ;
6
- import {
7
- OctokitResponse ,
8
- GitGetCommitResponseData ,
9
- PullsGetResponseData ,
10
- GitCreateTreeResponseData ,
11
- GitCreateCommitResponseData ,
12
- GitGetRefResponseData ,
13
- PullsListResponseData ,
14
- PullsCreateResponseData ,
15
- PullsUpdateResponseData ,
16
- GitListMatchingRefsResponseData ,
17
- } from '@octokit/types' ;
6
+ import { OctokitResponse } from '@octokit/types' ;
7
+ import { components } from '@octokit/openapi-types' ;
18
8
import { exportVariable } from '@actions/core' ;
19
9
import { Logger } from '@technote-space/github-action-log-helper' ;
20
- import { getRefForUpdate , isPrRef , getBranch , trimRef , versionCompare , generateNewPatchVersion , generateNewMajorVersion , generateNewMinorVersion } from './utils' ;
10
+ import { getRefForUpdate , isPrRef , getBranch , trimRef , versionCompare , generateNewPatchVersion , generateNewMajorVersion , generateNewMinorVersion , ensureNotNull } from './utils' ;
21
11
import { getSender } from './context-helper' ;
22
12
import { Octokit } from './types' ;
23
13
14
+ type GitGetCommitResponseData = components [ 'schemas' ] [ 'git-commit' ] ;
15
+ type PullsGetResponseData = components [ 'schemas' ] [ 'pull-request' ] ;
16
+ type GitCreateTreeResponseData = components [ 'schemas' ] [ 'git-tree' ] ;
17
+ type GitCreateCommitResponseData = components [ 'schemas' ] [ 'git-commit' ] ;
18
+ type GitGetRefResponseData = components [ 'schemas' ] [ 'git-ref' ] ;
19
+ type PullsListResponseData = components [ 'schemas' ] [ 'pull-request-simple' ] ;
20
+ type PullsCreateResponseData = components [ 'schemas' ] [ 'pull-request' ] ;
21
+ type PullsUpdateResponseData = components [ 'schemas' ] [ 'pull-request' ] ;
22
+
24
23
type PullsUpdateParams = {
25
24
body ?: string ;
26
25
draft ?: boolean ;
@@ -163,18 +162,18 @@ export default class ApiHelper {
163
162
/**
164
163
* @param {string } rootDir root dir
165
164
* @param {object } files files
166
- * @return {Promise<{ path: string, sha: string }[] > } blobs
165
+ * @return {Promise<Array< { path: string, sha: string }> > } blobs
167
166
*/
168
- public filesToBlobs = async ( rootDir : string , files : Array < string > ) : Promise < { path : string ; sha : string } [ ] > => await Promise . all ( Object . values ( files ) . map ( file => this . createBlob ( rootDir , file ) ) ) ;
167
+ public filesToBlobs = async ( rootDir : string , files : Array < string > ) : Promise < Array < { path : string ; sha : string } > > => await Promise . all ( files . map ( file => this . createBlob ( rootDir , file ) ) ) ;
169
168
170
169
/**
171
- * @param {{ path: string, sha: string }[] } blobs blobs
170
+ * @param {Array< { path: string, sha: string }> } blobs blobs
172
171
* @return {Promise<GitCreateTreeResponseData> } tree
173
172
*/
174
- public createTree = async ( blobs : { path : string ; sha : string } [ ] ) : Promise < GitCreateTreeResponseData > => this . getResponseData ( ( this . octokit as RestEndpointMethods ) . git . createTree ( {
173
+ public createTree = async ( blobs : Array < { path : string ; sha : string } > ) : Promise < GitCreateTreeResponseData > => this . getResponseData ( ( this . octokit as RestEndpointMethods ) . git . createTree ( {
175
174
...this . context . repo ,
176
175
'base_tree' : ( await this . getCommit ( ) ) . tree . sha ,
177
- tree : Object . values ( blobs ) . map ( blob => ( {
176
+ tree : blobs . map ( blob => ( {
178
177
path : blob . path ,
179
178
type : 'blob' ,
180
179
mode : '100644' ,
@@ -220,7 +219,7 @@ export default class ApiHelper {
220
219
await ( this . octokit as RestEndpointMethods ) . git . updateRef ( {
221
220
...this . context . repo ,
222
221
ref : refName ,
223
- sha : commit . sha ,
222
+ sha : ensureNotNull ( commit . sha ) ,
224
223
force,
225
224
} ) ;
226
225
@@ -245,7 +244,7 @@ export default class ApiHelper {
245
244
await ( this . octokit as RestEndpointMethods ) . git . createRef ( {
246
245
...this . context . repo ,
247
246
ref : refName ,
248
- sha : commit . sha ,
247
+ sha : ensureNotNull ( commit . sha ) ,
249
248
} ) ;
250
249
} ;
251
250
@@ -264,7 +263,7 @@ export default class ApiHelper {
264
263
* @param {string } branchName branch name
265
264
* @return {Promise<PullsListResponseData | null> } pull request
266
265
*/
267
- public findPullRequest = async ( branchName : string ) : Promise < PullsListResponseData [ number ] | null > => {
266
+ public findPullRequest = async ( branchName : string ) : Promise < PullsListResponseData | null > => {
268
267
const response = await ( this . octokit as RestEndpointMethods ) . pulls . list ( {
269
268
...this . context . repo ,
270
269
head : `${ this . context . repo . owner } :${ getBranch ( branchName , false ) } ` ,
@@ -278,9 +277,9 @@ export default class ApiHelper {
278
277
279
278
/**
280
279
* @param {PullsListParams } params params
281
- * @return {AsyncIterable<PullsListResponseData> } pull request list
280
+ * @return {AsyncIterable<Array< PullsListResponseData> > } pull request list
282
281
*/
283
- public pullsList = ( params : PullsListParams ) : Promise < PullsListResponseData > => ( this . octokit . paginate as PaginateInterface ) (
282
+ public pullsList = ( params : PullsListParams ) : Promise < Array < PullsListResponseData > > => ( this . octokit . paginate as PaginateInterface ) (
284
283
( this . octokit as RestEndpointMethods ) . pulls . list ,
285
284
Object . assign ( {
286
285
sort : 'created' ,
@@ -403,10 +402,10 @@ export default class ApiHelper {
403
402
private isProtectedBranchError = ( error : Error ) : boolean => / r e q u i r e d s t a t u s c h e c k s ? .* ( i s | a r e ) e x p e c t e d / i. test ( error . message ) ;
404
403
405
404
/**
406
- * @param {string[] } files files
405
+ * @param {Array< string> } files files
407
406
* @return {boolean } diff?
408
407
*/
409
- private checkDiff = ( files : string [ ] ) : boolean => {
408
+ private checkDiff = ( files : Array < string > ) : boolean => {
410
409
if ( ! files . length ) {
411
410
this . callLogger ( logger => logger . info ( 'There is no diff.' ) ) ;
412
411
return false ;
@@ -418,10 +417,10 @@ export default class ApiHelper {
418
417
/**
419
418
* @param {string } rootDir root dir
420
419
* @param {string } commitMessage commit message
421
- * @param {string[] } files files
420
+ * @param {Array< string> } files files
422
421
* @return {Promise<GitCreateCommitResponseData> } commit
423
422
*/
424
- private prepareCommit = async ( rootDir : string , commitMessage : string , files : string [ ] ) : Promise < GitCreateCommitResponseData > => {
423
+ private prepareCommit = async ( rootDir : string , commitMessage : string , files : Array < string > ) : Promise < GitCreateCommitResponseData > => {
425
424
this . callLogger ( logger => logger . startProcess ( 'Creating blobs...' ) ) ;
426
425
const blobs = await this . filesToBlobs ( rootDir , files ) ;
427
426
@@ -435,10 +434,10 @@ export default class ApiHelper {
435
434
/**
436
435
* @param {string } rootDir root dir
437
436
* @param {string } commitMessage commit message
438
- * @param {string[] } files files
437
+ * @param {Array< string> } files files
439
438
* @return {Promise<boolean> } result
440
439
*/
441
- public commit = async ( rootDir : string , commitMessage : string , files : string [ ] ) : Promise < boolean > => {
440
+ public commit = async ( rootDir : string , commitMessage : string , files : Array < string > ) : Promise < boolean > => {
442
441
if ( ! this . checkDiff ( files ) ) {
443
442
return false ;
444
443
}
@@ -459,12 +458,12 @@ export default class ApiHelper {
459
458
/**
460
459
* @param {string } rootDir root dir
461
460
* @param {string } commitMessage commit message
462
- * @param {string[] } files files
461
+ * @param {Array< string> } files files
463
462
* @param {string } createBranchName branch name
464
463
* @param {PullsCreateParams } detail detail
465
464
* @return {Promise<boolean|PullsInfo> } result
466
465
*/
467
- public createPR = async ( rootDir : string , commitMessage : string , files : string [ ] , createBranchName : string , detail : PullsCreateParams ) : Promise < boolean | PullsInfo > => {
466
+ public createPR = async ( rootDir : string , commitMessage : string , files : Array < string > , createBranchName : string , detail : PullsCreateParams ) : Promise < boolean | PullsInfo > => {
468
467
if ( ! this . checkDiff ( files ) ) {
469
468
return false ;
470
469
}
@@ -530,8 +529,8 @@ export default class ApiHelper {
530
529
531
530
return {
532
531
login : user . login ,
533
- email : user . email ,
534
- name : user . name ,
532
+ email : ensureNotNull ( user . email ) ,
533
+ name : ensureNotNull ( user . name ) ,
535
534
id : user . id ,
536
535
} ;
537
536
} ;
@@ -552,7 +551,7 @@ export default class ApiHelper {
552
551
...this . context . repo ,
553
552
ref : 'tags/' ,
554
553
} ,
555
- ) ) . map ( ( item ) : string => trimRef ( ( item as GitListMatchingRefsResponseData [ number ] ) . ref ) ) ;
554
+ ) ) . map ( ( item ) : string => trimRef ( item . ref ) ) ;
556
555
557
556
/**
558
557
* @return {Promise<string> } tag
0 commit comments