fix: merge existing inputs into new new_branch input

This commit is contained in:
Federico Grandi
2022-01-19 21:41:48 +01:00
parent d4d39927bf
commit a790c74dfe
4 changed files with 18 additions and 37 deletions

View File

@@ -12,13 +12,6 @@ inputs:
author_email:
description: The email of the user that will be displayed as the author of the commit
required: false
branch:
description: Name of the branch to switch to.
required: false
branch_mode:
description: How the action should behave when the targeted branch is missing ("throw" or "create")
required: false
default: create
commit:
description: Additional arguments for the git commit command
required: false
@@ -39,6 +32,9 @@ inputs:
message:
description: The message for the commit
required: false
new_branch:
description: The name of the branch to create.
required: false
pathspec_error_handling:
description: The way the action should handle pathspec errors from the add and remove commands.
required: false

2
lib/index.js generated

File diff suppressed because one or more lines are too long

View File

@@ -5,14 +5,13 @@ interface InputTypes {
add: string
author_name: string
author_email: string
branch: string | undefined
branch_mode: 'throw' | 'create'
commit: string | undefined
committer_name: string
committer_email: string
cwd: string
default_author: 'github_actor' | 'user_info' | 'github_actions'
message: string
new_branch: string | undefined
pathspec_error_handling: 'ignore' | 'exitImmediately' | 'exitAtEnd'
pull: string | undefined
push: string
@@ -197,18 +196,6 @@ export async function checkInputs() {
core.info(`> Using "${getInput('message')}" as commit message.`)
// #endregion
// #region branch_mode
const branch_mode_valid = ['throw', 'create']
if (!branch_mode_valid.includes(getInput('branch_mode')))
throw new Error(
`"${getInput(
'branch_mode'
)}" is not a valid value for the 'branch_mode' input. Valid values are: ${branch_mode_valid.join(
', '
)}`
)
// #endregion
// #region pathspec_error_handling
const peh_valid = ['ignore', 'exitImmediately', 'exitAtEnd']
if (!peh_valid.includes(getInput('pathspec_error_handling')))

View File

@@ -47,23 +47,19 @@ core.info(`Running in ${baseDir}`)
await git.fetch(['--tags', '--force'], log)
const targetBranch = getInput('branch')
const targetBranch = getInput('new_branch')
if (targetBranch) {
await git.checkout(targetBranch).catch(() => {
if (getInput('branch_mode') == 'create') {
log(
undefined,
`'${targetBranch}' branch not found, trying to create one.`
)
await git
.checkout(targetBranch)
.then(() => {
log(undefined, `'${targetBranch}' branch already existed.`)
})
.catch(() => {
log(undefined, `Creating '${targetBranch}' branch.`)
return git.checkoutLocalBranch(targetBranch, log)
} else throw `'${targetBranch}' branch not found.`
})
})
}
/*
The current default value is set here: it will not pull when it has
created a new branch, it will use --rebase when the branch already existed
*/
const pullOption = getInput('pull')
if (pullOption) {
core.info('> Pulling from remote...')
@@ -112,11 +108,13 @@ core.info(`Running in ${baseDir}`)
if (pushOption === true) {
core.debug(
`Running: git push origin ${getInput('branch')} --set-upstream`
`Running: git push origin ${
getInput('new_branch') || ''
} --set-upstream`
)
await git.push(
'origin',
getInput('branch'),
getInput('new_branch'),
{ '--set-upstream': null },
(err, data?) => {
if (data) setOutput('pushed', 'true')