diff --git a/.github/workflows/notify_updates.yml b/.github/workflows/notify_updates.yml deleted file mode 100644 index 7ecf4cc04..000000000 --- a/.github/workflows/notify_updates.yml +++ /dev/null @@ -1,24 +0,0 @@ -name: Announce updates - -on: - workflow_dispatch: - schedule: - - cron: 0 19 * * * # every day at 19:00 - -jobs: - notify: - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v5 - - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install ghexplain - - - name: Run script - env: - WEBHOOK_URL: ${{ secrets.WEBHOOK_URL }} - run: | - GITHUB_TOKEN=${{ secrets.PROJECT_STATUS_BOT_TOKEN }} python scripts/announce_updates.py $WEBHOOK_URL diff --git a/scripts/Readme.md b/scripts/Readme.md index 353d2f29f..bfbede4ec 100644 --- a/scripts/Readme.md +++ b/scripts/Readme.md @@ -96,24 +96,3 @@ This script retrieves open issues labeled "testing" from the NethServer/nethsecu - 0 - Success - 1 - Error when sending the message or missing Mattermost webhook URL - 2 - Error when loading issues from GitHub - -## announce_updates.py - -This script is used to announce packages updates released today. The announce is sent to a Mattermost channel via webhook. - -### Usage - -```bash -export GITHUB_TOKEN=ghoxxx; ./announce_updates.py -``` - -### Requirements - -- Python 3 -- ghexplain library (install via `pip install ghexplain`) - -### How It Works - -1. Fetches the list of packages updated today from the NethServer/nethserver GitHub repository. -2. Prepares a message listing the updated packages. -3. Sends the prepared message to a Mattermost channel using the provided webhook URL. \ No newline at end of file diff --git a/scripts/announce_updates.py b/scripts/announce_updates.py deleted file mode 100755 index 203b8d41e..000000000 --- a/scripts/announce_updates.py +++ /dev/null @@ -1,74 +0,0 @@ -#!/usr/bin/python3 - -import os -import sys -import requests -from datetime import datetime, timezone -import ghexplain - -# Set environment variable for GitHub token -GITHUB_TOKEN = os.getenv("GITHUB_TOKEN") - -# Repository information -REPO = "NethServer/nethsecurity" - -# Get today's date in ISO format -today = datetime.now(timezone.utc).replace(hour=0, minute=0, second=1, microsecond=0).isoformat() - -# GitHub API URL -GITHUB_API_URL = f"https://api.github.com/repos/{REPO}/issues" - - -def fetch_closed_issues(): - issues = [] - headers = { - "Authorization": f"token {GITHUB_TOKEN}", - "Accept": "application/vnd.github.v3+json" - } - response = requests.get(GITHUB_API_URL, headers=headers, params={"state": "closed", "since": today, "per_page": 100}) - response.raise_for_status() - for issue in response.json(): - # skip pull requests and issues with type name "Design" and "Task" - if 'pull_request' in issue or issue['type']['name'] in ["Design", "Task"]: - continue - issues.append(issue) - return issues - -def create_announcement(issues): - today_str = datetime.now().strftime("%d %B %Y") - announcement = f"## Updates released on {today_str}\n\n" - for issue in issues: - # log to stderr the processed issue - print(f"Processing issue {issue['number']}", file=sys.stderr) - icon = "" - title = issue["title"] - url = issue["html_url"] - if any('milestone goal' in label['name'] for label in issue['labels']): - icon = f"{title} :crown:" # Highlight the title - announcement += f"#### {title} ([{issue['number']}]({issue['url']})) {icon}\n" - explanation = ghexplain.issue(url) - announcement += f"{explanation}\n\n" - if icon: - announcement += "\nThis feature is a milestone goal.\n\n" - return announcement - -if __name__ == "__main__": - if len(sys.argv)!= 2: - print("No Mattermost webhook", file=sys.stderr) - sys.exit(1) - - closed_issues = fetch_closed_issues() - if not closed_issues: - print("No updates today", file=sys.stderr) - sys.exit(0) - announcement = create_announcement(closed_issues) - - webhook_url = sys.argv[1] - data = { "text": announcement } - response = requests.post(webhook_url, json=data) - - if response.status_code == 200: - print("Message sent!", file=sys.stderr) - else: - print(f"Error when sending the message: {response.text}", file=sys.stderr) - sys.exit(1) \ No newline at end of file