Skip to content

Issue number #1780 and #1781 is solved #727

Issue number #1780 and #1781 is solved

Issue number #1780 and #1781 is solved #727

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.'
});