feat: add input for branch delete

This commit is contained in:
Peter Evans 2020-09-06 10:21:35 +09:00
parent 5ea31358e9
commit a49ee3308e
6 changed files with 34 additions and 17 deletions

View file

@ -17,6 +17,7 @@ export interface Inputs {
author: string
signoff: boolean
branch: string
deleteBranch: boolean
branchSuffix: string
base: string
pushToFork: string
@ -194,18 +195,21 @@ export async function createPullRequest(inputs: Inputs): Promise<void> {
branchRepository
)
} else {
// If there is no longer a diff with the base delete the branch
// There is no longer a diff with the base
// Check we are in a state where a branch exists
if (['updated', 'not-updated'].includes(result.action)) {
core.info(
`Branch '${inputs.branch}' no longer differs from base branch '${inputs.base}'`
)
core.info(`Closing pull request and deleting branch '${inputs.branch}'`)
await git.push([
'--delete',
'--force',
branchRemoteName,
`refs/heads/${inputs.branch}`
])
if (inputs.deleteBranch) {
core.info(`Deleting branch '${inputs.branch}'`)
await git.push([
'--delete',
'--force',
branchRemoteName,
`refs/heads/${inputs.branch}`
])
}
}
}
} catch (error) {

View file

@ -13,6 +13,7 @@ async function run(): Promise<void> {
author: core.getInput('author'),
signoff: core.getInput('signoff') === 'true',
branch: core.getInput('branch'),
deleteBranch: core.getInput('delete-branch') === 'true',
branchSuffix: core.getInput('branch-suffix'),
base: core.getInput('base'),
pushToFork: core.getInput('push-to-fork'),