fix: merge existing inputs into new new_branch input
This commit is contained in:
15
src/io.ts
15
src/io.ts
@@ -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')))
|
||||
|
||||
28
src/main.ts
28
src/main.ts
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user