fix: merge existing inputs into new new_branch input
This commit is contained in:
10
action.yml
10
action.yml
@@ -12,13 +12,6 @@ inputs:
|
|||||||
author_email:
|
author_email:
|
||||||
description: The email of the user that will be displayed as the author of the commit
|
description: The email of the user that will be displayed as the author of the commit
|
||||||
required: false
|
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:
|
commit:
|
||||||
description: Additional arguments for the git commit command
|
description: Additional arguments for the git commit command
|
||||||
required: false
|
required: false
|
||||||
@@ -39,6 +32,9 @@ inputs:
|
|||||||
message:
|
message:
|
||||||
description: The message for the commit
|
description: The message for the commit
|
||||||
required: false
|
required: false
|
||||||
|
new_branch:
|
||||||
|
description: The name of the branch to create.
|
||||||
|
required: false
|
||||||
pathspec_error_handling:
|
pathspec_error_handling:
|
||||||
description: The way the action should handle pathspec errors from the add and remove commands.
|
description: The way the action should handle pathspec errors from the add and remove commands.
|
||||||
required: false
|
required: false
|
||||||
|
|||||||
2
lib/index.js
generated
2
lib/index.js
generated
File diff suppressed because one or more lines are too long
15
src/io.ts
15
src/io.ts
@@ -5,14 +5,13 @@ interface InputTypes {
|
|||||||
add: string
|
add: string
|
||||||
author_name: string
|
author_name: string
|
||||||
author_email: string
|
author_email: string
|
||||||
branch: string | undefined
|
|
||||||
branch_mode: 'throw' | 'create'
|
|
||||||
commit: string | undefined
|
commit: string | undefined
|
||||||
committer_name: string
|
committer_name: string
|
||||||
committer_email: string
|
committer_email: string
|
||||||
cwd: string
|
cwd: string
|
||||||
default_author: 'github_actor' | 'user_info' | 'github_actions'
|
default_author: 'github_actor' | 'user_info' | 'github_actions'
|
||||||
message: string
|
message: string
|
||||||
|
new_branch: string | undefined
|
||||||
pathspec_error_handling: 'ignore' | 'exitImmediately' | 'exitAtEnd'
|
pathspec_error_handling: 'ignore' | 'exitImmediately' | 'exitAtEnd'
|
||||||
pull: string | undefined
|
pull: string | undefined
|
||||||
push: string
|
push: string
|
||||||
@@ -197,18 +196,6 @@ export async function checkInputs() {
|
|||||||
core.info(`> Using "${getInput('message')}" as commit message.`)
|
core.info(`> Using "${getInput('message')}" as commit message.`)
|
||||||
// #endregion
|
// #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
|
// #region pathspec_error_handling
|
||||||
const peh_valid = ['ignore', 'exitImmediately', 'exitAtEnd']
|
const peh_valid = ['ignore', 'exitImmediately', 'exitAtEnd']
|
||||||
if (!peh_valid.includes(getInput('pathspec_error_handling')))
|
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)
|
await git.fetch(['--tags', '--force'], log)
|
||||||
|
|
||||||
const targetBranch = getInput('branch')
|
const targetBranch = getInput('new_branch')
|
||||||
if (targetBranch) {
|
if (targetBranch) {
|
||||||
await git.checkout(targetBranch).catch(() => {
|
await git
|
||||||
if (getInput('branch_mode') == 'create') {
|
.checkout(targetBranch)
|
||||||
log(
|
.then(() => {
|
||||||
undefined,
|
log(undefined, `'${targetBranch}' branch already existed.`)
|
||||||
`'${targetBranch}' branch not found, trying to create one.`
|
})
|
||||||
)
|
.catch(() => {
|
||||||
|
log(undefined, `Creating '${targetBranch}' branch.`)
|
||||||
return git.checkoutLocalBranch(targetBranch, log)
|
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')
|
const pullOption = getInput('pull')
|
||||||
if (pullOption) {
|
if (pullOption) {
|
||||||
core.info('> Pulling from remote...')
|
core.info('> Pulling from remote...')
|
||||||
@@ -112,11 +108,13 @@ core.info(`Running in ${baseDir}`)
|
|||||||
|
|
||||||
if (pushOption === true) {
|
if (pushOption === true) {
|
||||||
core.debug(
|
core.debug(
|
||||||
`Running: git push origin ${getInput('branch')} --set-upstream`
|
`Running: git push origin ${
|
||||||
|
getInput('new_branch') || ''
|
||||||
|
} --set-upstream`
|
||||||
)
|
)
|
||||||
await git.push(
|
await git.push(
|
||||||
'origin',
|
'origin',
|
||||||
getInput('branch'),
|
getInput('new_branch'),
|
||||||
{ '--set-upstream': null },
|
{ '--set-upstream': null },
|
||||||
(err, data?) => {
|
(err, data?) => {
|
||||||
if (data) setOutput('pushed', 'true')
|
if (data) setOutput('pushed', 'true')
|
||||||
|
|||||||
Reference in New Issue
Block a user