Skip to content

PR and Issue Activity Reminder via Slack #11

PR and Issue Activity Reminder via Slack

PR and Issue Activity Reminder via Slack #11

name: PR and Issue Activity Reminder via Slack
# on:
# schedule:
# - cron: '0 10 */2 * *' # Runs at 10:00 AM UTC every 2 days
# workflow_dispatch:
on:
schedule:
- cron: '*/5 * * * *' # Runs every 5 minutes
workflow_dispatch:
jobs:
send-reminders:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Debug Environment
run: |
echo "Current directory: $(pwd)"
echo "Directory contents:"
ls -la
echo "Python version:"
python --version
echo "Pip version:"
pip --version
echo "System information:"
uname -a
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install PyGithub requests
pip list
- name: Send PR and issue activity reminders via Slack
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ORG_NAME: ${{ secrets.ORG_NAME }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
run: |
python -c "
import os
import json
import requests
from github import Github
def get_org_members(org_name, github_token):
g = Github(github_token)
org = g.get_organization(org_name)
return [member.login for member in list(org.get_members())]
def get_pr_issue_activity(username, github_token):
g = Github(github_token)
user = g.get_user(username)
pr_issue_activity = []
for notification in user.get_notifications(participating=True):
if notification.subject.type in ['PullRequest', 'Issue']:
pr_issue_activity.append({
'type': notification.subject.type,
'title': notification.subject.title,
'url': notification.subject.url.replace('api.github.com/repos', 'github.com')
})
return pr_issue_activity
def send_slack_reminder(username, activities, webhook_url):
if not activities:
return
message = f'*Reminder for @{username}*\n'
message += f'You have {len(activities)} unread PR/issue notifications:\n'
for activity in activities:
message += f'• {activity['type']}: <{activity['url']}|{activity['title']}>\n'
payload = {'text': message, 'username': 'GitHub Notification Bot', 'icon_emoji': ':github:'}
requests.post(webhook_url, json=payload)
github_token = os.environ['GITHUB_TOKEN']
org_name = os.environ['ORG_NAME']
slack_webhook_url = os.environ['SLACK_WEBHOOK_URL']
org_members = get_org_members(org_name, github_token)
for member in org_members:
activities = get_pr_issue_activity(member, github_token)
if activities:
send_slack_reminder(member, activities, slack_webhook_url)
"