Restore the branch-suffix input

This commit is contained in:
Peter Evans 2020-07-20 19:14:42 +09:00
parent 3c6aade49b
commit 8c01dce3ac
6 changed files with 65 additions and 17 deletions

View file

@ -12,6 +12,7 @@ export interface Inputs {
committer: string
author: string
branch: string
branchSuffix: string
base: string
pushToFork: string
title: string
@ -107,6 +108,30 @@ export async function createPullRequest(inputs: Inputs): Promise<void> {
}
core.endGroup()
// Apply the branch suffix if set
if (inputs.branchSuffix) {
switch (inputs.branchSuffix) {
case 'short-commit-hash':
// Suffix with the short SHA1 hash
inputs.branch = `${inputs.branch}-${await git.revParse('HEAD', [
'--short'
])}`
break
case 'timestamp':
// Suffix with the current timestamp
inputs.branch = `${inputs.branch}-${utils.secondsSinceEpoch()}`
break
case 'random':
// Suffix with a 7 character random string
inputs.branch = `${inputs.branch}-${utils.randomString()}`
break
default:
throw new Error(
`Branch suffix '${inputs.branchSuffix}' is not a valid value. Unable to continue.`
)
}
}
// Output head branch
core.info(
`Pull request branch to create or update set to '${inputs.branch}'`

View file

@ -12,6 +12,7 @@ async function run(): Promise<void> {
committer: core.getInput('committer'),
author: core.getInput('author'),
branch: core.getInput('branch'),
branchSuffix: core.getInput('branch-suffix'),
base: core.getInput('base'),
pushToFork: core.getInput('push-to-fork'),
title: core.getInput('title'),