Skip to content

Commit

Permalink
Add support for skipping notifications via labels
Browse files Browse the repository at this point in the history
  • Loading branch information
SonnyRR committed Nov 6, 2024
1 parent ad1d6e0 commit cd9378a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
25 changes: 23 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"
Expand All @@ -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
Expand 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"
Expand Down Expand Up @@ -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:**
Expand Down

0 comments on commit cd9378a

Please sign in to comment.