Skip to content

Commit 3ae9e13

Browse files
committed
pre-commit fix
1 parent 0a53b76 commit 3ae9e13

File tree

12 files changed

+119
-70
lines changed

12 files changed

+119
-70
lines changed

.github/workflows/bug_triager_workflow.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ jobs:
3131
MAINTAINERS: ${{ secrets.MAINTAINERS }}
3232
REPO_CONFIG: ${{ secrets.REPO_CONFIG }}
3333
run: |
34-
python -m triager --bugs -c example-config.yaml --log --send-email
34+
python -m triager --bugs -c config.yaml --log --send-email

.github/workflows/ci_workflow.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ jobs:
3131
MAINTAINERS: ${{ secrets.MAINTAINERS }}
3232
REPO_CONFIG: ${{ secrets.REPO_CONFIG }}
3333
run: |
34-
python -m triager --ci -c example-config.yaml --log --send-email
34+
python -m triager --ci -c config.yaml --log --send-email

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
*.code-workspace
44
__pycache__/
55
*.egg-info
6-
.env
6+
.env
7+
.flake8

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,4 +671,4 @@ into proprietary programs. If your program is a subroutine library, you
671671
may consider it more useful to permit linking proprietary applications with
672672
the library. If this is what you want to do, use the GNU Lesser General
673673
Public License instead of this License. But first, please read
674-
<https://www.gnu.org/licenses/why-not-lgpl.html>.
674+
<https://www.gnu.org/licenses/why-not-lgpl.html>.

example-config.yaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
##Template for config.yaml
1+
# #Template for config.yaml
22

3-
#Organization name (used in email subject)
4-
organization_name: "Ansible Networking"
3+
# #Organization name (used in email subject)
4+
# organization_name: "Ansible Networking"
55

6-
#Workflow name
7-
workflow_name: "tests.yml"
6+
# #Workflow name
7+
# workflow_name: "tests.yml"
88

9-
#Time delta (in days) for triaging issues
10-
timedelta: 14
9+
# #Time delta (in days) for triaging issues
10+
# timedelta: 14
1111
##Template for adding repos in Github secrets or .env file(for running locally)
1212

1313
# REPO_CONFIG= {

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
ptable
22
PyYAML
33
requests
4-
python-dotenv
4+
python-dotenv

triager/__main__.py

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
import argparse
22
import logging
33
from datetime import datetime
4-
import os
4+
55
from dotenv import load_dotenv
66

77
from triager import triager
8+
from triager.ci_report import generate_ci_report
89
from triager.config import Config
910
from triager.mailer import send_mail
1011
from triager.release import __ver__
1112
from triager.tablemaker import make_table
12-
from triager.ci_report import generate_ci_report
13+
1314

1415
def run(args):
1516
logging_level = logging.DEBUG if args.debug else logging.INFO
16-
logging.basicConfig(level=logging_level, format='%(levelname)-10s%(message)s')
17+
logging.basicConfig(
18+
level=logging_level,
19+
format="%(levelname)-10s%(message)s",
20+
)
1721

1822
load_dotenv()
1923

@@ -27,30 +31,48 @@ def run(args):
2731
table = make_table(issues)
2832
print(table)
2933
if args.send_email and config.is_email_ready:
30-
send_mail(content=table, config=config, subject=f"{config.organization_name} Weekly Triage - {report_date}")
34+
subject = (
35+
f"{config.organization_name} Weekly Triage - " f"{report_date}"
36+
)
37+
send_mail(content=table, config=config, subject=subject)
3138
else:
3239
message = "No new issues found or error occurred during triage."
3340
print(message)
3441
if args.send_email and config.is_email_ready:
35-
send_mail(content=message, config=config, subject=f"{config.organization_name} Weekly Triage - No New Issues - {report_date}")
42+
subject = (
43+
f"{config.organization_name} Weekly Triage - "
44+
f"No New Issues - {report_date}"
45+
)
46+
send_mail(content=message, config=config, subject=subject)
3647
elif args.ci:
3748
ci_report = generate_ci_report(config)
3849
if ci_report:
3950
table = make_table(ci_report, ci=True)
4051
print(table)
41-
report_date = ci_report.get("date", datetime.now().strftime("%Y-%m-%d"))
52+
report_date = ci_report.get(
53+
"date",
54+
datetime.now().strftime("%Y-%m-%d"),
55+
)
4256
status = ci_report.get("overall_status", "Unknown")
4357
if args.send_email and config.is_email_ready:
44-
send_mail(content=table, config=config, subject=f"{config.organization_name} Nightly CI Report - {report_date} - {status}")
58+
subject = (
59+
f"{config.organization_name} Nightly CI Report - "
60+
f"{report_date} - {status}"
61+
)
62+
send_mail(content=table, config=config, subject=subject)
4563
else:
46-
logging.warning("No CI report generated or error occurred during CI report generation.")
64+
logging.warning(
65+
"No CI report generated or error occurred during CI report "
66+
"generation.",
67+
)
4768
except Exception as e:
4869
logging.error(f"An error occurred: {str(e)}", exc_info=True)
4970
raise
5071

