Skip to content

Daily GitHub Issues Report #121

Daily GitHub Issues Report

Daily GitHub Issues Report #121

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: |
echo "#!/usr/bin/env python3" > script.py
echo "import requests" >> script.py
echo "import json" >> script.py
echo "from datetime import datetime" >> script.py
echo "" >> script.py
echo "GITHUB_API_URL = 'https://api.github.com/repos/pagopa/pagopa-api/issues'" >> script.py
echo "GITHUB_TOKEN = '${{ secrets.GH_TOKEN_ISSUES_DAILY_REPORT }}'" >> script.py
echo "SLACK_WEBHOOK_URL = '${{ secrets.SLACK_WEBHOOK_URL }}'" >> script.py
echo "" >> script.py
echo "def get_github_issues():" >> script.py
echo " headers = {" >> script.py
echo " 'Authorization': f'token {GITHUB_TOKEN}'" >> script.py
echo " }" >> script.py
echo " response = requests.get(GITHUB_API_URL, headers=headers)" >> script.py
echo " issues = response.json()" >> script.py
echo " return [issue for issue in issues if not issue.get('labels') and 'pull_request' not in issue]" >> script.py
echo "" >> script.py
echo "def create_slack_message(issues):" >> script.py
echo " today = datetime.now().strftime('%Y-%m-%d')" >> script.py
echo " message = {" >> script.py
echo " 'text': f'Issue Report for {today}'," >> script.py
echo " 'blocks': [" >> script.py
echo " {" >> script.py
echo " 'type': 'section'," >> script.py
echo " 'text': {" >> script.py
echo " 'type': 'mrkdwn'," >> script.py
echo " 'text': '*Buongiorno, queste sono le issue github aperte e non ancora prese in carico*'" >> script.py
echo " }" >> script.py
echo " }," >> script.py
echo " {" >> script.py
echo " 'type': 'divider'" >> script.py
echo " }" >> script.py
echo " ]" >> script.py
echo " }" >> script.py
echo "" >> script.py
echo " for issue in issues:" >> script.py
echo " issue_url = issue['html_url']" >> script.py
echo " issue_title = issue['title']" >> script.py
echo " issue_created_at = issue['created_at']" >> script.py
echo " issue_creator = issue['user']['login']" >> script.py
echo " message['blocks'].append({" >> script.py
echo " 'type': 'section'," >> script.py
echo " 'fields': [" >> script.py
echo " {" >> script.py
echo " 'type': 'mrkdwn'," >> script.py
echo " 'text': f'*< {issue_url} | {issue_title} >*'" >> script.py
echo " }," >> script.py
echo " {" >> script.py
echo " 'type': 'mrkdwn'," >> script.py
echo " 'text': f'*Creato il:* {issue_created_at}'" >> script.py
echo " }," >> script.py
echo " {" >> script.py
echo " 'type': 'mrkdwn'," >> script.py
echo " 'text': f'*Creato da:* {issue_creator}'" >> script.py
echo " }" >> script.py
echo " ]" >> script.py
echo " })" >> script.py
echo " message['blocks'].append({" >> script.py
echo " 'type': 'divider'" >> script.py
echo " })" >> script.py
echo " return message" >> script.py
echo "" >> script.py
echo "def send_slack_message(message):" >> script.py
echo " headers = {" >> script.py
echo " 'Content-Type': 'application/json'" >> script.py
echo " }" >> script.py
echo " response = requests.post(SLACK_WEBHOOK_URL, headers=headers, data=json.dumps(message))" >> script.py
echo " if response.status_code != 200:" >> script.py
echo " raise ValueError(f'Request to Slack returned an error {response.status_code}, the response is:\\n{response.text}')" >> script.py
echo "" >> script.py
echo "def main():" >> script.py
echo " issues = get_github_issues()" >> script.py
echo " slack_message = create_slack_message(issues)" >> script.py
echo " send_slack_message(slack_message)" >> script.py
echo "" >> script.py
echo "if __name__ == '__main__':" >> script.py
echo " main()" >> script.py
python script.py