Skip to content

Commit 2e83b20

Browse files
committed
Add pylint disable comments to changelog CI check
1 parent eb61ae0 commit 2e83b20

File tree

2 files changed

+81
-1
lines changed

2 files changed

+81
-1
lines changed

.github/workflows/changelogs/changelogs.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env python3
2+
# pylint: disable=missing-module-docstring
23

34
import logging
45
import argparse
@@ -39,11 +40,14 @@ def __init__(self, tracker_filename: str = None):
3940
trackers = {}
4041
if tracker_filename:
4142
try:
43+
# pylint: disable-next=logging-fstring-interpolation
4244
logging.info(f"Parsing tracker file: {tracker_filename}")
4345
tree = ET.parse(tracker_filename)
4446
except FileNotFoundError as e:
47+
# pylint: disable-next=raise-missing-from,broad-exception-raised
4548
raise Exception(f"{e.strerror}: '{e.filename}'")
4649
except ET.ParseError as e:
50+
# pylint: disable-next=raise-missing-from,broad-exception-raised
4751
raise Exception(f"Error parsing '{tracker_filename}': {e.msg}")
4852

4953
for tracker in tree.getroot():
@@ -53,11 +57,13 @@ def __init__(self, tracker_filename: str = None):
5357
name = tracker.find("name").text
5458
regex = tracker.find("regex").text
5559
except AttributeError:
60+
# pylint: disable-next=raise-missing-from,broad-exception-raised
5661
raise Exception(
5762
f"Error parsing '{tracker_filename}': not a tracker XML file"
5863
)
5964
trackers[name] = regex
6065

66+
# pylint: disable-next=logging-fstring-interpolation
6167
logging.info(f"Found {len(trackers.keys())} tracker definition(s)")
6268

6369
self.trackers = trackers
@@ -145,10 +151,13 @@ def get_message_header(self) -> str:
145151
if os.getenv("GITHUB_ACTION"):
146152
msg = "::error" if self.severe else "::warning"
147153
if self.file:
154+
# pylint: disable-next=consider-using-f-string
148155
msg += " file={}".format(self.file)
149156
if self.line:
157+
# pylint: disable-next=consider-using-f-string
150158
msg += ",line={}".format(self.line)
151159
if self.end_line:
160+
# pylint: disable-next=consider-using-f-string
152161
msg += ",endLine={}".format(self.end_line)
153162

154163
return msg + "::"
@@ -214,6 +223,7 @@ def __init__(
214223
regex_rules: RegexRules,
215224
):
216225
if pr_number and not os.getenv("GH_TOKEN"):
226+
# pylint: disable-next=broad-exception-raised
217227
raise Exception(
218228
"GitHub API key not set. Please set it in 'GH_TOKEN' environment variable."
219229
)
@@ -239,14 +249,18 @@ def get_bugzilla_api(self) -> bugzilla.Bugzilla:
239249

240250
uri = os.getenv("BUGZILLA_URI", DEFAULT_BUGZILLA_URI)
241251
try:
252+
# pylint: disable-next=logging-fstring-interpolation
242253
logging.info(f"Initializing Bugzilla API at '{uri}'")
243254
bzapi = bugzilla.Bugzilla(uri, api_key=api_key)
255+
# pylint: disable-next=unused-variable
244256
except requests.exceptions.ConnectionError as e:
257+
# pylint: disable-next=raise-missing-from
245258
raise ConnectionError(f"Cannot connect to the Bugzilla API at '{uri}'")
246259

