Skip to content

Commit a7b0e8c

Browse files
#162 - Introduce presence of Release Notes to Issues (#163)
- Add issue type attribute.
1 parent aa99988 commit a7b0e8c

File tree

5 files changed

+128
-2
lines changed

5 files changed

+128
-2
lines changed

DEVELOPER.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ This will execute all tests located in the tests directory.
135135
Code coverage is collected using the pytest-cov coverage tool. To run the tests and collect coverage information, use the following command:
136136

137137
```shell
138-
pytest --cov=. -v tests/ --cov-fail-under=80
138+
pytest --cov=. -v tests/ --cov-fail-under=80 # Check coverage threshold
139+
pytest --cov=. -v tests/ --cov-fail-under=80 --cov-report=html # Generate HTML report
139140
```
140141

141142
This will execute all tests in the tests directory and generate a code coverage report.

release_notes_generator/model/issue_record.py

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

2929
self._issue: Issue = issue
30+
self._issue_type: Optional[str] = None
31+
32+
if issue is not None and issue.type is not None:
33+
self._issue_type = issue.type.name
34+
3035
self._labels = {label.name for label in self._issue.get_labels()}
3136

3237
self._pull_requests: dict[int, PullRequest] = {}
@@ -62,6 +67,15 @@ def issue(self) -> Issue:
6267
"""
6368
return self._issue
6469

70+
@property
71+
def issue_type(self) -> Optional[str]:
72+
"""
73+
Gets the type of the issue.
74+
Returns:
75+
str: The type of the issue.
76+
"""
77+
return self._issue_type
78+
6579
# methods - override Record methods
6680

6781
def to_chapter_row(self) -> str:
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#
2+
# Copyright 2023 ABSA Group Limited
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
17+
from datetime import datetime
18+
19+
from github.Issue import Issue
20+
from github.IssueType import IssueType
21+
22+
from release_notes_generator.model.issue_record import IssueRecord
23+
24+
25+
def _make_issue(mocker, type_name=None) -> Issue:
26+
27+
if type_name:
28+
mock_issue_type = mocker.Mock(spec=IssueType)
29+
mock_issue_type.name = type_name
30+
else:
31+
mock_issue_type = None
32+
33+
mock_issue = mocker.Mock(spec=Issue)
34+
mock_issue.id = 1
35+
mock_issue.number = 123
36+
mock_issue.title = "Issue 1"
37+
mock_issue.body = "Body of issue 1"
38+
mock_issue.state = "open"
39+
mock_issue.created_at = datetime.now()
40+
mock_issue.get_labels.return_value = []
41+
mock_issue.type = mock_issue_type
42+
43+
return mock_issue
44+
45+
46+
def test_issue_record_init_with_type_none(mocker):
47+
issue: Issue = _make_issue(mocker, type_name=None)
48+
record = IssueRecord(issue)
49+
assert record.issue_type is None
50+
51+
52+
def test_issue_record_init_with_type_value(mocker):
53+
issue: Issue = _make_issue(mocker, type_name="enhancement")
54+
record = IssueRecord(issue)
55+
assert record.issue_type == "enhancement"
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#
2+
# Copyright 2023 ABSA Group Limited
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
17+
import re
18+
import pytest
19+
from github.PullRequest import PullRequest
20+
21+
from release_notes_generator.model.pull_request_record import PullRequestRecord
22+
23+
# get_rls_notes
24+
25+
def test_get_rls_notes_coderabbit_ignores_groups(mocker):
26+
pr = mocker.Mock(spec=PullRequest)
27+
pr.state = PullRequestRecord.PR_STATE_CLOSED
28+
pr.number = 42
29+
pr.title = "PR with CR summary"
30+
pr.get_labels.return_value = []
31+
pr.body = (
32+
"Summary by CodeRabbit\n"
33+
"- **Improvements**\n"
34+
" - Speed up\n"
35+
"- **Fixes**\n"
36+
" - Crash fix\n"
37+
" + Minor patch\n"
38+
"Other text"
39+
)
40+
41+
rec = PullRequestRecord(pr)
42+
43+
mocker.patch("release_notes_generator.action_inputs.ActionInputs.get_release_notes_title", return_value=r"^Release Notes:$")
44+
mocker.patch("release_notes_generator.action_inputs.ActionInputs.is_coderabbit_support_active", return_value=True)
45+
mocker.patch("release_notes_generator.action_inputs.ActionInputs.get_coderabbit_release_notes_title", return_value="Summary by CodeRabbit")
46+
mocker.patch("release_notes_generator.action_inputs.ActionInputs.get_coderabbit_summary_ignore_groups", return_value=["Improvements"])
47+
48+
notes = rec.get_rls_notes()
49+
assert notes == " - Crash fix\n + Minor patch"
50+
51+
# get_commit
52+
53+
def test_get_commit_found_and_missing(pull_request_record_merged):
54+
found = pull_request_record_merged.get_commit("merge_commit_sha")
55+
missing = pull_request_record_merged.get_commit("nonexistent")
56+
assert found is not None and getattr(found, "sha", None) == "merge_commit_sha"
57+
assert missing is None

tests/release_notes/test_record_factory.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
from release_notes_generator.model.mined_data import MinedData
3030
from release_notes_generator.model.pull_request_record import PullRequestRecord
3131
from release_notes_generator.record.record_factory import RecordFactory
32-
from tests.conftest import MockLabel
3332

3433

3534
def setup_no_issues_pulls_commits(mocker):

0 commit comments

Comments
 (0)