Skip to content

Commit 0303c12

Browse files
Merge pull request #212 from technote-space/release/v0.8.4
Release/v0.8.4
2 parents a2a3b52 + e58956e commit 0303c12

File tree

6 files changed

+40
-9
lines changed

6 files changed

+40
-9
lines changed

__tests__/api-helper1.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import nock from 'nock';
33
import path from 'path';
44
import { Octokit } from '@octokit/rest';
5+
import { Utils } from '../src';
56
import {
67
disableNetConnect,
78
testEnv,
@@ -29,7 +30,7 @@ const context = getContext({
2930
number: 123,
3031
},
3132
});
32-
const octokit = new Octokit({auth: 'token test-token'});
33+
const octokit = Utils.getOctokit('test-token');
3334
const logger = new Logger();
3435

3536
const createCommitResponse = createResponse<Octokit.GitCreateCommitResponse>({

__tests__/api-helper2.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import nock from 'nock';
33
import path from 'path';
44
import { Octokit } from '@octokit/rest';
5+
import { Utils } from '../src';
56
import {
67
disableNetConnect,
78
testEnv,
@@ -29,7 +30,7 @@ const context = getContext({
2930
number: 123,
3031
},
3132
});
32-
const octokit = new Octokit({auth: 'token test-token'});
33+
const octokit = Utils.getOctokit('test-token');
3334
const logger = new Logger();
3435

3536
const createCommitResponse = createResponse<Octokit.GitCreateCommitResponse>({

__tests__/utils.test.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import path from 'path';
33
import { testEnv, getContext, testFs } from '@technote-space/github-action-test-helper';
44
import { Utils } from '../src';
55

6-
const {getWorkspace, getActor, escapeRegExp, getRegExp, getPrefixRegExp, getSuffixRegExp, useNpm, versionCompare} = Utils;
7-
const {isSemanticVersioningTagName, isPrRef, getPrMergeRef, getBoolValue, replaceAll, getPrHeadRef, arrayChunk, sleep} = Utils;
8-
const {getBranch, getRefForUpdate, uniqueArray, getBuildInfo, split, getArrayInput, generateNewPatchVersion, getPrBranch} = Utils;
6+
const {getWorkspace, getActor, escapeRegExp, getRegExp, getPrefixRegExp, getSuffixRegExp, useNpm, versionCompare, getOctokit} = Utils;
7+
const {isSemanticVersioningTagName, isPrRef, getPrMergeRef, getBoolValue, replaceAll, getPrHeadRef, arrayChunk, sleep} = Utils;
8+
const {getBranch, getRefForUpdate, uniqueArray, getBuildInfo, split, getArrayInput, generateNewPatchVersion, getPrBranch} = Utils;
99

1010
jest.useFakeTimers();
1111

@@ -465,3 +465,20 @@ describe('versionCompare', () => {
465465
expect(versionCompare('v1.2.3', 'v1.2.4', false)).toBe(-1);
466466
});
467467
});
468+
469+
describe('getOctokit', () => {
470+
testEnv();
471+
472+
it('should use env token', () => {
473+
process.env.INPUT_GITHUB_TOKEN = 'input token';
474+
expect(() => getOctokit()).not.toThrow();
475+
});
476+
477+
it('should use input token', () => {
478+
expect(() => getOctokit('input token')).not.toThrow();
479+
});
480+
481+
it('should throw error', () => {
482+
expect(() => getOctokit()).toThrow();
483+
});
484+
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@technote-space/github-action-helper",
3-
"version": "0.8.3",
3+
"version": "0.8.4",
44
"description": "Helper to filter GitHub Action.",
55
"author": {
66
"name": "Technote",

src/utils.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import fs from 'fs';
22
import path from 'path';
33
import { getInput } from '@actions/core' ;
4+
import { GitHub } from '@actions/github';
45
import { Context } from '@actions/github/lib/context';
6+
import { Octokit } from '@octokit/rest';
57

68
const getRef = (ref: string | Context): string => typeof ref === 'string' ? ref : ref.ref;
79

@@ -56,6 +58,16 @@ export const getPrBranch = (context: Context): string => context.payload.pull_re
5658

5759
export const getAccessToken = (required: boolean): string => getInput('GITHUB_TOKEN', {required});
5860

61+
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
62+
// @ts-ignore
63+
export const getOctokit = (token?: string): Octokit => new GitHub(token ?? getAccessToken(true), {
64+
log: {
65+
// eslint-disable-next-line @typescript-eslint/no-empty-function
66+
warn: function(): void {
67+
},
68+
},
69+
});
70+
5971
export const getActor = (): string => process.env.GITHUB_ACTOR || '';
6072

6173
export const escapeRegExp = (text: string): string => text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');

yarn.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
"@octokit/rest" "^16.15.0"
1818

1919
"@actions/http-client@^1.0.3":
20-
version "1.0.5"
21-
resolved "https://registry.yarnpkg.com/@actions/http-client/-/http-client-1.0.5.tgz#7df8013257cb50bdbe93199b765f0db67e46bbac"
22-
integrity sha512-kX9T1EwfohZU/iTHei0nQlykxdTV9xvKMeHYTtYkfkgBKoe2Z0z0IP3ANVYTsFAlycMwLheBhVEBTm2XvGhR1Q==
20+
version "1.0.6"
21+
resolved "https://registry.yarnpkg.com/@actions/http-client/-/http-client-1.0.6.tgz#6f9267ca50e1d74d8581f4a894a943cd4c97b49a"
22+
integrity sha512-LGmio4w98UyGX33b/W6V6Nx/sQHRXZ859YlMkn36wPsXPB82u8xTVlA/Dq2DXrm6lEq9RVmisRJa1c+HETAIJA==
2323
dependencies:
2424
tunnel "0.0.6"
2525

0 commit comments

Comments
 (0)