forked from lf-edge/eve
-
Notifications
You must be signed in to change notification settings - Fork 0
68 lines (64 loc) · 2.87 KB
/
close-master-pr.yml
File metadata and controls
68 lines (64 loc) · 2.87 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# Copyright (c) 2025, Zededa, Inc.
# SPDX-License-Identifier: Apache-2.0
---
name: Close PRs from master
on: # yamllint disable-line rule:truthy
pull_request_target:
types: [opened, reopened]
jobs:
close-master-pr:
runs-on: ubuntu-latest
steps:
- name: Close PR if from master
if: github.event.pull_request.head.ref == 'master' || github.event.pull_request.head.ref == 'main'
run: |
# 1) Close the PR via GitHub API
curl -s -X PATCH \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
-d '{"state":"closed"}' \
"https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}"
# 2) Add a comment explaining why
COMMENT_PAYLOAD=$(cat <<EOF
{
"body": "🚨 Hey there! We automatically close PRs from the \`master\` branch.\n\n\
Please create a dedicated feature branch instead. Follow these steps to do it properly:\n\n\
1. Add the upstream repository if you haven't already:\n\n\
\`\`\`sh\n\
git remote add upstream https://github.com/${{ github.repository }}.git\n\
\`\`\`\n\
2. Add your fork as a separate remote:\n\n\
\`\`\`sh\n\
git remote add myfork ${{ github.event.pull_request.head.repo.clone_url }}\n\
\`\`\`\n\
3. Fetch the latest changes from the upstream repository:\n\n\
\`\`\`sh\n\
git fetch upstream\n\
\`\`\`\n\
4. Rebase your \`master\` branch on top of the upstream \`master\`:\n\n\
\`\`\`sh\n\
git rebase upstream/master\n\
\`\`\`\n\
5. Create a new feature branch from the updated \`master\`:\n\n\
\`\`\`sh\n\
git checkout -b feature/my-change\n\
\`\`\`\n\
6. Reset \`master\` to match the upstream version without affecting your feature branch:\n\n\
\`\`\`sh\n\
git branch -f master upstream/master\n\
\`\`\`\n\
7. Push the new feature branch to your fork:\n\n\
\`\`\`sh\n\
git push myfork feature/my-change\n\
\`\`\`\n\n\
Finally, open a new pull request from your \`feature/my-change\` branch.\n\n\
Please also review our [contributing guidelines](https://github.com/${{ github.repository }}/blob/master/CONTRIBUTING.md).\n\n\
Thanks!"
}
EOF
)
curl -s -X POST \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
-d "$COMMENT_PAYLOAD" \
"https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments"