Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions .github/workflows/alert-on-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Alert on PR Changes

on:
pull_request:
types: [opened, synchronize, reopened]

permissions:
contents: read

jobs:
alert:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'

- name: Install requests
run: |
python -m pip install --upgrade pip
pip install requests

- name: Send Slack alert on PR changes
env:
SLACK_WEBHOOK: ${{ secrets.DEVEX_ALERTS_SECRET }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.pull_request.number }}
run: |
import requests, os
repo = os.environ.get('GITHUB_REPOSITORY')
pr_number = os.environ.get('PR_NUMBER')
token = os.environ.get('GITHUB_TOKEN')
api_url = f"https://api.github.com/repos/{repo}/pulls/{pr_number}"
headers = {'Authorization': f'token {token}', 'Accept': 'application/vnd.github.v3+json'}
pr_resp = requests.get(api_url, headers=headers)
branch_name = os.environ.get('GITHUB_HEAD_REF', '')
if pr_resp.status_code == 200:
pr_data = pr_resp.json()
pr_title = pr_data.get('title', '')
pr_body = pr_data.get('body', '')
pr_user = pr_data.get('user', {}).get('login', '')
pr_url = pr_data.get('html_url', '')
message = f"PR Alert!\nTitle: {pr_title}\nBranch: {branch_name}\nAuthor: {pr_user}\nURL: {pr_url}\nDescription: {pr_body}"
else:
message = f"PR Alert!\nUnable to fetch PR details.\nStatus Code: {pr_resp.status_code}\nResponse: {pr_resp.text}"
webhook = os.environ['SLACK_WEBHOOK']
requests.post(webhook, json={"text": message})
shell: python