Skip to content

Commit 6e901e5

Browse files
#149 - Merge labels from PR and the connected issue (#159)
* #149 - Merge labels from PR and the connected issue - Labels are now holded on record itself as set of strings.
1 parent eda69f4 commit 6e901e5

File tree

11 files changed

+133
-106
lines changed

11 files changed

+133
-106
lines changed

DEVELOPER.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ Pylint displays a global evaluation score for the code, rated out of a maximum s
3131

3232
### Set Up Python Environment
3333
```shell
34-
python3 -m venv venv
35-
source venv/bin/activate
34+
python3 -m venv .venv
35+
source .venv/bin/activate
36+
pip install --upgrade pip
3637
pip install -r requirements.txt
3738
```
3839

main.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
from release_notes_generator.action_inputs import ActionInputs
3232
from release_notes_generator.utils.gh_action import set_action_output
3333
from release_notes_generator.utils.logging_config import setup_logging
34-
from release_notes_generator.filter import FilterByRelease
3534

3635
warnings.filterwarnings("ignore", category=InsecureRequestWarning)
3736

release_notes_generator/model/commit_record.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ def is_closed(self) -> bool:
3535
def is_open(self) -> bool:
3636
return False
3737

38-
@property
39-
def labels(self):
40-
return []
41-
4238
@property
4339
def authors(self) -> list[str]:
4440
return [self._commit.author.login] if self._commit.author else []

release_notes_generator/model/issue_record.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ def __init__(self, issue: Issue, skip: bool = False):
2727
super().__init__(skip=skip)
2828

2929
self._issue: Issue = issue
30+
self._labels = {label.name for label in self._issue.get_labels()}
31+
3032
self._pull_requests: dict[int, PullRequest] = {}
3133
self._commits: dict[int, dict[str, Commit]] = {}
3234

@@ -44,10 +46,6 @@ def is_closed(self) -> bool:
4446
def is_open(self) -> bool:
4547
return self._issue.state == self.ISSUE_STATE_OPEN
4648

47-
@property
48-
def labels(self):
49-
return [label.name for label in self._issue.labels]
50-
5149
@property
5250
def authors(self) -> list[str]:
5351
if not self._issue or not self._issue.user:
@@ -161,6 +159,7 @@ def register_pull_request(self, pull: PullRequest) -> None:
161159
Returns: None
162160
"""
163161
self._pull_requests[pull.number] = pull
162+
self._labels.update({label.name for label in pull.get_labels()})
164163

165164
def register_commit(self, pull: PullRequest, commit: Commit) -> None:
166165
"""

release_notes_generator/model/pull_request_record.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ def __init__(self, pull: PullRequest, skip: bool = False):
2525
super().__init__(skip=skip)
2626

2727
self._pull_request: PullRequest = pull
28+
self._labels = {label.name for label in self._pull_request.get_labels()}
29+
2830
self._commits: dict[str, Commit] = {}
2931

3032
# properties - override Record properties
@@ -45,10 +47,6 @@ def is_closed(self) -> bool:
4547
def is_open(self) -> bool:
4648
return self._pull_request.state == self.PR_STATE_OPEN
4749

48-
@property
49-
def labels(self):
50-
return [label.name for label in self._pull_request.labels]
51-
5250
@property
5351
def authors(self) -> list[str]:
5452
if not self._pull_request or not self._pull_request.user:
@@ -242,7 +240,8 @@ def _get_rls_notes_code_rabbit(
242240
Parameters:
243241
pull (PullRequest): The pull request from which to extract release notes.
244242
line_marks (list[str]): A list of characters that indicate the start of a release notes section.
245-
cr_detection_regex (re.Pattern[str]): A regex pattern to detect the start of the Code Rabbit release notes section.
243+
cr_detection_regex (re.Pattern[str]): A regex pattern to detect the start of the Code Rabbit release notes
244+
section.
246245
Returns:
247246
str: The extracted release notes as a string. If no release notes are found, returns an empty string.
248247
"""

release_notes_generator/model/record.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def __init__(self, skip: bool = False):
3838
self._present_in_chapters = 0
3939
self._skip = skip
4040
self._is_release_note_detected: Optional[bool] = None
41+
self._labels: set[str] = set()
4142
self._rls_notes: Optional[str] = None # single annotation here
4243

4344
# properties
@@ -55,6 +56,15 @@ def skip(self) -> bool:
5556
"""Check if the record should be skipped during output generation process."""
5657
return self._skip
5758

59+
@property
60+
def labels(self) -> list[str]:
61+
"""
62+
Gets the labels of the record.
63+
Returns:
64+
list[str]: A list of labels associated with the record.
65+
"""
66+
return list(self._labels)
67+
5868
@property
5969
@abstractmethod
6070
def record_id(self) -> int | str:
@@ -82,15 +92,6 @@ def is_open(self) -> bool:
8292
bool: True if the record is open, False otherwise.
8393
"""
8494

85-
@property
86-
@abstractmethod
87-
def labels(self) -> list[str]:
88-
"""
89-
Gets the labels of the record.
90-
Returns:
91-
list[str]: A list of labels associated with the record.
92-
"""
93-
9495
@property
9596
@abstractmethod
9697
def authors(self) -> list[str]:

release_notes_generator/record/record_factory.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ def generate(github: Github, data: MinedData) -> dict[int | str, Record]:
5858

5959
def register_pull_request(pull: PullRequest, skip_rec: bool) -> None:
6060
detected_issues = extract_issue_numbers_from_body(pull)
61-
logger.debug(f"Detected issues - from body: {detected_issues}")
61+
logger.debug("Detected issues - from body: %s", detected_issues)
6262
detected_issues.update(safe_call(get_issues_for_pr)(pull_number=pull.number))
63-
logger.debug(f"Detected issues - final: {detected_issues}")
63+
logger.debug("Detected issues - final: %s", detected_issues)
6464

6565
for parent_issue_number in detected_issues:
6666
# create an issue record if not present for PR parent
@@ -98,14 +98,14 @@ def register_pull_request(pull: PullRequest, skip_rec: bool) -> None:
9898

9999
logger.debug("Registering pull requests to records...")
100100
for pull in data.pull_requests:
101-
pull_labels = [label.name for label in pull.labels]
101+
pull_labels = [label.name for label in pull.get_labels()]
102102
skip_record: bool = any(item in pull_labels for item in ActionInputs.get_skip_release_notes_labels())
103103

104104
if not safe_call(get_issues_for_pr)(pull_number=pull.number) and not extract_issue_numbers_from_body(pull):
105105
records[pull.number] = PullRequestRecord(pull, skip=skip_record)
106106
logger.debug("Created record for PR %d: %s", pull.number, pull.title)
107107
else:
108-
logger.debug(f"Registering pull number: {pull.number}, title : {pull.title}")
108+
logger.debug("Registering pull number: %s, title : %s", pull.number, pull.title)
109109
register_pull_request(pull, skip_record)
110110

111111
logger.debug("Registering commits to records...")
@@ -158,7 +158,7 @@ def _create_record_for_issue(records: dict[int | str, Record], i: Issue) -> None
158158
@return: None
159159
"""
160160
# check for skip labels presence and skip when detected
161-
issue_labels = [label.name for label in i.labels]
161+
issue_labels = [label.name for label in i.get_labels()]
162162
skip_record = any(item in issue_labels for item in ActionInputs.get_skip_release_notes_labels())
163163
records[i.number] = IssueRecord(issue=i, skip=skip_record)
164164

requirements.txt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
pytest==7.4.3
2-
pytest-cov==5.0.0
3-
pytest-mock==3.14.0
1+
pytest==8.4.2
2+
pytest-cov==6.3.0
3+
pytest-mock==3.15.0
44
PyGithub==1.59.0
5-
pylint==3.2.6
6-
requests==2.31.0
7-
black==24.8.0
5+
pylint==3.3.8
6+
requests==2.32.5
7+
black==25.1.0
88
PyYAML==6.0.2
9-
semver==3.0.2
10-
mypy==1.15.0
11-
mypy-extensions==1.0.0
12-
types-requests==2.32.0.20250328
13-
types-PyYAML==6.0.2
9+
semver==3.0.4
10+
mypy==1.17.1
11+
mypy-extensions==1.1.0
12+
types-requests==2.32.4.20250809
13+
types-PyYAML==6.0.12.20250822

0 commit comments

Comments
 (0)