Merge pull request #547 from peter-evans/delete-branch

feat: add input for branch delete
This commit is contained in:
Peter Evans 2020-09-07 09:14:08 +09:00 committed by GitHub
commit e17bb55cb7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 34 additions and 17 deletions

20
dist/index.js vendored
View file

@ -1405,6 +1405,7 @@ function run() {
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'),
@ -7042,16 +7043,19 @@ function createPullRequest(inputs) {
yield githubHelper.createOrUpdatePullRequest(inputs, baseRemote.repository, 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}'`);
yield git.push([
'--delete',
'--force',
branchRemoteName,
`refs/heads/${inputs.branch}`
]);
if (inputs.deleteBranch) {
core.info(`Deleting branch '${inputs.branch}'`);
yield git.push([
'--delete',
'--force',
branchRemoteName,
`refs/heads/${inputs.branch}`
]);
}
}
}
}