From 44809182b1b62a8da5b7c5bec3b22987581779d5 Mon Sep 17 00:00:00 2001 From: Jacob Coffee Date: Sun, 7 Jan 2024 04:48:32 -0600 Subject: [PATCH] ci: add new feature notifier (#2889) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit feat(ci): add new feature notifier Signed-off-by: Janek Nouvertné <25355197+provinzkraut@users.noreply.github.com> --------- Signed-off-by: Janek Nouvertné <25355197+provinzkraut@users.noreply.github.com> Co-authored-by: Janek Nouvertné <25355197+provinzkraut@users.noreply.github.com> --- .github/workflows/pr-target.yml | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/.github/workflows/pr-target.yml b/.github/workflows/pr-target.yml index fd1a0209a8..6b9181f09c 100644 --- a/.github/workflows/pr-target.yml +++ b/.github/workflows/pr-target.yml @@ -6,11 +6,9 @@ on: - opened - edited - synchronize - branches: - - main permissions: - pull-requests: read + pull-requests: write jobs: main: @@ -18,7 +16,25 @@ jobs: runs-on: ubuntu-latest steps: - name: Check PR target - if: ${{ startsWith(github.event.pull_request.title, 'feat') }} + id: check-pr-target + uses: actions/github-script@v7 + with: + script: | + const isFeature = context.payload.pull_request.title.startsWith('feat'); + const targetsMain = context.payload.pull_request.base.ref == 'main'; + core.setOutput('needs-rebase', isFeature && targetsMain ? 'true' : 'false'); + + - name: Comment PR + if: steps.check-pr-target.outputs.needs-rebase == 'true' + uses: thollander/actions-comment-pull-request@v2 + with: + message: "It looks like you are adding a new feature! :rocket: Please rebase and point your PR to the `develop` branch." + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + comment_tag: check_pr_target + mode: recreate + + - name: Fail if feature PR is targeted to main + if: steps.check-pr-target.outputs.needs-rebase == 'true' uses: actions/github-script@v7 with: script: |