From 906fd5bb8d0e2fbaaa00096c4d88b0266d08817c Mon Sep 17 00:00:00 2001 From: pdf Date: Mon, 16 Sep 2024 10:39:29 -0700 Subject: [PATCH] Initial --- .gitignore | 1 + run.py | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 .gitignore create mode 100644 run.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bdaab25 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +env/ diff --git a/run.py b/run.py new file mode 100644 index 0000000..7f3ef12 --- /dev/null +++ b/run.py @@ -0,0 +1,59 @@ +import requests +from rocketry import Rocketry +from rocketry.conds import every + +# 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() + +# Function to send a message to Discord +def send_discord_notification(title, email, subject, message, issue_url): + data = { + "content": f"**New Issue**\n**Email:** {email}\n**Subject:** {subject}\n**Message:** {message}\n**Link:** {issue_url}" + } + response = requests.post(DISCORD_WEBHOOK_URL, json=data) + if response.status_code == 204: + print("Notification sent successfully.") + else: + print(f"Failed to send notification. Status code: {response.status_code}") + +# Function to check for new issues +def check_for_new_issues(): + response = requests.get(GITLAB_API_URL, headers=headers) + if response.status_code == 200: + issues = response.json() + for issue in issues: + if issue['id'] not in reported_issues: + 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']) + else: + print(f"Failed to fetch issues. Status code: {response.status_code}") + +# Create a Rocketry app +app = Rocketry() + +# Schedule the task to run every 30 seconds +@app.task(every('20 seconds')) +def scheduled_task(): + check_for_new_issues() + +# Run the Rocketry app +if __name__ == "__main__": + app.run() +