Git Product home page Git Product logo

close-pull's Introduction

Close Pull

CI GitHub Marketplace

A GitHub action to close a pull request and optionally delete its branch.

Usage

โ— Using this action is no longer necessary

The same functionality exists in the GitHub CLI. See the documentation here.

    - name: Close Pull
      run: gh pr close --comment "Auto-closing pull request" --delete-branch "1"
      env:
        GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

If you prefer to use this action:

      - name: Close Pull
        uses: peter-evans/close-pull@v3
        with:
          pull-request-number: 1
          comment: Auto-closing pull request
          delete-branch: true

Action inputs

Name Description Default
token GITHUB_TOKEN or a repo scoped PAT. GITHUB_TOKEN
repository The GitHub repository containing the pull request. Current repository
pull-request-number The number of the pull request to close. github.event.number
comment A comment to make on the pull request before closing.
delete-branch Delete the pull request branch. false

Note: Deleting branches will fail silently for pull requests to public repositories from forks. Private repositories can be configured to enable workflows from forks to run without restriction.

Accessing pull requests in other repositories

You can close pull requests in another repository by using a PAT instead of GITHUB_TOKEN. The user associated with the PAT must have write access to the repository.

License

MIT

close-pull's People

Contributors

actions-bot avatar dependabot[bot] avatar peter-evans avatar renovate-bot avatar renovate[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

close-pull's Issues

unexpected: closing PR closes all PRs for the commit not the branch

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:

  • closes both PRs
  • leaves a comment on both PRs
  • deletes the invalid-branch-name branch

Expectations:

  • closes PR #2
  • leaves a comment on PR #2
  • deletes the invalid-branch-name branch

Is 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}}

Allow regex matching

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.