From 9758f4618ee12f091a37bcd0b98ebfef388dd02c Mon Sep 17 00:00:00 2001 From: Sibiraj Date: Sun, 27 Feb 2022 08:25:13 +0530 Subject: [PATCH] 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 3da2439..6a68eb8 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 45a1ae8..ce69b4e 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 a491d91..6202cbe 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) {