peter-evans / close-pull Goto Github PK
View Code? Open in Web Editor NEWA GitHub action to close a pull request and optionally delete its branch.
License: MIT License
A GitHub action to close a pull request and optionally delete its branch.
License: MIT License
if i have two prs:
- #1 fix: [ABC-123] do-something
- #2 invalid branch name
and they have different branches:
- #1 fix: [ABC-123] do-something
fix/ABC-123-do-something
- #2 invalid branch name
invalid-branch-name
But both those branches point to the same commit ref:
- #1 fix: [ABC-123] do-something
d280cce fix/ABC-123-do-something
- #2 invalid branch name
d280cce invalid-branch-name
This ends up doing the following:
invalid-branch-name
branchExpectations:
#2
#2
invalid-branch-name
branchIs there something I'm missing?
Then when i run this action with:
# ./pkg/format-prtitle/action.yml
name: Enforce branch name conventions
description: This will close pull requests that do not follow the branch naming conventions
inputs:
ValidationPattern:
description: acceptable branch name regex
required: false
ValidationCommand:
description: a command to run that returns exit code 0 for success or exit code 1 for failure
required: false
HelpUrl:
description: A url to display that provides more detailed information to the user
required: false
GithubToken:
description: should we use context or fetch the latest title
required: false
default: ${{github.token}}
BranchName:
description: name of the branch to test
required: true
runs:
using: "composite"
steps:
- name: Test branch with pattern
if: inputs.ValidationPattern != '' && inputs.ValidationCommand == ''
uses: actions/github-script@v6
env:
PATTERN: ${{inputs.ValidationPattern}}
BRANCH: ${{inputs.BranchName}}
with:
github-token: ${{inputs.GithubToken}}
script: |
const validator = new RegExp(process.env.PATTERN);
validator.test(process.env.BRANCH)
? process.exit(0)
: process.exit(1);
- name: Test brach with command
if: inputs.ValidationPattern == '' && inputs.ValidationCommand != ''
shell: bash
run: ${{inputs.ValidationCommand}}
- name: create additional information link
if: failure()
shell: bash
env:
HELP_URL: ${{inputs.HelpUrl}}
run: |
[ -n "${HELP_URL}" ] && {
echo "MORE_INFORMATION='For more information see: ${HELP_URL}'" >> $GITHUB_ENV
} || {
echo "MORE_INFORMATION=''" >> $GITHUB_ENV
}
- name: Add/Update Help Comment
if: failure()
uses: peter-evans/close-pull@v2
with:
token: ${{inputs.GithubToken}}
delete-branch: true
comment: |
The branch name used is invalid.
To fix this, please rename your branch locally and open a new pull request.
```
$ git branch -m <correct branch pattern>
```
${{env.MORE_INFORMATION}}
which will be run in a workflow like so:
# .github/workflows/code-review-titles.yml
name: CodeReviewTitles
on:
pull_request:
types: ['opened', 'edited', 'reopened', 'ready_for_review', 'synchronize']
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
Format:
runs-on: ubuntu-latest
permissions:
pull-requests: write
issues: write
contents: read
repository-projects: write
steps:
- uses: actions/checkout@v3
- name: get branchpattern
id: branchpattern
uses: actions/github-script@v6
with:
github-token: ${{secrets.OUR_BOT_TOKEN}}
script: return require("./.validate-branch-namerc").pattern
result-encoding: string
- name: Close PRs with invalid branchnames
uses: ./pkg/enforce-branchname
with:
ValidationPattern: ${{steps.branchpattern.outputs.result}}
BranchName: ${{github.head_ref}}
- uses: ./pkg/format-prtitle
with:
Pattern: ${{steps.branchpattern.outputs.result}}
GithubToken: ${{secrets.OUR_BOT_TOKEN}}
- uses: ./pkg/setup-tooling
- uses: ./pkg/setup-pnpm
- uses: ./pkg/commitlint-prtitle
with:
InstallCommitLint: false
FetchTitle: true
GithubToken: ${{secrets.OUR_BOT_TOKEN}}
This is more of a feature request than anything else.
Would it be possible to have the action close all pull requests that have the titles corresponding to the Regex Match?
Would be cool and in some cases more useful than just a PR number.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.