72+
5173
def main():
5274
parser = argparse.ArgumentParser(
53-
description="Triage issues and pull-requests from repositories of interest.",
75+
description=("Triage issues and pull-requests from repositories of interest."),
5476
prog="Ansible Network Triager",
5577
)
5678
parser.add_argument(
@@ -65,32 +87,32 @@ def main():
6587
group.add_argument(
6688
"--bugs",
6789
action="store_true",
68-
help="Generate a bug scrub report"
90+
help="Generate a bug scrub report",
6991
)
7092
group.add_argument(
7193
"--ci",
7294
action="store_true",
73-
help="Generate a CI report"
95+
help="Generate a CI report",
7496
)
7597
parser.add_argument(
7698
"--log-to-file",
7799
nargs="?",
78100
const="/tmp/triager-{0}.log".format(
79-
datetime.now().strftime("%Y-%m-%d-%X")
101+
datetime.now().strftime("%Y-%m-%d-%X"),
80102
),
81103
dest="log_to_file",
82104
help="save logging information to a file",
83105
)
84106
parser.add_argument(
85107
"--log",
86108
action="store_true",
87-
help="display logging data on console"
109+
help="display logging data on console",
88110
)
89111

90112
parser.add_argument(
91113
"--debug",
92114
action="store_true",
93-
help="Bump logging level to debug"
115+
help="Bump logging level to debug",
94116
)
95117

96118
parser.add_argument(
@@ -102,7 +124,7 @@ def main():
102124
parser.add_argument(
103125
"--version",
104126
action="store_true",
105-
help="show version number"
127+
help="show version number",
106128
)
107129

108130
args = parser.parse_args()

triager/ci_report.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
11
import logging
2-
import smtplib
32
import textwrap
43
from datetime import date
5-
from email.headerregistry import Address
6-
from email.message import EmailMessage
74

8-
import prettytable
95
import requests
106

117
WRAPPER = textwrap.TextWrapper(width=120)
128
REQUEST_FMT = "https://api.github.com/repos/{0}/actions/workflows/{1}/runs"
139

10+
1411
def generate_ci_report(config):
1512
data = []
1613
overall_status = "Success"
1714
workflow = config.workflow_name
18-
15+
1916
for repo in config.ci_repos:
20-
repo_name = repo['name'] if isinstance(repo, dict) else repo
17+
repo_name = repo["name"] if isinstance(repo, dict) else repo
2118
try:
2219
resp = requests.get(
2320
REQUEST_FMT.format(repo_name, workflow),
@@ -32,21 +29,30 @@ def generate_ci_report(config):
3229
logging.error("API rate limiting or authentication issues.")
3330
logging.debug(f"Response content: {resp.content}")
3431
continue
35-
32+
3633
resp_json = resp.json()
3734
if not resp_json["workflow_runs"]:
3835
logging.warning(f"No workflow runs found for {repo_name}")
3936
continue
40-
37+
4138
latest_run = resp_json["workflow_runs"][0]
4239
status = latest_run["conclusion"]
40+
41+
if status is None:
42+
logging.info(f"Workflow for {repo_name} is still in progress")
43+
continue
44+
4345
if status != "success":
4446
overall_status = "Failure"
45-
46-
temp = {"repo": repo_name, "status": status, "url": latest_run["html_url"]}
47+
48+
temp = {
49+
"repo": repo_name,
50+
"status": status,
51+
"url": latest_run["html_url"],
52+
}
4753
logging.info(f"CI data fetched for {repo_name}: {status}")
4854
data.append(temp)
49-
55+
5056
return {
5157
"data": data,
5258
"overall_status": overall_status,

triager/config.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,7 @@ def _set_repo_config(self):
9191
logging.debug(f"Bug repos: {self.bug_repos}")
9292
logging.debug(f"CI repos: {self.ci_repos}")
9393

94-
# Parse maintainers
95-
94+
# Parse maintainers
9695
def _set_maintainers(self):
9796
maintainers_json = os.environ.get("MAINTAINERS", "[]")
9897
logging.debug(f"MAINTAINERS env var: {maintainers_json}")
@@ -108,8 +107,7 @@ def _set_maintainers(self):
108107

109108
logging.debug(f"Maintainers: {self.maintainers}")
110109

111-
# Parse email configuration
112-
110+
# Parse email configuration
113111
def _set_email_config(self):
114112
self.sender = {
115113
"email": os.environ.get("EMAIL_SENDER"),
@@ -119,10 +117,11 @@ def _set_email_config(self):
119117
if self.sender["email"] and self.sender["password"]:
120118
logging.info("Email configuration found in environment variables")
121119
else:
122-
logging.warning("Email configuration not found in environment variables")
123-
124-
# Set last triage date
120+
logging.warning(
121+
"Email configuration not found in environment variables",
122+
)
125123

124+
# Set last triage date
126125
def _set_last_triage_date(self):
127126
self.last_triage_date = datetime.utcnow() - timedelta(
128127
days=int(self.config_data.get("timedelta", 14)),
@@ -147,5 +146,5 @@ def token(self):
147146
@property
148147
def is_email_ready(self):
149148
return bool(
150-
self.sender["email"] and self.sender["password"] and self.maintainers
149+
self.sender["email"] and self.sender["password"] and self.maintainers,
151150
)

triager/mailer.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
import smtplib
33
from datetime import date
44
from email.message import EmailMessage
5+
56
from triager.ci_report import generate_ci_report
67

8+
79
def send_mail(content, config, subject):
8-
logging.info("attempting to send email to maintainers")
10+
logging.info("attempting to send email to maintainers")
911
msg = EmailMessage()
1012
msg["From"] = config.sender["email"]
1113
msg["To"] = [str(maintainer) for maintainer in config.maintainers]
@@ -14,11 +16,11 @@ def send_mail(content, config, subject):
1416
msg.set_content(str(content))
1517
msg.add_alternative(
1618
content.get_html_string(
17-
attributes={"border": "1", "style": "text-align:center"}
19+
attributes={"border": "1", "style": "text-align:center"},
1820
),
1921
subtype="html",
2022
)
21-
23+
2224
try:
2325
with smtplib.SMTP("smtp.gmail.com", 587) as smtp:
2426
logging.info("attempting to send email")
@@ -29,14 +31,19 @@ def send_mail(content, config, subject):
2931
except Exception as e:
3032
logging.error(f"Failed to send email: {str(e)}")
3133

34+
3235
def send_bug_report(content, config):
33-
subject = f"{config.organization_name} Weekly Triage - Bug Report - {date.today().isoformat()}"
36+
subject = (
37+
f"{config.organization_name} Weekly Triage - "
38+
f"Bug Report - {date.today().isoformat()}"
39+
)
3440
send_mail(content, config, subject)
3541

42+
3643
def send_ci_report(content, config):
3744
ci_report = generate_ci_report(config)
3845
status = ci_report.get("overall_status", "Unknown")
3946
report_date = ci_report.get("date", date.today().isoformat())
40-
47+
4148
subject = f"{config.organization_name} Nightly CI Report - {report_date} - {status}"
42-
send_mail(content, config, subject)
49+
send_mail(content, config, subject)

0 commit comments

Comments
 (0)