diff options
| author | Daniel Smith <daniel.smith@qt.io> | 2024-07-24 11:03:06 +0200 |
|---|---|---|
| committer | Daniel Smith <daniel.smith@qt.io> | 2024-07-24 11:04:35 +0200 |
| commit | d6752d1912619a52b44dbbe9ef3714386c98a01c (patch) | |
| tree | 0b2400252230dfd6707db2738ebbf83c0b699696 /email_alert.py | |
Initial Commit of Qt Binary Size Bot
Task-number: QTQAINFRA-6459
Change-Id: I50887b05bd7f11119092ba284082aacc3062ee19
Diffstat (limited to 'email_alert.py')
| -rw-r--r-- | email_alert.py | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/email_alert.py b/email_alert.py new file mode 100644 index 0000000..4520196 --- /dev/null +++ b/email_alert.py @@ -0,0 +1,37 @@ +# Copyright (C) 2024 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only +""" Module contains logic for sending email alerts for git commit authors """ + +import urllib +import smtplib +from email.message import EmailMessage +from pygerrit2 import GerritRestAPI + + +def get_authors(url, project, shas): + """ Fetches authors for given shas""" + https_url = f"https://{url}" + authors = [] + + rest_api = GerritRestAPI(https_url, auth=None) + encoded_project = urllib.parse.quote(project, safe='') + for sha in shas: + res = rest_api.get(f"/projects/{encoded_project}/commits/{sha}") + authors.append(res["author"]["email"]) + + return authors + + +def send_email(smtp_server, sender, authors, cc, subject, message): + # pylint: disable=R0913 + """ Sends email for authors """ + msg = EmailMessage() + msg.set_content(message) + msg['Subject'] = subject + msg['From'] = sender + msg['Cc'] = cc + msg['To'] = ', '.join(authors) + + s = smtplib.SMTP(smtp_server) + s.send_message(msg) + s.quit() |
