Skip to content

Commit

Permalink
Update notification-reminder.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
Sonichigo authored Sep 10, 2024
1 parent 92034b3 commit 9bd677d
Showing 1 changed file with 35 additions and 35 deletions.
70 changes: 35 additions & 35 deletions .github/workflows/notification-reminder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,46 +47,46 @@ jobs:
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')
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'
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)
"
activities = get_pr_issue_activity(member, github_token)
if activities:
send_slack_reminder(member, activities, slack_webhook_url)
"

0 comments on commit 9bd677d

Please sign in to comment.