-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Petr "Stone" Hracek <[email protected]>
- Loading branch information
Showing
6 changed files
with
261 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,9 +25,44 @@ | |
# | ||
# Authors: Petr Hracek <[email protected]> | ||
|
||
import logging | ||
import sys | ||
|
||
import click | ||
|
||
from auto_merger.merger import AutoMerger | ||
from auto_merger.utils import setup_logger | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
@click.command() | ||
@click.option("-d", "--debug", is_flag=True, help="Enable debug logs") | ||
@click.option("--print-results", is_flag=True, help="Prints readable summary") | ||
@click.option("--github-labels", required=True, multiple=True, | ||
help="Specify Git Hub labels to meet criteria") | ||
@click.option("--blocking-labels", multiple=True, | ||
help="Specify Git Hub labels that blocks PR to merge") | ||
@click.option("--send-email", multiple=True, help="Specify email addresses to which the mail will be sent.") | ||
@click.option("--approvals", | ||
default=2, type=int, | ||
help="Specify number of approvals to automatically merge PR. Default 2") | ||
def auto_merger(debug, print_results, github_labels, blocking_labels, approvals, send_email): | ||
am = AutoMerger(github_labels, blocking_labels, approvals) | ||
if debug: | ||
setup_logger("auto-merger", level=logging.DEBUG) | ||
else: | ||
setup_logger("auto-merger", level=logging.INFO) | ||
ret_value = am.check_all_containers() | ||
if ret_value != 0: | ||
sys.exit(2) | ||
if print_results: | ||
am.print_blocked_pull_request() | ||
am.print_approval_pull_request() | ||
if not am.send_results(send_email): | ||
sys.exit(1) | ||
sys.exit(ret_value) | ||
|
||
|
||
if __name__ == "__main__": | ||
auto_merger = AutoMerger() | ||
auto_merger.check_all_containers() | ||
auto_merger() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# MIT License | ||
# | ||
# Copyright (c) 2024 Red Hat, Inc. | ||
|
||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the "Software"), to deal | ||
# in the Software without restriction, including without limitation the rights | ||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
# copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included in all | ||
# copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
# SOFTWARE. | ||
|
||
import smtplib | ||
|
||
|
||
from email.mime.application import MIMEApplication | ||
from email.mime.multipart import MIMEMultipart | ||
from email.mime.text import MIMEText | ||
from typing import List | ||
|
||
|
||
class EmailSender: | ||
|
||
def __init__(self, recipient_email: List[str]): | ||
self.recipient_email = recipient_email | ||
self.mime_msg = MIMEMultipart() | ||
|
||
def send_email(self, subject_msg, body: List[str]): | ||
send_from = "[email protected]" | ||
send_to = self.recipient_email | ||
print(body) | ||
msg = "<br>".join(body) | ||
print(msg) | ||
self.mime_msg["From"] = send_from | ||
self.mime_msg["To"] = ", ".join(send_to) | ||
self.mime_msg["Subject"] = subject_msg | ||
self.mime_msg.attach(MIMEText(msg, "html")) | ||
smtp = smtplib.SMTP("127.0.0.1") | ||
smtp.sendmail(send_from, send_to, self.mime_msg.as_string()) | ||
smtp.close() | ||
print("Sending email finished") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pytest | ||
PyYAML | ||
flexmock | ||
click |
Oops, something went wrong.