revert: getMultilineInput to getInputAsArray

This commit is contained in:
Sibiraj 2022-02-28 08:48:04 +05:30
parent ab22478357
commit 998527a682
3 changed files with 28 additions and 5 deletions

View file

@ -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 () => { test('getRepoPath successfully returns the path to the repository', async () => {
expect(utils.getRepoPath()).toEqual(process.env['GITHUB_WORKSPACE']) expect(utils.getRepoPath()).toEqual(process.env['GITHUB_WORKSPACE'])
expect(utils.getRepoPath('foo')).toEqual( expect(utils.getRepoPath('foo')).toEqual(

View file

@ -1,13 +1,14 @@
import * as core from '@actions/core' import * as core from '@actions/core'
import {Inputs, createPullRequest} from './create-pull-request' import {Inputs, createPullRequest} from './create-pull-request'
import {inspect} from 'util' import {inspect} from 'util'
import * as utils from './utils'
async function run(): Promise<void> { async function run(): Promise<void> {
try { try {
const inputs: Inputs = { const inputs: Inputs = {
token: core.getInput('token'), token: core.getInput('token'),
path: core.getInput('path'), path: core.getInput('path'),
addPaths: core.getMultilineInput('add-paths'), addPaths: utils.getInputAsArray('add-paths'),
commitMessage: core.getInput('commit-message'), commitMessage: core.getInput('commit-message'),
committer: core.getInput('committer'), committer: core.getInput('committer'),
author: core.getInput('author'), author: core.getInput('author'),
@ -19,10 +20,10 @@ async function run(): Promise<void> {
pushToFork: core.getInput('push-to-fork'), pushToFork: core.getInput('push-to-fork'),
title: core.getInput('title'), title: core.getInput('title'),
body: core.getInput('body'), body: core.getInput('body'),
labels: core.getMultilineInput('labels'), labels: utils.getInputAsArray('labels'),
assignees: core.getMultilineInput('assignees'), assignees: utils.getInputAsArray('assignees'),
reviewers: core.getMultilineInput('reviewers'), reviewers: utils.getInputAsArray('reviewers'),
teamReviewers: core.getMultilineInput('team-reviewers'), teamReviewers: utils.getInputAsArray('team-reviewers'),
milestone: Number(core.getInput('milestone')), milestone: Number(core.getInput('milestone')),
draft: core.getBooleanInput('draft') draft: core.getBooleanInput('draft')
} }

View file

@ -2,6 +2,20 @@ import * as core from '@actions/core'
import * as fs from 'fs' import * as fs from 'fs'
import * as path from 'path' 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 { export function getRepoPath(relativePath?: string): string {
let githubWorkspacePath = process.env['GITHUB_WORKSPACE'] let githubWorkspacePath = process.env['GITHUB_WORKSPACE']
if (!githubWorkspacePath) { if (!githubWorkspacePath) {