247260
try:
248261
assert bzapi.logged_in, f"Cannot log into the Bugzilla API at '{uri}'"
249262
except xmlrpc.client.Fault as f:
263+
# pylint: disable-next=raise-missing-from,broad-exception-raised
250264
raise Exception(
251265
f"Cannot log in to the Bugzilla API at '{uri}': {f.faultString}"
252266
)
@@ -277,12 +291,16 @@ def get_modified_files_for_pkg(
277291
pkg_files.append(f)
278292

279293
if logging.getLogger().isEnabledFor(logging.DEBUG):
294+
# pylint: disable-next=use-implicit-booleaness-not-len
280295
if len(pkg_files):
296+
# pylint: disable-next=logging-not-lazy
281297
logging.debug(
282298
f"Found {len(pkg_files)} file(s) in package {pkg_name}:\n "
283299
+ "\n ".join(pkg_files)
284300
)
301+
# pylint: disable-next=use-implicit-booleaness-not-len
285302
if len(pkg_chlogs):
303+
# pylint: disable-next=logging-not-lazy
286304
logging.debug(
287305
f"Found {len(pkg_chlogs)} changelog(s) in package {pkg_name}:\n "
288306
+ "\n ".join(pkg_chlogs)
@@ -312,8 +330,10 @@ def get_pkg_index(self, files: list[str]) -> dict[str, list[str]]:
312330

313331
try:
314332
pkg_names = os.listdir(packages_dir)
333+
# pylint: disable-next=logging-fstring-interpolation
315334
logging.debug(f"Found {len(pkg_names)} package(s) in 'rel-eng/packages'")
316335
except FileNotFoundError:
336+
# pylint: disable-next=raise-missing-from,broad-exception-raised
317337
raise Exception(
318338
"Not an Uyuni repository. Consider using '--uyuni-dir' option."
319339
)
@@ -330,6 +350,7 @@ def get_pkg_index(self, files: list[str]) -> dict[str, list[str]]:
330350
.rstrip()
331351
.split(maxsplit=1)[1]
332352
)
353+
# pylint: disable-next=logging-fstring-interpolation
333354
logging.debug(f"Indexing package {pkg_name} in path {pkg_path}")
334355

335356
# Get the list of modified files and changelog files for the package
@@ -375,6 +396,7 @@ def get_pr_trackers(
375396
assert pr_number
376397
assert git_repo
377398

399+
# pylint: disable-next=logging-fstring-interpolation
378400
logging.info(f"Requesting information for PR#{pr_number} at '{git_repo}'")
379401

380402
pr_path = f"repos/{git_repo}/pulls/{pr_number}"
@@ -383,10 +405,12 @@ def get_pr_trackers(
383405
)
384406
title_and_commits = stream.read()
385407
if stream.close():
408+
# pylint: disable-next=broad-exception-raised
386409
raise Exception(
387410
"An error occurred when getting the PR information from the GitHub API."
388411
)
389412

413+
# pylint: disable-next=logging-fstring-interpolation
390414
logging.debug(
391415
f"Retrieved title and commit messages for PR#{pr_number}:\n{title_and_commits}"
392416
)
@@ -409,6 +433,7 @@ def validate_chlog_entry(
409433
# Test spacing (ignored in version strings)
410434
# Test to check if a match overlaps with a version string
411435
overlaps = (
436+
# pylint: disable-next=unnecessary-lambda-assignment
412437
lambda ver_str, match: ver_str.start() <= match.start()
413438
and ver_str.end() >= match.end()
414439
)
@@ -455,12 +480,14 @@ def get_entry_obj(self, buffer: list[str], file: str, line_no: int) -> Entry:
455480
def validate_chlog_file(self, file: str) -> tuple[list[Issue], list[Entry]]:
456481
"""Validate a single changelog file"""
457482

483+
# pylint: disable-next=logging-fstring-interpolation
458484
logging.debug(f"Validating changelog file: {file}")
459485
file_path = os.path.join(self.uyuni_root, file)
460486

461487
if os.path.getsize(file_path) == 0:
462488
return ([Issue(IssueType.EMPTY_CHLOG, file)], [])
463489

490+
# pylint: disable-next=unspecified-encoding
464491
f = open(file_path, "r")
465492
issues = []
466493
entries = []
@@ -520,6 +547,7 @@ def validate_chlog_file(self, file: str) -> tuple[list[Issue], list[Entry]]:
520547
# EOF
521548
if entry_buf:
522549
# Validate and append the last entry
550+
# pylint: disable-next=undefined-loop-variable
523551
entry = self.get_entry_obj(entry_buf, file, line_no + 1)
524552
issues.extend(self.validate_chlog_entry(entry, entries))
525553
entries.append(entry)
@@ -532,9 +560,11 @@ def validate_bsc(self, entry: Entry) -> list[Issue]:
532560
issues = []
533561
# 'bnc' is the name of the tracker as defined in the trackers file
534562
if "bnc" in entry.trackers:
563+
# pylint: disable-next=unused-variable
535564
for tracker, bug_id in entry.trackers["bnc"]:
536565
try:
537566
bug = self.bzapi.getbug(bug_id)
567+
# pylint: disable-next=logging-fstring-interpolation
538568
logging.debug(f"Bug #{bug_id} belongs to product '{bug.product}'")
539569

540570
if not bug.product.startswith("SUSE Manager"):
@@ -629,6 +659,7 @@ def validate_trackers(self, entries: list[Entry]) -> list[Issue]:
629659
# changelog entry are also mentioned in the PR
630660
if pr_validation:
631661
for t in trackers:
662+
# pylint: disable-next=possibly-used-before-assignment
632663
if kind not in pr_trackers or t not in pr_trackers[kind]:
633664
# Tracker not mentioned in the PR
634665
issues.append(
@@ -763,14 +794,18 @@ def main():
763794

764795
try:
765796
logging.debug("Initializing the validator")
797+
# pylint: disable-next=invalid-name
766798
regexRules = RegexRules(args.tracker_file)
767799
validator = ChangelogValidator(
768800
args.uyuni_dir, args.git_repo, args.pr_number, args.line_length, regexRules
769801
)
770802

803+
# pylint: disable-next=logging-fstring-interpolation
771804
logging.debug(f"Validating {len(args.files)} file(s)")
772805
issues = validator.validate(args.files)
806+
# pylint: disable-next=logging-fstring-interpolation
773807
logging.debug(f"Validation finished with {len(issues)} issue(s)")
808+
# pylint: disable-next=broad-exception-caught
774809
except Exception as e:
775810
print(e, file=sys.stderr)
776811
return 2
@@ -782,6 +817,7 @@ def main():
782817
return 0
783818

784819
logging.info(
820+
# pylint: disable-next=logging-format-interpolation,consider-using-f-string
785821
"Changelog test {} with {} issue(s):".format(
786822
"failed" if is_fail else "passed", len(issues)
787823
)
@@ -794,6 +830,7 @@ def main():
794830
if is_fail:
795831
print()
796832
print(
833+
# pylint: disable-next=consider-using-f-string
797834
"{}See https://github.com/uyuni-project/uyuni/wiki/Contributing for a guide to writing changelogs.".format(
798835
"::notice::" if is_gh_action else ""
799836
)

0 commit comments

Comments
 (0)