From 917722ac717c61b709539fe885fbe3a7291cfb2d Mon Sep 17 00:00:00 2001 From: "Eric T. Johnson" Date: Tue, 12 Nov 2024 15:30:03 -0500 Subject: [PATCH] Add GH actions workflow to replace mergeable bot --- .github/mergeable.yml | 13 ------- .github/workflows/check-title-and-labels.yaml | 37 +++++++++++++++++++ 2 files changed, 37 insertions(+), 13 deletions(-) delete mode 100644 .github/mergeable.yml create mode 100644 .github/workflows/check-title-and-labels.yaml diff --git a/.github/mergeable.yml b/.github/mergeable.yml deleted file mode 100644 index 0fa89860041..00000000000 --- a/.github/mergeable.yml +++ /dev/null @@ -1,13 +0,0 @@ -# config file for mergeable: https://github.com/mergeability/mergeable -version: 2 -mergeable: - - when: pull_request.* - validate: - - do: title - must_exclude: - regex: ^\[?WIP\b - message: "WIP pull requests can't be merged." - - do: label - must_include: - regex: 'bug|enhancement|new feature|docs|infrastructure|dead code|refactor' - message: "Please label this pull request with one of: bug, enhancement, new feature, docs or infrastructure." diff --git a/.github/workflows/check-title-and-labels.yaml b/.github/workflows/check-title-and-labels.yaml new file mode 100644 index 00000000000..8d45d3997f0 --- /dev/null +++ b/.github/workflows/check-title-and-labels.yaml @@ -0,0 +1,37 @@ +# based on https://stackoverflow.com/a/75036059 and +# https://github.com/astropy/astropy/blob/main/.github/workflows/check_milestone.yml +name: Check PR title and labels + +on: + # So it cannot be skipped. + pull_request_target: + types: [opened, edited, synchronize, labeled, unlabeled] + +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref }} + cancel-in-progress: true + +jobs: + check-title: + runs-on: ubuntu-latest + steps: + - uses: actions/github-script@v7 + with: + script: | + if (/^\[?WIP\b/i.test(context.payload.pull_request.title)) { + core.setFailed("WIP pull requests can't be merged."); + } + + check-labels: + runs-on: ubuntu-latest + steps: + - uses: actions/github-script@v7 + with: + script: | + const requiredLabels = ['bug', 'enhancement', 'new feature', 'docs', 'infrastructure', 'dead code', 'refactor']; + let labels = context.payload.pull_request.labels; + + core.info(`Current labels: ${labels.map(l => l.name).join(', ')}`); + if (labels.filter(l => requiredLabels.includes(l.name)).length === 0) { + core.setFailed('Please label this pull request with one of: bug, enhancement, new feature, docs or infrastructure.'); + }