Skip to content

Commit a790c74

Browse files
committed
fix: merge existing inputs into new new_branch input
1 parent d4d3992 commit a790c74

File tree

4 files changed

+18
-37
lines changed

4 files changed

+18
-37
lines changed

action.yml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,6 @@ inputs:
1212
author_email:
1313
description: The email of the user that will be displayed as the author of the commit
1414
required: false
15-
branch:
16-
description: Name of the branch to switch to.
17-
required: false
18-
branch_mode:
19-
description: How the action should behave when the targeted branch is missing ("throw" or "create")
20-
required: false
21-
default: create
2215
commit:
2316
description: Additional arguments for the git commit command
2417
required: false
@@ -39,6 +32,9 @@ inputs:
3932
message:
4033
description: The message for the commit
4134
required: false
35+
new_branch:
36+
description: The name of the branch to create.
37+
required: false
4238
pathspec_error_handling:
4339
description: The way the action should handle pathspec errors from the add and remove commands.
4440
required: false

lib/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/io.ts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@ interface InputTypes {
55
add: string
66
author_name: string
77
author_email: string
8-
branch: string | undefined
9-
branch_mode: 'throw' | 'create'
108
commit: string | undefined
119
committer_name: string
1210
committer_email: string
1311
cwd: string
1412
default_author: 'github_actor' | 'user_info' | 'github_actions'
1513
message: string
14+
new_branch: string | undefined
1615
pathspec_error_handling: 'ignore' | 'exitImmediately' | 'exitAtEnd'
1716
pull: string | undefined
1817
push: string
@@ -197,18 +196,6 @@ export async function checkInputs() {
197196
core.info(`> Using "${getInput('message')}" as commit message.`)
198197
// #endregion
199198

200-
// #region branch_mode
201-
const branch_mode_valid = ['throw', 'create']
202-
if (!branch_mode_valid.includes(getInput('branch_mode')))
203-
throw new Error(
204-
`"${getInput(
205-
'branch_mode'
206-
)}" is not a valid value for the 'branch_mode' input. Valid values are: ${branch_mode_valid.join(
207-
', '
208-
)}`
209-
)
210-
// #endregion
211-
212199
// #region pathspec_error_handling
213200
const peh_valid = ['ignore', 'exitImmediately', 'exitAtEnd']
214201
if (!peh_valid.includes(getInput('pathspec_error_handling')))

src/main.ts

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,23 +47,19 @@ core.info(`Running in ${baseDir}`)
4747

4848
await git.fetch(['--tags', '--force'], log)
4949

50-
const targetBranch = getInput('branch')
50+
const targetBranch = getInput('new_branch')
5151
if (targetBranch) {
52-
await git.checkout(targetBranch).catch(() => {
53-
if (getInput('branch_mode') == 'create') {
54-
log(
55-
undefined,
56-
`'${targetBranch}' branch not found, trying to create one.`
57-
)
52+
await git
53+
.checkout(targetBranch)
54+
.then(() => {
55+
log(undefined, `'${targetBranch}' branch already existed.`)
56+
})
57+
.catch(() => {
58+
log(undefined, `Creating '${targetBranch}' branch.`)
5859
return git.checkoutLocalBranch(targetBranch, log)
59-
} else throw `'${targetBranch}' branch not found.`
60-
})
60+
})
6161
}
6262

63-
/*
64-
The current default value is set here: it will not pull when it has
65-
created a new branch, it will use --rebase when the branch already existed
66-
*/
6763
const pullOption = getInput('pull')
6864
if (pullOption) {
6965
core.info('> Pulling from remote...')
@@ -112,11 +108,13 @@ core.info(`Running in ${baseDir}`)
112108

113109
if (pushOption === true) {
114110
core.debug(
115-
`Running: git push origin ${getInput('branch')} --set-upstream`
111+
`Running: git push origin ${
112+
getInput('new_branch') || ''
113+
} --set-upstream`
116114
)
117115
await git.push(
118116
'origin',
119-
getInput('branch'),
117+
getInput('new_branch'),
120118
{ '--set-upstream': null },
121119
(err, data?) => {
122120
if (data) setOutput('pushed', 'true')

0 commit comments

Comments
 (0)