Skip to content

Commit a2a3b52

Browse files
Merge pull request #210 from technote-space/release/v0.8.3
release/v0.8.3
2 parents 3583137 + 409444f commit a2a3b52

File tree

6 files changed

+169
-199
lines changed

6 files changed

+169
-199
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
/node_modules
33
/coverage
44
/dist
5+
.eslintcache

__tests__/api-helper1.test.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
/* eslint-disable no-magic-numbers */
22
import nock from 'nock';
33
import path from 'path';
4-
import { GitHub } from '@actions/github' ;
5-
import { GitCreateTreeResponse, GitCreateCommitResponse } from '@octokit/rest';
4+
import { Octokit } from '@octokit/rest';
65
import {
76
disableNetConnect,
87
testEnv,
@@ -30,10 +29,10 @@ const context = getContext({
3029
number: 123,
3130
},
3231
});
33-
const octokit = new GitHub('test-token');
32+
const octokit = new Octokit({auth: 'token test-token'});
3433
const logger = new Logger();
3534

36-
const createCommitResponse = createResponse<GitCreateCommitResponse>({
35+
const createCommitResponse = createResponse<Octokit.GitCreateCommitResponse>({
3736
author: {
3837
date: '',
3938
email: '',
@@ -160,7 +159,7 @@ describe('ApiHelper', () => {
160159
return getApiFixture(rootDir, 'repos.git.commits');
161160
});
162161

163-
const commit = await helper.createCommit('test commit message', createResponse<GitCreateTreeResponse>({
162+
const commit = await helper.createCommit('test commit message', createResponse<Octokit.GitCreateTreeResponse>({
164163
sha: 'tree-sha',
165164
tree: [],
166165
url: '',
@@ -197,7 +196,7 @@ describe('ApiHelper', () => {
197196
},
198197
},
199198
}), logger);
200-
const commit = await helper.createCommit('test commit message', createResponse<GitCreateTreeResponse>({
199+
const commit = await helper.createCommit('test commit message', createResponse<Octokit.GitCreateTreeResponse>({
201200
sha: 'tree-sha',
202201
tree: [],
203202
url: '',

__tests__/api-helper2.test.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
/* eslint-disable no-magic-numbers */
22
import nock from 'nock';
33
import path from 'path';
4-
import { GitHub } from '@actions/github' ;
5-
import { GitCreateCommitResponse } from '@octokit/rest';
4+
import { Octokit } from '@octokit/rest';
65
import {
76
disableNetConnect,
87
testEnv,
@@ -30,10 +29,10 @@ const context = getContext({
3029
number: 123,
3130
},
3231
});
33-
const octokit = new GitHub('test-token');
32+
const octokit = new Octokit({auth: 'token test-token'});
3433
const logger = new Logger();
3534

36-
const createCommitResponse = createResponse<GitCreateCommitResponse>({
35+
const createCommitResponse = createResponse<Octokit.GitCreateCommitResponse>({
3736
author: {
3837
date: '',
3938
email: '',

package.json

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
{
22
"name": "@technote-space/github-action-helper",
3-
"version": "0.8.2",
3+
"version": "0.8.3",
44
"description": "Helper to filter GitHub Action.",
5-
"author": "Technote <[email protected]> (https://technote.space)",
5+
"author": {
6+
"name": "Technote",
7+
"email": "[email protected]",
8+
"url": "https://technote.space"
9+
},
610
"license": "MIT",
711
"keywords": [
812
"github",
@@ -28,16 +32,16 @@
2832
"sprintf-js": "^1.1.2"
2933
},
3034
"devDependencies": {
31-
"@technote-space/github-action-test-helper": "^0.1.4",
32-
"@types/jest": "^24.9.1",
33-
"@types/node": "^13.5.0",
34-
"@typescript-eslint/eslint-plugin": "^2.17.0",
35-
"@typescript-eslint/parser": "^2.17.0",
35+
"@technote-space/github-action-test-helper": "^0.1.5",
36+
"@types/jest": "^25.1.1",
37+
"@types/node": "^13.7.0",
38+
"@typescript-eslint/eslint-plugin": "^2.19.0",
39+
"@typescript-eslint/parser": "^2.19.0",
3640
"eslint": "^6.8.0",
3741
"jest": "^25.1.0",
3842
"jest-circus": "^25.1.0",
3943
"nock": "^11.7.2",
40-
"ts-jest": "^25.0.0",
44+
"ts-jest": "^25.2.0",
4145
"typescript": "^3.7.5"
4246
},
4347
"publishConfig": {
@@ -46,7 +50,7 @@
4650
"scripts": {
4751
"build": "tsc",
4852
"test": "yarn lint && yarn cover",
49-
"lint": "eslint 'src/**/*.ts' '__tests__/**/*.ts'",
53+
"lint": "eslint 'src/**/*.ts' '__tests__/**/*.ts' --cache",
5054
"lint:fix": "eslint --fix 'src/**/*.ts' '__tests__/**/*.ts'",
5155
"cover": "jest --coverage",
5256
"update": "ncu -u && yarn install && yarn upgrade && yarn audit"

src/api-helper.ts

Lines changed: 29 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,7 @@
11
import fs from 'fs';
22
import path from 'path';
3-
import { GitHub } from '@actions/github/lib/github';
43
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';
165
import { exportVariable } from '@actions/core';
176
import { Logger } from './index';
187
import { getRefForUpdate, isPrRef, getBranch } from './utils';
@@ -55,10 +44,10 @@ export default class ApiHelper {
5544
private readonly sender?: string | undefined = undefined;
5645
private readonly suppressBPError?: boolean | undefined = undefined;
5746
private readonly refForUpdate?: string | undefined = undefined;
58-
private prCache: { [key: number]: Response<PullsGetResponse> } = {};
47+
private prCache: { [key: number]: Octokit.Response<Octokit.PullsGetResponse> } = {};
5948

6049
/**
61-
* @param {GitHub} octokit octokit
50+
* @param {Octokit} octokit octokit
6251
* @param {Context} context context
6352
* @param {Logger} logger logger
6453
* @param {object} options options
@@ -68,7 +57,7 @@ export default class ApiHelper {
6857
* @param {boolean|undefined} options.suppressBPError suppress branch protection error?
6958
*/
7059
constructor(
71-
private readonly octokit: GitHub,
60+
private readonly octokit: Octokit,
7261
private readonly context: Context,
7362
private readonly logger: Logger,
7463
options?: { branch?: string; sender?: string; refForUpdate?: string; suppressBPError?: boolean },
@@ -120,18 +109,18 @@ export default class ApiHelper {
120109
private getCommitSha = (): string => isPrRef(this.context) && this.context.payload.pull_request ? this.context.payload.pull_request.head.sha : this.context.sha;
121110

122111
/**
123-
* @return {Promise<Response<GitGetCommitResponse>>} commit
112+
* @return {Promise<Octokit.Response<Octokit.GitGetCommitResponse>>} commit
124113
*/
125-
private getCommit = async(): Promise<Response<GitGetCommitResponse>> => this.octokit.git.getCommit({
114+
private getCommit = async(): Promise<Octokit.Response<Octokit.GitGetCommitResponse>> => this.octokit.git.getCommit({
126115
owner: this.context.repo.owner,
127116
repo: this.context.repo.repo,
128117
'commit_sha': this.getCommitSha(),
129118
});
130119

131120
/**
132-
* @return {Promise<Response<PullsGetResponse>>} commit
121+
* @return {Promise<Octokit.Response<Octokit.PullsGetResponse>>} commit
133122
*/
134-
private getPR = async(): Promise<Response<PullsGetResponse>> => {
123+
private getPR = async(): Promise<Octokit.Response<Octokit.PullsGetResponse>> => {
135124
const key = parseInt(this.context.payload.number, 10);
136125
if (!(key in this.prCache)) {
137126
this.prCache[key] = await this.octokit.pulls.get({
@@ -153,9 +142,9 @@ export default class ApiHelper {
153142

154143
/**
155144
* @param {{ path: string, sha: string }[]} blobs blobs
156-
* @return {Promise<Response<GitCreateTreeResponse>>} tree
145+
* @return {Promise<Octokit.Response<Octokit.GitCreateTreeResponse>>} tree
157146
*/
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({
159148
owner: this.context.repo.owner,
160149
repo: this.context.repo.repo,
161150
'base_tree': (await this.getCommit()).data.tree.sha,
@@ -169,10 +158,10 @@ export default class ApiHelper {
169158

170159
/**
171160
* @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
174163
*/
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({
176165
owner: this.context.repo.owner,
177166
repo: this.context.repo.repo,
178167
tree: tree.data.sha,
@@ -182,9 +171,9 @@ export default class ApiHelper {
182171

183172
/**
184173
* @param {string} refName refName
185-
* @return {Promise<AnyResponse|null>} refName
174+
* @return {Promise<Octokit.AnyResponse|null>} refName
186175
*/
187-
private getRef = async(refName: string): Promise<AnyResponse | null> => {
176+
private getRef = async(refName: string): Promise<Octokit.AnyResponse | null> => {
188177
try {
189178
return await this.octokit.git.getRef({
190179
owner: this.context.repo.owner,
@@ -197,12 +186,12 @@ export default class ApiHelper {
197186
};
198187

199188
/**
200-
* @param {Response<GitCreateCommitResponse>} commit commit
189+
* @param {Octokit.Response<Octokit.GitCreateCommitResponse>} commit commit
201190
* @param {string} refName refName
202191
* @param {boolean} force force
203192
* @return {Promise<void>} void
204193
*/
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> => {
206195
try {
207196
await this.octokit.git.updateRef({
208197
owner: this.context.repo.owner,
@@ -225,11 +214,11 @@ export default class ApiHelper {
225214
};
226215

227216
/**
228-
* @param {Response<GitCreateCommitResponse>} commit commit
217+
* @param {Octokit.Response<Octokit.GitCreateCommitResponse>} commit commit
229218
* @param {string} refName refName
230219
* @return {Promise<void>} void
231220
*/
232-
public createRef = async(commit: Response<GitCreateCommitResponse>, refName: string): Promise<void> => {
221+
public createRef = async(commit: Octokit.Response<Octokit.GitCreateCommitResponse>, refName: string): Promise<void> => {
233222
await this.octokit.git.createRef({
234223
owner: this.context.repo.owner,
235224
repo: this.context.repo.repo,
@@ -252,9 +241,9 @@ export default class ApiHelper {
252241

253242
/**
254243
* @param {string} branchName branch name
255-
* @return {Promise<PullsListResponseItem>} pull request
244+
* @return {Promise<Octokit.PullsListResponseItem>} pull request
256245
*/
257-
public findPullRequest = async(branchName: string): Promise<PullsListResponseItem | null> => {
246+
public findPullRequest = async(branchName: string): Promise<Octokit.PullsListResponseItem | null> => {
258247
const response = await this.octokit.pulls.list({
259248
owner: this.context.repo.owner,
260249
repo: this.context.repo.repo,
@@ -269,9 +258,9 @@ export default class ApiHelper {
269258

270259
/**
271260
* @param {PullsListParams} params params
272-
* @return {AsyncIterable<PullsListResponseItem>} pull request list
261+
* @return {AsyncIterable<Octokit.PullsListResponseItem>} pull request list
273262
*/
274-
public async* pullsList(params: PullsListParams): AsyncIterable<PullsListResponseItem> {
263+
public async* pullsList(params: PullsListParams): AsyncIterable<Octokit.PullsListResponseItem> {
275264
const perPage = 100;
276265
let page = 1;
277266
while (true) {
@@ -295,9 +284,9 @@ export default class ApiHelper {
295284
/**
296285
* @param {string} branchName branch name
297286
* @param {PullsCreateParams} detail detail
298-
* @return {Promise<PullsCreateResponse>} pull
287+
* @return {Promise<Octokit.Response<Octokit.PullsCreateResponse>>} pull
299288
*/
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({
301290
owner: this.context.repo.owner,
302291
repo: this.context.repo.repo,
303292
head: `${this.context.repo.owner}:${getBranch(branchName, false)}`,
@@ -308,9 +297,9 @@ export default class ApiHelper {
308297
/**
309298
* @param {number} number pull number
310299
* @param {PullsUpdateParams} detail detail
311-
* @return {Promise<PullsUpdateResponse>} pull
300+
* @return {Promise<Octokit.Response<Octokit.PullsUpdateResponse>>} pull
312301
*/
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({
314303
owner: this.context.repo.owner,
315304
repo: this.context.repo.repo,
316305
'pull_number': number,
@@ -418,9 +407,9 @@ export default class ApiHelper {
418407
* @param {string} rootDir root dir
419408
* @param {string} commitMessage commit message
420409
* @param {string[]} files files
421-
* @return {Promise<Response<GitCreateCommitResponse>>} commit
410+
* @return {Promise<Octokit.Response<Octokit.GitCreateCommitResponse>>} commit
422411
*/
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>> => {
424413
this.logger.startProcess('Creating blobs...');
425414
const blobs = await this.filesToBlobs(rootDir, files);
426415

0 commit comments

Comments
 (0)