check last updated time

This commit is contained in:
Nixon 2024-09-16 10:44:32 -07:00
parent 906fd5bb8d
commit 2ae6c03618
No known key found for this signature in database
2 changed files with 9 additions and 10 deletions

17
run.py
View file

@ -1,22 +1,18 @@
import requests
from rocketry import Rocketry
from rocketry.conds import every
from sec import GITLAB_API_TOKEN, DISCORD_WEBHOOK_URL
# GitLab API token and repository details
GITLAB_API_TOKEN = 'glpat-8i4z8VbfL9a76YxFqHHC'
GITLAB_API_URL = 'https://gitlab.com/api/v4/projects/codebreaker-challenge%2F2024%2Foutreach-2024/issues?state=opened'
GITLAB_PROJECT_URL = 'https://gitlab.com/codebreaker-challenge/2024/outreach-2024'
# Discord webhook URL
DISCORD_WEBHOOK_URL = 'https://discord.com/api/webhooks/1285276886871834655/0pRndW9BZjUUmLlcELIT1fLkOXKfe-FEX3WDpoPZT7MMvKvK9V_dFo7FkDfB2W3CRghV'
# Headers for GitLab API request
headers = {
'Private-Token': GITLAB_API_TOKEN
}
# Set to keep track of reported issues
reported_issues = set()
# Dictionary to keep track of reported issues and their update times
reported_issues = {}
# Function to send a message to Discord
def send_discord_notification(title, email, subject, message, issue_url):
@ -35,13 +31,15 @@ def check_for_new_issues():
if response.status_code == 200:
issues = response.json()
for issue in issues:
if issue['id'] not in reported_issues:
issue_id = issue['id']
updated_at = issue['updated_at']
if issue_id not in reported_issues or reported_issues[issue_id] != updated_at:
title = issue['title']
email, subject = title.split(' - ', 1)
message = issue['description'][:50] + '...' if len(issue['description']) > 50 else issue['description']
issue_url = f"{GITLAB_PROJECT_URL}/-/issues/{issue['iid']}"
send_discord_notification(title, email, subject, message, issue_url)
reported_issues.add(issue['id'])
reported_issues[issue_id] = updated_at
else:
print(f"Failed to fetch issues. Status code: {response.status_code}")
@ -56,4 +54,3 @@ def scheduled_task():
# Run the Rocketry app
if __name__ == "__main__":
app.run()

2
sec.py Normal file
View file

@ -0,0 +1,2 @@
GITLAB_API_TOKEN = 'glpat-8i4z8VbfL9a76YxFqHHC'
DISCORD_WEBHOOK_URL = 'https://discord.com/api/webhooks/1285276886871834655/0pRndW9BZjUUmLlcELIT1fLkOXKfe-FEX3WDpoPZT7MMvKvK9V_dFo7FkDfB2W3CRghV'