1
1
import fs from 'fs' ;
2
2
import path from 'path' ;
3
- import { GitHub } from '@actions/github/lib/github' ;
4
3
import { Context } from '@actions/github/lib/context' ;
5
- import {
6
- Response ,
7
- AnyResponse ,
8
- GitCreateTreeResponse ,
9
- GitCreateCommitResponse ,
10
- GitGetCommitResponse ,
11
- PullsGetResponse ,
12
- PullsListResponseItem ,
13
- PullsCreateResponse ,
14
- PullsUpdateResponse ,
15
- } from '@octokit/rest' ;
4
+ import { Octokit } from '@octokit/rest' ;
16
5
import { exportVariable } from '@actions/core' ;
17
6
import { Logger } from './index' ;
18
7
import { getRefForUpdate , isPrRef , getBranch } from './utils' ;
@@ -55,10 +44,10 @@ export default class ApiHelper {
55
44
private readonly sender ?: string | undefined = undefined ;
56
45
private readonly suppressBPError ?: boolean | undefined = undefined ;
57
46
private readonly refForUpdate ?: string | undefined = undefined ;
58
- private prCache : { [ key : number ] : Response < PullsGetResponse > } = { } ;
47
+ private prCache : { [ key : number ] : Octokit . Response < Octokit . PullsGetResponse > } = { } ;
59
48
60
49
/**
61
- * @param {GitHub } octokit octokit
50
+ * @param {Octokit } octokit octokit
62
51
* @param {Context } context context
63
52
* @param {Logger } logger logger
64
53
* @param {object } options options
@@ -68,7 +57,7 @@ export default class ApiHelper {
68
57
* @param {boolean|undefined } options.suppressBPError suppress branch protection error?
69
58
*/
70
59
constructor (
71
- private readonly octokit : GitHub ,
60
+ private readonly octokit : Octokit ,
72
61
private readonly context : Context ,
73
62
private readonly logger : Logger ,
74
63
options ?: { branch ?: string ; sender ?: string ; refForUpdate ?: string ; suppressBPError ?: boolean } ,
@@ -120,18 +109,18 @@ export default class ApiHelper {
120
109
private getCommitSha = ( ) : string => isPrRef ( this . context ) && this . context . payload . pull_request ? this . context . payload . pull_request . head . sha : this . context . sha ;
121
110
122
111
/**
123
- * @return {Promise<Response<GitGetCommitResponse>> } commit
112
+ * @return {Promise<Octokit. Response<Octokit. GitGetCommitResponse>> } commit
124
113
*/
125
- private getCommit = async ( ) : Promise < Response < GitGetCommitResponse > > => this . octokit . git . getCommit ( {
114
+ private getCommit = async ( ) : Promise < Octokit . Response < Octokit . GitGetCommitResponse > > => this . octokit . git . getCommit ( {
126
115
owner : this . context . repo . owner ,
127
116
repo : this . context . repo . repo ,
128
117
'commit_sha' : this . getCommitSha ( ) ,
129
118
} ) ;
130
119
131
120
/**
132
- * @return {Promise<Response<PullsGetResponse>> } commit
121
+ * @return {Promise<Octokit. Response<Octokit. PullsGetResponse>> } commit
133
122
*/
134
- private getPR = async ( ) : Promise < Response < PullsGetResponse > > => {
123
+ private getPR = async ( ) : Promise < Octokit . Response < Octokit . PullsGetResponse > > => {
135
124
const key = parseInt ( this . context . payload . number , 10 ) ;
136
125
if ( ! ( key in this . prCache ) ) {
137
126
this . prCache [ key ] = await this . octokit . pulls . get ( {
@@ -153,9 +142,9 @@ export default class ApiHelper {
153
142
154
143
/**
155
144
* @param {{ path: string, sha: string }[] } blobs blobs
156
- * @return {Promise<Response<GitCreateTreeResponse>> } tree
145
+ * @return {Promise<Octokit. Response<Octokit. GitCreateTreeResponse>> } tree
157
146
*/
158
- public createTree = async ( blobs : { path : string ; sha : string } [ ] ) : Promise < Response < GitCreateTreeResponse > > => this . octokit . git . createTree ( {
147
+ public createTree = async ( blobs : { path : string ; sha : string } [ ] ) : Promise < Octokit . Response < Octokit . GitCreateTreeResponse > > => this . octokit . git . createTree ( {
159
148
owner : this . context . repo . owner ,
160
149
repo : this . context . repo . repo ,
161
150
'base_tree' : ( await this . getCommit ( ) ) . data . tree . sha ,
@@ -169,10 +158,10 @@ export default class ApiHelper {
169
158
170
159
/**
171
160
* @param {string } commitMessage commit message
172
- * @param {Response<GitCreateTreeResponse> } tree tree
173
- * @return {Promise<Response<GitCreateCommitResponse>> } commit
161
+ * @param {Octokit. Response<Octokit. GitCreateTreeResponse> } tree tree
162
+ * @return {Promise<Octokit. Response<Octokit. GitCreateCommitResponse>> } commit
174
163
*/
175
- public createCommit = async ( commitMessage : string , tree : Response < GitCreateTreeResponse > ) : Promise < Response < GitCreateCommitResponse > > => this . octokit . git . createCommit ( {
164
+ public createCommit = async ( commitMessage : string , tree : Octokit . Response < Octokit . GitCreateTreeResponse > ) : Promise < Octokit . Response < Octokit . GitCreateCommitResponse > > => this . octokit . git . createCommit ( {
176
165
owner : this . context . repo . owner ,
177
166
repo : this . context . repo . repo ,
178
167
tree : tree . data . sha ,
@@ -182,9 +171,9 @@ export default class ApiHelper {
182
171
183
172
/**
184
173
* @param {string } refName refName
185
- * @return {Promise<AnyResponse|null> } refName
174
+ * @return {Promise<Octokit. AnyResponse|null> } refName
186
175
*/
187
- private getRef = async ( refName : string ) : Promise < AnyResponse | null > => {
176
+ private getRef = async ( refName : string ) : Promise < Octokit . AnyResponse | null > => {
188
177
try {
189
178
return await this . octokit . git . getRef ( {
190
179
owner : this . context . repo . owner ,
@@ -197,12 +186,12 @@ export default class ApiHelper {
197
186
} ;
198
187
199
188
/**
200
- * @param {Response<GitCreateCommitResponse> } commit commit
189
+ * @param {Octokit. Response<Octokit. GitCreateCommitResponse> } commit commit
201
190
* @param {string } refName refName
202
191
* @param {boolean } force force
203
192
* @return {Promise<void> } void
204
193
*/
205
- public updateRef = async ( commit : Response < GitCreateCommitResponse > , refName : string , force : boolean ) : Promise < boolean > => {
194
+ public updateRef = async ( commit : Octokit . Response < Octokit . GitCreateCommitResponse > , refName : string , force : boolean ) : Promise < boolean > => {
206
195
try {
207
196
await this . octokit . git . updateRef ( {
208
197
owner : this . context . repo . owner ,
@@ -225,11 +214,11 @@ export default class ApiHelper {
225
214
} ;
226
215
227
216
/**
228
- * @param {Response<GitCreateCommitResponse> } commit commit
217
+ * @param {Octokit. Response<Octokit. GitCreateCommitResponse> } commit commit
229
218
* @param {string } refName refName
230
219
* @return {Promise<void> } void
231
220
*/
232
- public createRef = async ( commit : Response < GitCreateCommitResponse > , refName : string ) : Promise < void > => {
221
+ public createRef = async ( commit : Octokit . Response < Octokit . GitCreateCommitResponse > , refName : string ) : Promise < void > => {
233
222
await this . octokit . git . createRef ( {
234
223
owner : this . context . repo . owner ,
235
224
repo : this . context . repo . repo ,
@@ -252,9 +241,9 @@ export default class ApiHelper {
252
241
253
242
/**
254
243
* @param {string } branchName branch name
255
- * @return {Promise<PullsListResponseItem> } pull request
244
+ * @return {Promise<Octokit. PullsListResponseItem> } pull request
256
245
*/
257
- public findPullRequest = async ( branchName : string ) : Promise < PullsListResponseItem | null > => {
246
+ public findPullRequest = async ( branchName : string ) : Promise < Octokit . PullsListResponseItem | null > => {
258
247
const response = await this . octokit . pulls . list ( {
259
248
owner : this . context . repo . owner ,
260
249
repo : this . context . repo . repo ,
@@ -269,9 +258,9 @@ export default class ApiHelper {
269
258
270
259
/**
271
260
* @param {PullsListParams } params params
272
- * @return {AsyncIterable<PullsListResponseItem> } pull request list
261
+ * @return {AsyncIterable<Octokit. PullsListResponseItem> } pull request list
273
262
*/
274
- public async * pullsList ( params : PullsListParams ) : AsyncIterable < PullsListResponseItem > {
263
+ public async * pullsList ( params : PullsListParams ) : AsyncIterable < Octokit . PullsListResponseItem > {
275
264
const perPage = 100 ;
276
265
let page = 1 ;
277
266
while ( true ) {
@@ -295,9 +284,9 @@ export default class ApiHelper {
295
284
/**
296
285
* @param {string } branchName branch name
297
286
* @param {PullsCreateParams } detail detail
298
- * @return {Promise<PullsCreateResponse> } pull
287
+ * @return {Promise<Octokit.Response<Octokit. PullsCreateResponse> > } pull
299
288
*/
300
- public pullsCreate = async ( branchName : string , detail : PullsCreateParams ) : Promise < Response < PullsCreateResponse > > => this . octokit . pulls . create ( {
289
+ public pullsCreate = async ( branchName : string , detail : PullsCreateParams ) : Promise < Octokit . Response < Octokit . PullsCreateResponse > > => this . octokit . pulls . create ( {
301
290
owner : this . context . repo . owner ,
302
291
repo : this . context . repo . repo ,
303
292
head : `${ this . context . repo . owner } :${ getBranch ( branchName , false ) } ` ,
@@ -308,9 +297,9 @@ export default class ApiHelper {
308
297
/**
309
298
* @param {number } number pull number
310
299
* @param {PullsUpdateParams } detail detail
311
- * @return {Promise<PullsUpdateResponse> } pull
300
+ * @return {Promise<Octokit.Response<Octokit. PullsUpdateResponse> > } pull
312
301
*/
313
- public pullsUpdate = async ( number : number , detail : PullsUpdateParams ) : Promise < Response < PullsUpdateResponse > > => this . octokit . pulls . update ( {
302
+ public pullsUpdate = async ( number : number , detail : PullsUpdateParams ) : Promise < Octokit . Response < Octokit . PullsUpdateResponse > > => this . octokit . pulls . update ( {
314
303
owner : this . context . repo . owner ,
315
304
repo : this . context . repo . repo ,
316
305
'pull_number' : number ,
@@ -418,9 +407,9 @@ export default class ApiHelper {
418
407
* @param {string } rootDir root dir
419
408
* @param {string } commitMessage commit message
420
409
* @param {string[] } files files
421
- * @return {Promise<Response<GitCreateCommitResponse>> } commit
410
+ * @return {Promise<Octokit. Response<Octokit. GitCreateCommitResponse>> } commit
422
411
*/
423
- private prepareCommit = async ( rootDir : string , commitMessage : string , files : string [ ] ) : Promise < Response < GitCreateCommitResponse > > => {
412
+ private prepareCommit = async ( rootDir : string , commitMessage : string , files : string [ ] ) : Promise < Octokit . Response < Octokit . GitCreateCommitResponse > > => {
424
413
this . logger . startProcess ( 'Creating blobs...' ) ;
425
414
const blobs = await this . filesToBlobs ( rootDir , files ) ;
426
415
0 commit comments