-
Notifications
You must be signed in to change notification settings - Fork 15
95 lines (81 loc) · 3.24 KB
/
Daily_GitHub_Issues_Report.yaml
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
name: Daily GitHub Issues Report
on:
schedule:
- cron: '0 9 * * *' # Esegue ogni giorno alle 9:00 UTC
workflow_dispatch: # Permette di eseguire manualmente il workflow
jobs:
report:
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: Install dependencies
run: |
python -m pip install --upgrade pip
pip install requests
- name: Generate and send report
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN_ISSUES_DAILY_REPORT }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
run: |
#!/usr/bin/env python3
import requests
import json
from datetime import datetime
GITHUB_API_URL = 'https://api.github.com/repos/pagopa/pagopa-api/issues'
GITHUB_TOKEN = '${{ secrets.GH_TOKEN_ISSUES_DAILY_REPORT }}'
SLACK_WEBHOOK_URL = '${{ secrets.SLACK_WEBHOOK_URL }}'
def get_github_issues():
headers = {
'Authorization': f'token {GITHUB_TOKEN}'
}
response = requests.get(GITHUB_API_URL, headers=headers)
issues = response.json()
return issues
def filter_issues_by_label(issues, label):
filtered_issues = [issue for issue in issues if label in [lbl['in progress'] for lbl in issue['labels']]]
return filtered_issues
def create_slack_message(issues_by_label):
today = datetime.now().strftime('%Y-%m-%d')
message = {
"text": f"Issue Report for {today}",
"blocks": []
}
for label, issues in issues_by_label.items():
message["blocks"].append({
"type": "section",
"text": {
"type": "mrkdwn",
"text": f"*Label: {label}*"
}
})
message["blocks"].append({"type": "divider"})
for issue in issues:
issue_text = f"<{issue['html_url']}|{issue['title']}>"
message["blocks"].append({
"type": "section",
"text": {
"type": "mrkdwn",
"text": issue_text
}
})
return message
def send_slack_message(message):
headers = {
'Content-Type': 'application/json'
}
response = requests.post(SLACK_WEBHOOK_URL, headers=headers, data=json.dumps(message))
if response.status_code != 200:
raise ValueError(f"Request to Slack returned an error {response.status_code}, the response is:\n{response.text}")
def main():
issues = get_github_issues()
labels = set(lbl['name'] for issue in issues for lbl in issue['labels'])
issues_by_label = {label: filter_issues_by_label(issues, label) for label in labels}
slack_message = create_slack_message(issues_by_label)
send_slack_message(slack_message)
if __name__ == "__main__":
main()