From cd9378acfc636a7568124b687a6ea6dc97d38929 Mon Sep 17 00:00:00 2001 From: Vasil Kotsev <9307969+SonnyRR@users.noreply.github.com> Date: Wed, 6 Nov 2024 19:30:53 +0200 Subject: [PATCH] Add support for skipping notifications via labels --- README.md | 4 ++++ action.yml | 25 +++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index cc76800..1ab343d 100644 --- a/README.md +++ b/README.md @@ -45,4 +45,8 @@ request-number: descripton: "The pull request number" default: ${{ github.event.pull_request.number }} required: true +no-sync-label: + description: "The label value, used for tagging PRs that shouldn't be checked" + default: 'no-branch-sync' + required: false ``` diff --git a/action.yml b/action.yml index c325bab..94b11e5 100644 --- a/action.yml +++ b/action.yml @@ -1,5 +1,5 @@ name: "Branch out-of-sync notifier" -description: "Comments on an open PR if the base branch is out of sync with the target one." +description: "Comments on a given PR if the base branch is out of sync with the target one." branding: icon: git-branch color: orange @@ -21,6 +21,10 @@ inputs: descripton: "The pull request number" default: ${{ github.event.pull_request.number }} required: true + no-sync-label: + description: "The label value, used for tagging PRs that shouldn't be checked" + default: 'no-branch-sync' + required: false runs: using: "composite" @@ -32,8 +36,24 @@ runs: submodules: true clean: false + - name: Check if no-sync label has been applied + uses: actions/github-script@v7 + id: "check-for-no-sync-label" + with: + script: | + const labels = await github.paginate(github.rest.issues.listLabelsOnIssue, { + issue_number: ${{ inputs.request-number }}, + owner: context.repo.owner, + repo: context.repo.repo, + }); + + const projectedLabels = labels?.map(l => l.name); + const isNoSyncLabelApplied = projectedLabels.includes('${{ inputs.no-sync-label }}'); + return isNoSyncLabelApplied; + - name: Compare branches id: "compare-branches" + if: steps.check-for-no-sync-label.outputs.result == 'false' shell: bash run: | git fetch --all @@ -42,6 +62,7 @@ runs: - name: Remove existing comments uses: actions/github-script@v7 + if: steps.check-for-no-sync-label.outputs.result == 'false' env: # Top level env. variables are not supported in composite actions :( SYNC_BOT_TITLE: "Branch Sync Notifier" @@ -77,7 +98,7 @@ runs: ### Hey, @${{ inputs.request-owner }}! :wave: ### Your branch is out of sync with the PR's target branch. - ### Please rebase it on top of the latest changes from \`${{ github.event.pull_request.base.ref }}\` or merge them. :sun_with_face: + ### Please rebase it on top of the latest changes from \`${{ inputs.base-ref }}\` or merge them. :sun_with_face: **Run: [${{ github.run_number }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) :rabbit2:** **Attempt: № \`${{ github.run_attempt }}\` :eyes:**