Skip to content

Commit

Permalink
This pull request sends email in better HTLM style.
Browse files Browse the repository at this point in the history
Just one row is not so readable.

Let's show in TableView better way.

Signed-off-by: Petr "Stone" Hracek <[email protected]>
  • Loading branch information
phracek committed Nov 5, 2024
1 parent b6fe507 commit 924e8ac
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
4 changes: 3 additions & 1 deletion auto_merger/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ def send_email(self, subject_msg, body: List[str]):
send_from = "[email protected]"
send_to = self.recipient_email
print(body)
msg = "<br>".join(body)
whole_body = "".join(body)
msg = ("<html><head><style>table, th, td {border: 1px solid black;}</style></head>"
f"<body>{whole_body}</body></html>")
print(msg)
self.mime_msg["From"] = send_from
self.mime_msg["To"] = ", ".join(send_to)
Expand Down
26 changes: 15 additions & 11 deletions auto_merger/merger.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,38 +240,42 @@ def print_blocked_pull_request(self):
# Do not print anything in case we do not have PR.
if not [x for x in self.blocked_pr if self.blocked_pr[x]]:
return 0
self.blocked_body.append(f"Pull requests that are blocked by labels [{', '.join(self.blocking_labels)}]")
self.blocked_body.append(
f"Pull requests that are blocked by labels <b>[{', '.join(self.blocking_labels)}]</b><br><br>"
)

for container, pull_requests in self.blocked_pr.items():
if not pull_requests:
continue
self.blocked_body.append(f"{container}:")
self.blocked_body.append(f"<b>{container}<b>:")
self.blocked_body.append("<table><tr><th>Pull request URL</th><th>Title</th><th>Missing labels</th></tr>")
for pr in pull_requests:
blocked_labels = self.get_blocked_labels(pr["pr_dict"])
self.blocked_body.append(
f"https://github.com/sclorg/{container}/pull/{pr['number']} - "
f"[{pr['pr_dict']['title']}] -> {' '.join(blocked_labels)}"
f"<tr><td>https://github.com/sclorg/{container}/pull/{pr['number']}</td>"
f"<td>{pr['pr_dict']['title']}</td><td><p style='color:red;'>{' '.join(blocked_labels)}</p></td></tr>"
)
self.blocked_body.extend([""])
self.blocked_body.extend(["", ""])
self.blocked_body.append("</table><br><br>")
print('\n'.join(self.blocked_body))

def print_approval_pull_request(self):
# Do not print anything in case we do not have PR.
if not [x for x in self.pr_to_merge if self.pr_to_merge[x]]:
return 0
self.approval_body.append(f"Pull requests that can be merged or missing {self.approvals} approvals")
self.approval_body.append("<table><tr><th>Pull request URL</th><th>Title</th><th>Approval status</th></tr>")
for container, pr in self.pr_to_merge.items():
if not pr:
continue
if int(pr["approvals"]) >= self.approvals:
result_pr = f" -> CAN BE MERGED"
result_pr = f"CAN BE MERGED"
else:
result_pr = f" -> Missing {self.approvals-int(pr['approvals'])} APPROVAL"
result_pr = f"Missing {self.approvals-int(pr['approvals'])} APPROVAL"
self.approval_body.append(
f"https://github.com/sclorg/{container}/pull/{pr['number']} - "
f"[{pr['pr_dict']['title']}]{result_pr}"
f"<tr><td>https://github.com/sclorg/{container}/pull/{pr['number']}</td>"
f"<td>{pr['pr_dict']['title']}</td><td><p style='color:red;'>{result_pr}</p></td></tr>"
)
self.approval_body.extend(["", ""])
self.approval_body.append("</table><br>")
print('\n'.join(self.approval_body))

def send_results(self, recipients):
Expand Down

0 comments on commit 924e8ac

Please sign in to comment.