mirror of
https://forgejo.stefka.eu/jiriks74/create-pull-request.git
synced 2025-01-18 16:01:06 +01:00
fix: prefer getMultilineInput and getBooleanInput from actions/core
This commit is contained in:
parent
a7bb76508d
commit
9758f4618e
3 changed files with 8 additions and 31 deletions
|
@ -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 () => {
|
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(
|
||||||
|
|
17
src/main.ts
17
src/main.ts
|
@ -1,31 +1,30 @@
|
||||||
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: utils.getInputAsArray('add-paths'),
|
addPaths: core.getMultilineInput('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'),
|
||||||
signoff: core.getInput('signoff') === 'true',
|
signoff: core.getBooleanInput('signoff'),
|
||||||
branch: core.getInput('branch'),
|
branch: core.getInput('branch'),
|
||||||
deleteBranch: core.getInput('delete-branch') === 'true',
|
deleteBranch: core.getBooleanInput('delete-branch'),
|
||||||
branchSuffix: core.getInput('branch-suffix'),
|
branchSuffix: core.getInput('branch-suffix'),
|
||||||
base: core.getInput('base'),
|
base: core.getInput('base'),
|
||||||
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: utils.getInputAsArray('labels'),
|
labels: core.getMultilineInput('labels'),
|
||||||
assignees: utils.getInputAsArray('assignees'),
|
assignees: core.getMultilineInput('assignees'),
|
||||||
reviewers: utils.getInputAsArray('reviewers'),
|
reviewers: core.getMultilineInput('reviewers'),
|
||||||
teamReviewers: utils.getInputAsArray('team-reviewers'),
|
teamReviewers: core.getMultilineInput('team-reviewers'),
|
||||||
milestone: Number(core.getInput('milestone')),
|
milestone: Number(core.getInput('milestone')),
|
||||||
draft: core.getInput('draft') === 'true'
|
draft: core.getBooleanInput('draft')
|
||||||
}
|
}
|
||||||
core.debug(`Inputs: ${inspect(inputs)}`)
|
core.debug(`Inputs: ${inspect(inputs)}`)
|
||||||
|
|
||||||
|
|
14
src/utils.ts
14
src/utils.ts
|
@ -2,20 +2,6 @@ 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) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue