Skip to content

Commit

Permalink
Cleanup code
Browse files Browse the repository at this point in the history
  • Loading branch information
lagru committed Jan 9, 2024
1 parent d22a760 commit d846fb1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
35 changes: 18 additions & 17 deletions src/changelist/_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,14 @@ def from_pull_requests(
matches := tuple(pr_summary_regex.finditer(pr.body))
):
logger.debug("falling back to title for %s", pr.html_url)
notes.add(
cls(
content=pr.title.strip(),
reference_name=f"#{pr.number}",
reference_url=pr.html_url,
labels=pr_labels,
timestamp=pr.merged_at,
)
note = cls(
content=pr.title.strip(),
reference_name=f"#{pr.number}",
reference_url=pr.html_url,
labels=pr_labels,
timestamp=pr.merged_at,
)
notes.add(note)
continue

assert len(matches) >= 1
Expand All @@ -70,21 +69,23 @@ def from_pull_requests(
labels = tuple(
label.strip() for label in label_match["label"].split(",")
)
# Remove label block
summary = pr_summary_label_regex.sub("", summary)
else:
logger.debug(
"falling back to PR labels for summary in %s", pr.html_url
"falling back to PR labels for summary '%r' in %s",
summary,
pr.html_url,
)
labels = pr_labels
notes.add(
cls(
content=summary.strip(),
reference_name=f"#{pr.number}",
reference_url=pr.html_url,
labels=labels,
timestamp=pr.merged_at,
)
note = cls(
content=summary.strip(),
reference_name=f"#{pr.number}",
reference_url=pr.html_url,
labels=labels,
timestamp=pr.merged_at,
)
notes.add(note)
return notes


Expand Down
4 changes: 4 additions & 0 deletions test/test_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@

@dataclass
class _MockLabel:
"""Mocks github.Label.Label partially."""

name: str


@dataclass
class _MockPullRequest:
"""Mocks github.PullRequest.PullRequest partially."""

title: str
body: Union[str, None]
labels: list[_MockLabel]
Expand Down

0 comments on commit d846fb1

Please sign in to comment.