-
Notifications
You must be signed in to change notification settings - Fork 333
45 lines (37 loc) · 1.47 KB
/
check_fork_status.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
name: Check Fork Status and Notify
on:
pull_request:
types: [opened, synchronize] # Trigger when a PR is opened or updated
permissions:
pull-requests: write # Allow posting comments on PRs
jobs:
check_fork:
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
uses: actions/checkout@v3
with:
fetch-depth: 2 # Fetch enough history to compare branches
- name: Fetch the latest base branch
run: |
git fetch origin main # Replace 'main' with your base branch if different
- name: Check if the branch is up to date
id: check_fork
run: |
# Compare the contributor's branch with the base branch (main)
behind_count=$(git rev-list --right-only --count HEAD...origin/main)
echo "::set-output name=behind::$behind_count"
- name: Comment on the PR if fork is outdated
if: steps.check_fork.outputs.behind != '0' # If the fork is behind
uses: actions/github-script@v7
with:
script: |
const prNumber = context.payload.pull_request.number;
const owner = context.repo.owner;
const repo = context.repo.repo;
await github.rest.issues.createComment({
owner: owner,
repo: repo,
issue_number: prNumber,
body: '⚠️ It looks like your branch is out of date with the base branch. Please sync your fork and update the PR.'
});