Merge pull request #547 from peter-evans/delete-branch
feat: add input for branch delete
This commit is contained in:
commit
e17bb55cb7
6 changed files with 34 additions and 17 deletions
1
.github/workflows/cpr-example-command.yml
vendored
1
.github/workflows/cpr-example-command.yml
vendored
|
@ -34,6 +34,7 @@ jobs:
|
||||||
milestone: 1
|
milestone: 1
|
||||||
draft: false
|
draft: false
|
||||||
branch: example-patches
|
branch: example-patches
|
||||||
|
delete-branch: true
|
||||||
|
|
||||||
- name: Check output
|
- name: Check output
|
||||||
run: |
|
run: |
|
||||||
|
|
|
@ -51,6 +51,7 @@ All inputs are **optional**. If not set, sensible defaults will be used.
|
||||||
| `author` | The author name and email address in the format `Display Name <email@address.com>`. Defaults to the user who triggered the workflow run. | `${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>` |
|
| `author` | The author name and email address in the format `Display Name <email@address.com>`. Defaults to the user who triggered the workflow run. | `${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>` |
|
||||||
| `signoff` | Add [`Signed-off-by`](https://git-scm.com/docs/git-commit#Documentation/git-commit.txt---signoff) line by the committer at the end of the commit log message. | `false` |
|
| `signoff` | Add [`Signed-off-by`](https://git-scm.com/docs/git-commit#Documentation/git-commit.txt---signoff) line by the committer at the end of the commit log message. | `false` |
|
||||||
| `branch` | The pull request branch name. | `create-pull-request/patch` |
|
| `branch` | The pull request branch name. | `create-pull-request/patch` |
|
||||||
|
| `delete-branch` | Delete the `branch` when closing pull requests, and when undeleted after merging. Recommend `true`. | `false` |
|
||||||
| `branch-suffix` | The branch suffix type when using the alternative branching strategy. Valid values are `random`, `timestamp` and `short-commit-hash`. See [Alternative strategy](#alternative-strategy---always-create-a-new-pull-request-branch) for details. | |
|
| `branch-suffix` | The branch suffix type when using the alternative branching strategy. Valid values are `random`, `timestamp` and `short-commit-hash`. See [Alternative strategy](#alternative-strategy---always-create-a-new-pull-request-branch) for details. | |
|
||||||
| `base` | Sets the pull request base branch. | Defaults to the branch checked out in the workflow. |
|
| `base` | Sets the pull request base branch. | Defaults to the branch checked out in the workflow. |
|
||||||
| `push-to-fork` | A fork of the checked-out parent repository to which the pull request branch will be pushed. e.g. `owner/repo-fork`. The pull request will be created to merge the fork's branch into the parent's base. See [push pull request branches to a fork](docs/concepts-guidelines.md#push-pull-request-branches-to-a-fork) for details. | |
|
| `push-to-fork` | A fork of the checked-out parent repository to which the pull request branch will be pushed. e.g. `owner/repo-fork`. The pull request will be created to merge the fork's branch into the parent's base. See [push pull request branches to a fork](docs/concepts-guidelines.md#push-pull-request-branches-to-a-fork) for details. | |
|
||||||
|
@ -88,7 +89,7 @@ How the action behaves:
|
||||||
- If there are changes (i.e. a diff exists with the checked-out base branch), the changes will be pushed to a new `branch` and a pull request created.
|
- If there are changes (i.e. a diff exists with the checked-out base branch), the changes will be pushed to a new `branch` and a pull request created.
|
||||||
- If there are no changes (i.e. no diff exists with the checked-out base branch), no pull request will be created and the action exits silently.
|
- If there are no changes (i.e. no diff exists with the checked-out base branch), no pull request will be created and the action exits silently.
|
||||||
- If a pull request already exists and there are no further changes (i.e. no diff with the current pull request branch) then the action exits silently.
|
- If a pull request already exists and there are no further changes (i.e. no diff with the current pull request branch) then the action exits silently.
|
||||||
- If a pull request exists and new changes on the base branch make the pull request unnecessary (i.e. there is no longer a diff between the base and pull request branch), the pull request is automatically closed and the branch deleted.
|
- If a pull request exists and new changes on the base branch make the pull request unnecessary (i.e. there is no longer a diff between the pull request branch and the base), the pull request is automatically closed. Additionally, if `delete-branch` is set to `true` the `branch` will be deleted.
|
||||||
|
|
||||||
For further details about how the action works and usage guidelines, see [Concepts, guidelines and advanced usage](docs/concepts-guidelines.md).
|
For further details about how the action works and usage guidelines, see [Concepts, guidelines and advanced usage](docs/concepts-guidelines.md).
|
||||||
|
|
||||||
|
@ -176,6 +177,7 @@ jobs:
|
||||||
author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>
|
author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>
|
||||||
signoff: false
|
signoff: false
|
||||||
branch: example-patches
|
branch: example-patches
|
||||||
|
delete-branch: true
|
||||||
title: '[Example] Update report'
|
title: '[Example] Update report'
|
||||||
body: |
|
body: |
|
||||||
Update report
|
Update report
|
||||||
|
|
|
@ -27,6 +27,11 @@ inputs:
|
||||||
branch:
|
branch:
|
||||||
description: 'The pull request branch name.'
|
description: 'The pull request branch name.'
|
||||||
default: 'create-pull-request/patch'
|
default: 'create-pull-request/patch'
|
||||||
|
delete-branch:
|
||||||
|
description: >
|
||||||
|
Delete the `branch` when closing pull requests, and when undeleted after merging.
|
||||||
|
Recommend `true`.
|
||||||
|
default: false
|
||||||
branch-suffix:
|
branch-suffix:
|
||||||
description: 'The branch suffix type when using the alternative branching strategy.'
|
description: 'The branch suffix type when using the alternative branching strategy.'
|
||||||
base:
|
base:
|
||||||
|
|
20
dist/index.js
vendored
20
dist/index.js
vendored
|
@ -1405,6 +1405,7 @@ function run() {
|
||||||
author: core.getInput('author'),
|
author: core.getInput('author'),
|
||||||
signoff: core.getInput('signoff') === 'true',
|
signoff: core.getInput('signoff') === 'true',
|
||||||
branch: core.getInput('branch'),
|
branch: core.getInput('branch'),
|
||||||
|
deleteBranch: core.getInput('delete-branch') === 'true',
|
||||||
branchSuffix: core.getInput('branch-suffix'),
|
branchSuffix: core.getInput('branch-suffix'),
|
||||||
base: core.getInput('base'),
|
base: core.getInput('base'),
|
||||||
pushToFork: core.getInput('push-to-fork'),
|
pushToFork: core.getInput('push-to-fork'),
|
||||||
|
@ -7042,16 +7043,19 @@ function createPullRequest(inputs) {
|
||||||
yield githubHelper.createOrUpdatePullRequest(inputs, baseRemote.repository, branchRepository);
|
yield githubHelper.createOrUpdatePullRequest(inputs, baseRemote.repository, branchRepository);
|
||||||
}
|
}
|
||||||
else {
|
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)) {
|
if (['updated', 'not-updated'].includes(result.action)) {
|
||||||
core.info(`Branch '${inputs.branch}' no longer differs from base branch '${inputs.base}'`);
|
core.info(`Branch '${inputs.branch}' no longer differs from base branch '${inputs.base}'`);
|
||||||
core.info(`Closing pull request and deleting branch '${inputs.branch}'`);
|
if (inputs.deleteBranch) {
|
||||||
yield git.push([
|
core.info(`Deleting branch '${inputs.branch}'`);
|
||||||
'--delete',
|
yield git.push([
|
||||||
'--force',
|
'--delete',
|
||||||
branchRemoteName,
|
'--force',
|
||||||
`refs/heads/${inputs.branch}`
|
branchRemoteName,
|
||||||
]);
|
`refs/heads/${inputs.branch}`
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@ export interface Inputs {
|
||||||
author: string
|
author: string
|
||||||
signoff: boolean
|
signoff: boolean
|
||||||
branch: string
|
branch: string
|
||||||
|
deleteBranch: boolean
|
||||||
branchSuffix: string
|
branchSuffix: string
|
||||||
base: string
|
base: string
|
||||||
pushToFork: string
|
pushToFork: string
|
||||||
|
@ -194,18 +195,21 @@ export async function createPullRequest(inputs: Inputs): Promise<void> {
|
||||||
branchRepository
|
branchRepository
|
||||||
)
|
)
|
||||||
} else {
|
} 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)) {
|
if (['updated', 'not-updated'].includes(result.action)) {
|
||||||
core.info(
|
core.info(
|
||||||
`Branch '${inputs.branch}' no longer differs from base branch '${inputs.base}'`
|
`Branch '${inputs.branch}' no longer differs from base branch '${inputs.base}'`
|
||||||
)
|
)
|
||||||
core.info(`Closing pull request and deleting branch '${inputs.branch}'`)
|
if (inputs.deleteBranch) {
|
||||||
await git.push([
|
core.info(`Deleting branch '${inputs.branch}'`)
|
||||||
'--delete',
|
await git.push([
|
||||||
'--force',
|
'--delete',
|
||||||
branchRemoteName,
|
'--force',
|
||||||
`refs/heads/${inputs.branch}`
|
branchRemoteName,
|
||||||
])
|
`refs/heads/${inputs.branch}`
|
||||||
|
])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
|
@ -13,6 +13,7 @@ async function run(): Promise<void> {
|
||||||
author: core.getInput('author'),
|
author: core.getInput('author'),
|
||||||
signoff: core.getInput('signoff') === 'true',
|
signoff: core.getInput('signoff') === 'true',
|
||||||
branch: core.getInput('branch'),
|
branch: core.getInput('branch'),
|
||||||
|
deleteBranch: core.getInput('delete-branch') === 'true',
|
||||||
branchSuffix: core.getInput('branch-suffix'),
|
branchSuffix: core.getInput('branch-suffix'),
|
||||||
base: core.getInput('base'),
|
base: core.getInput('base'),
|
||||||
pushToFork: core.getInput('push-to-fork'),
|
pushToFork: core.getInput('push-to-fork'),
|
||||||
|
|
Loading…
Reference in a new issue