From 9758f4618ee12f091a37bcd0b98ebfef388dd02c Mon Sep 17 00:00:00 2001 From: Sibiraj Date: Sun, 27 Feb 2022 08:25:13 +0530 Subject: [PATCH 1/6] fix: prefer getMultilineInput and getBooleanInput from actions/core --- __test__/utils.unit.test.ts | 8 -------- src/main.ts | 17 ++++++++--------- src/utils.ts | 14 -------------- 3 files changed, 8 insertions(+), 31 deletions(-) diff --git a/__test__/utils.unit.test.ts b/__test__/utils.unit.test.ts index 3da2439ad..6a68eb86c 100644 --- a/__test__/utils.unit.test.ts +++ b/__test__/utils.unit.test.ts @@ -17,14 +17,6 @@ describe('utils tests', () => { } }) - test('getStringAsArray splits string input by newlines and commas', async () => { - const array = utils.getStringAsArray('1, 2, 3\n4, 5, 6') - expect(array.length).toEqual(6) - - const array2 = utils.getStringAsArray('') - expect(array2.length).toEqual(0) - }) - test('getRepoPath successfully returns the path to the repository', async () => { expect(utils.getRepoPath()).toEqual(process.env['GITHUB_WORKSPACE']) expect(utils.getRepoPath('foo')).toEqual( diff --git a/src/main.ts b/src/main.ts index 45a1ae85e..ce69b4e37 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,31 +1,30 @@ import * as core from '@actions/core' import {Inputs, createPullRequest} from './create-pull-request' import {inspect} from 'util' -import * as utils from './utils' async function run(): Promise { try { const inputs: Inputs = { token: core.getInput('token'), path: core.getInput('path'), - addPaths: utils.getInputAsArray('add-paths'), + addPaths: core.getMultilineInput('add-paths'), commitMessage: core.getInput('commit-message'), committer: core.getInput('committer'), author: core.getInput('author'), - signoff: core.getInput('signoff') === 'true', + signoff: core.getBooleanInput('signoff'), branch: core.getInput('branch'), - deleteBranch: core.getInput('delete-branch') === 'true', + deleteBranch: core.getBooleanInput('delete-branch'), branchSuffix: core.getInput('branch-suffix'), base: core.getInput('base'), pushToFork: core.getInput('push-to-fork'), title: core.getInput('title'), body: core.getInput('body'), - labels: utils.getInputAsArray('labels'), - assignees: utils.getInputAsArray('assignees'), - reviewers: utils.getInputAsArray('reviewers'), - teamReviewers: utils.getInputAsArray('team-reviewers'), + labels: core.getMultilineInput('labels'), + assignees: core.getMultilineInput('assignees'), + reviewers: core.getMultilineInput('reviewers'), + teamReviewers: core.getMultilineInput('team-reviewers'), milestone: Number(core.getInput('milestone')), - draft: core.getInput('draft') === 'true' + draft: core.getBooleanInput('draft') } core.debug(`Inputs: ${inspect(inputs)}`) diff --git a/src/utils.ts b/src/utils.ts index a491d9155..6202cbe69 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -2,20 +2,6 @@ import * as core from '@actions/core' import * as fs from 'fs' import * as path from 'path' -export function getInputAsArray( - name: string, - options?: core.InputOptions -): string[] { - return getStringAsArray(core.getInput(name, options)) -} - -export function getStringAsArray(str: string): string[] { - return str - .split(/[\n,]+/) - .map(s => s.trim()) - .filter(x => x !== '') -} - export function getRepoPath(relativePath?: string): string { let githubWorkspacePath = process.env['GITHUB_WORKSPACE'] if (!githubWorkspacePath) { From e5b1abe130e3fd90cded5b4bc974c5f5a8696b8d Mon Sep 17 00:00:00 2001 From: Sibiraj Date: Sun, 27 Feb 2022 08:25:44 +0530 Subject: [PATCH 2/6] build: update distribution --- dist/index.js | 30 +++++++++--------------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/dist/index.js b/dist/index.js index f4a2a3839..d75536f2d 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1074,31 +1074,30 @@ Object.defineProperty(exports, "__esModule", ({ value: true })); const core = __importStar(__nccwpck_require__(2186)); const create_pull_request_1 = __nccwpck_require__(3780); const util_1 = __nccwpck_require__(3837); -const utils = __importStar(__nccwpck_require__(918)); function run() { return __awaiter(this, void 0, void 0, function* () { try { const inputs = { token: core.getInput('token'), path: core.getInput('path'), - addPaths: utils.getInputAsArray('add-paths'), + addPaths: core.getMultilineInput('add-paths'), commitMessage: core.getInput('commit-message'), committer: core.getInput('committer'), author: core.getInput('author'), - signoff: core.getInput('signoff') === 'true', + signoff: core.getBooleanInput('signoff'), branch: core.getInput('branch'), - deleteBranch: core.getInput('delete-branch') === 'true', + deleteBranch: core.getBooleanInput('delete-branch'), branchSuffix: core.getInput('branch-suffix'), base: core.getInput('base'), pushToFork: core.getInput('push-to-fork'), title: core.getInput('title'), body: core.getInput('body'), - labels: utils.getInputAsArray('labels'), - assignees: utils.getInputAsArray('assignees'), - reviewers: utils.getInputAsArray('reviewers'), - teamReviewers: utils.getInputAsArray('team-reviewers'), + labels: core.getMultilineInput('labels'), + assignees: core.getMultilineInput('assignees'), + reviewers: core.getMultilineInput('reviewers'), + teamReviewers: core.getMultilineInput('team-reviewers'), milestone: Number(core.getInput('milestone')), - draft: core.getInput('draft') === 'true' + draft: core.getBooleanInput('draft') }; core.debug(`Inputs: ${(0, util_1.inspect)(inputs)}`); yield (0, create_pull_request_1.createPullRequest)(inputs); @@ -1164,21 +1163,10 @@ var __importStar = (this && this.__importStar) || function (mod) { return result; }; Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.fileExistsSync = exports.parseDisplayNameEmail = exports.randomString = exports.secondsSinceEpoch = exports.getRemoteUrl = exports.getRemoteDetail = exports.getRepoPath = exports.getStringAsArray = exports.getInputAsArray = void 0; +exports.fileExistsSync = exports.parseDisplayNameEmail = exports.randomString = exports.secondsSinceEpoch = exports.getRemoteUrl = exports.getRemoteDetail = exports.getRepoPath = void 0; const core = __importStar(__nccwpck_require__(2186)); const fs = __importStar(__nccwpck_require__(7147)); const path = __importStar(__nccwpck_require__(1017)); -function getInputAsArray(name, options) { - return getStringAsArray(core.getInput(name, options)); -} -exports.getInputAsArray = getInputAsArray; -function getStringAsArray(str) { - return str - .split(/[\n,]+/) - .map(s => s.trim()) - .filter(x => x !== ''); -} -exports.getStringAsArray = getStringAsArray; function getRepoPath(relativePath) { let githubWorkspacePath = process.env['GITHUB_WORKSPACE']; if (!githubWorkspacePath) { From 86a3a4b8e292099efff08abda85d1b352edd40dd Mon Sep 17 00:00:00 2001 From: Sibiraj Date: Sun, 27 Feb 2022 08:29:24 +0530 Subject: [PATCH 3/6] feat: update action runtime to node 16 --- .github/workflows/ci.yml | 2 +- action.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7bb4b151e..6e0a55690 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,7 +17,7 @@ jobs: - uses: actions/checkout@v2 - uses: actions/setup-node@v1 with: - node-version: 12.x + node-version: 16.x - uses: actions/setup-python@v2 with: python-version: '3.x' diff --git a/action.yml b/action.yml index 60e3adeb7..09290a810 100644 --- a/action.yml +++ b/action.yml @@ -81,7 +81,7 @@ outputs: pull-request-head-sha: description: 'The commit SHA of the pull request branch.' runs: - using: 'node12' + using: 'node16' main: 'dist/index.js' branding: icon: 'git-pull-request' From ab22478357c4797ecbefe21f2224d35003f57442 Mon Sep 17 00:00:00 2001 From: Sibiraj Date: Sun, 27 Feb 2022 08:30:03 +0530 Subject: [PATCH 4/6] ci: update setup-node and cache npm dependencies --- .github/workflows/ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6e0a55690..d59cfd46f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,9 +15,10 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - uses: actions/setup-node@v1 + - uses: actions/setup-node@v2 with: node-version: 16.x + cache: npm - uses: actions/setup-python@v2 with: python-version: '3.x' From 998527a6820303c955edc59e075f7144b9705e48 Mon Sep 17 00:00:00 2001 From: Sibiraj Date: Mon, 28 Feb 2022 08:48:04 +0530 Subject: [PATCH 5/6] revert: getMultilineInput to getInputAsArray --- __test__/utils.unit.test.ts | 8 ++++++++ src/main.ts | 11 ++++++----- src/utils.ts | 14 ++++++++++++++ 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/__test__/utils.unit.test.ts b/__test__/utils.unit.test.ts index 6a68eb86c..3da2439ad 100644 --- a/__test__/utils.unit.test.ts +++ b/__test__/utils.unit.test.ts @@ -17,6 +17,14 @@ describe('utils tests', () => { } }) + test('getStringAsArray splits string input by newlines and commas', async () => { + const array = utils.getStringAsArray('1, 2, 3\n4, 5, 6') + expect(array.length).toEqual(6) + + const array2 = utils.getStringAsArray('') + expect(array2.length).toEqual(0) + }) + test('getRepoPath successfully returns the path to the repository', async () => { expect(utils.getRepoPath()).toEqual(process.env['GITHUB_WORKSPACE']) expect(utils.getRepoPath('foo')).toEqual( diff --git a/src/main.ts b/src/main.ts index ce69b4e37..f3d9171cb 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,13 +1,14 @@ import * as core from '@actions/core' import {Inputs, createPullRequest} from './create-pull-request' import {inspect} from 'util' +import * as utils from './utils' async function run(): Promise { try { const inputs: Inputs = { token: core.getInput('token'), path: core.getInput('path'), - addPaths: core.getMultilineInput('add-paths'), + addPaths: utils.getInputAsArray('add-paths'), commitMessage: core.getInput('commit-message'), committer: core.getInput('committer'), author: core.getInput('author'), @@ -19,10 +20,10 @@ async function run(): Promise { pushToFork: core.getInput('push-to-fork'), title: core.getInput('title'), body: core.getInput('body'), - labels: core.getMultilineInput('labels'), - assignees: core.getMultilineInput('assignees'), - reviewers: core.getMultilineInput('reviewers'), - teamReviewers: core.getMultilineInput('team-reviewers'), + labels: utils.getInputAsArray('labels'), + assignees: utils.getInputAsArray('assignees'), + reviewers: utils.getInputAsArray('reviewers'), + teamReviewers: utils.getInputAsArray('team-reviewers'), milestone: Number(core.getInput('milestone')), draft: core.getBooleanInput('draft') } diff --git a/src/utils.ts b/src/utils.ts index 6202cbe69..a491d9155 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -2,6 +2,20 @@ import * as core from '@actions/core' import * as fs from 'fs' import * as path from 'path' +export function getInputAsArray( + name: string, + options?: core.InputOptions +): string[] { + return getStringAsArray(core.getInput(name, options)) +} + +export function getStringAsArray(str: string): string[] { + return str + .split(/[\n,]+/) + .map(s => s.trim()) + .filter(x => x !== '') +} + export function getRepoPath(relativePath?: string): string { let githubWorkspacePath = process.env['GITHUB_WORKSPACE'] if (!githubWorkspacePath) { From 7e61e556a181355409e127101f1b4c10dc9c53ff Mon Sep 17 00:00:00 2001 From: Sibiraj Date: Mon, 28 Feb 2022 08:51:31 +0530 Subject: [PATCH 6/6] build: update distribution --- dist/index.js | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/dist/index.js b/dist/index.js index d75536f2d..6144a21d4 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1074,13 +1074,14 @@ Object.defineProperty(exports, "__esModule", ({ value: true })); const core = __importStar(__nccwpck_require__(2186)); const create_pull_request_1 = __nccwpck_require__(3780); const util_1 = __nccwpck_require__(3837); +const utils = __importStar(__nccwpck_require__(918)); function run() { return __awaiter(this, void 0, void 0, function* () { try { const inputs = { token: core.getInput('token'), path: core.getInput('path'), - addPaths: core.getMultilineInput('add-paths'), + addPaths: utils.getInputAsArray('add-paths'), commitMessage: core.getInput('commit-message'), committer: core.getInput('committer'), author: core.getInput('author'), @@ -1092,10 +1093,10 @@ function run() { pushToFork: core.getInput('push-to-fork'), title: core.getInput('title'), body: core.getInput('body'), - labels: core.getMultilineInput('labels'), - assignees: core.getMultilineInput('assignees'), - reviewers: core.getMultilineInput('reviewers'), - teamReviewers: core.getMultilineInput('team-reviewers'), + labels: utils.getInputAsArray('labels'), + assignees: utils.getInputAsArray('assignees'), + reviewers: utils.getInputAsArray('reviewers'), + teamReviewers: utils.getInputAsArray('team-reviewers'), milestone: Number(core.getInput('milestone')), draft: core.getBooleanInput('draft') }; @@ -1163,10 +1164,21 @@ var __importStar = (this && this.__importStar) || function (mod) { return result; }; Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.fileExistsSync = exports.parseDisplayNameEmail = exports.randomString = exports.secondsSinceEpoch = exports.getRemoteUrl = exports.getRemoteDetail = exports.getRepoPath = void 0; +exports.fileExistsSync = exports.parseDisplayNameEmail = exports.randomString = exports.secondsSinceEpoch = exports.getRemoteUrl = exports.getRemoteDetail = exports.getRepoPath = exports.getStringAsArray = exports.getInputAsArray = void 0; const core = __importStar(__nccwpck_require__(2186)); const fs = __importStar(__nccwpck_require__(7147)); const path = __importStar(__nccwpck_require__(1017)); +function getInputAsArray(name, options) { + return getStringAsArray(core.getInput(name, options)); +} +exports.getInputAsArray = getInputAsArray; +function getStringAsArray(str) { + return str + .split(/[\n,]+/) + .map(s => s.trim()) + .filter(x => x !== ''); +} +exports.getStringAsArray = getStringAsArray; function getRepoPath(relativePath) { let githubWorkspacePath = process.env['GITHUB_WORKSPACE']; if (!githubWorkspacePath) {