Skip to content

Commit e43ae16

Browse files
nithishrCopilot
andauthored
Update GitHub Actions workflow to improve PR alert conditions (#53)
* Update GitHub Actions workflow to improve PR alert conditions - Enhanced the alert-on-pr.yml workflow to include conditions for triggering alerts based on the source of the pull request, specifically for PRs from forked repositories. - Adjusted the Python version specification format for consistency. * Update .github/workflows/alert-on-pr.yml Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 5e498ed commit e43ae16

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

.github/workflows/alert-on-pr.yml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,26 @@ permissions:
1111

1212
jobs:
1313
alert:
14+
# Only run this job if:
15+
# - The event is 'pull_request' and the PR is from the same repository (not a fork), OR
16+
# - The event is 'pull_request_target' and the PR is from a forked repository.
17+
# This ensures that PRs from forks are handled with 'pull_request_target' (for security),
18+
# while PRs from the same repo are handled with 'pull_request'.
19+
if: >-
20+
(
21+
github.event_name == 'pull_request' &&
22+
github.event.pull_request.head.repo.full_name == github.repository
23+
) ||
24+
(
25+
github.event_name == 'pull_request_target' &&
26+
github.event.pull_request.head.repo.full_name != github.repository
27+
)
1428
runs-on: ubuntu-latest
1529
steps:
1630
- name: Set up Python
1731
uses: actions/setup-python@v5
1832
with:
19-
python-version: '3.11'
33+
python-version: "3.11"
2034

2135
- name: Install requests
2236
run: |
@@ -57,4 +71,4 @@ jobs:
5771
except Exception as e:
5872
print(f"Slack notification failed: {e}")
5973
else:
60-
print("SLACK_WEBHOOK missing or invalid; skipping Slack notification.")
74+
print("SLACK_WEBHOOK missing or invalid; skipping Slack notification.")

0 commit comments

Comments
 (0)