Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion release_notes_generator/model/commit_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def commit(self) -> Commit:
# methods - override Record methods

def to_chapter_row(self) -> str:
self.added_into_chapters()
super().to_chapter_row()
row_prefix = f"{ActionInputs.get_duplicity_icon()} " if self.present_in_chapters() > 1 else ""

# collecting values for formatting
Expand Down
20 changes: 14 additions & 6 deletions release_notes_generator/model/issue_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def issue_type(self) -> Optional[str]:
# methods - override Record methods

def to_chapter_row(self) -> str:
self.added_into_chapters()
super().to_chapter_row()
row_prefix = f"{ActionInputs.get_duplicity_icon()} " if self.present_in_chapters() > 1 else ""
format_values: dict[str, Any] = {}

Expand Down Expand Up @@ -115,6 +115,10 @@ def get_rls_notes(self, line_marks: Optional[list[str]] = None) -> str:
# Code Rabbit detection regex
cr_active: bool = ActionInputs.is_coderabbit_support_active()

# Get release notes from Issue
if self._issue.body and detection_regex.search(self._issue.body):
release_notes += self._get_rls_notes_default(self._issue, line_marks, detection_regex)

# Iterate over all PRs
for pull in self._pull_requests.values():
if pull.body and detection_regex.search(pull.body):
Expand Down Expand Up @@ -213,21 +217,25 @@ def get_pr_links(self) -> list[str]:

return res

def _get_rls_notes_default(self, pull: PullRequest, line_marks: list[str], detection_regex: re.Pattern[str]) -> str:
def _get_rls_notes_default(
self, record: Issue | PullRequest, line_marks: list[str], detection_regex: re.Pattern[str]
) -> str:
"""
Extracts release notes from the pull request body based on the provided line marks and detection regex.
Parameters:
pull (PullRequest): The pull request from which to extract release notes.
record (Issue or PullRequest): The issue or pull request from which to extract release notes.
line_marks (list[str]): A list of characters that indicate the start of a release notes section.
detection_regex (re.Pattern[str]): A regex pattern to detect the start of the release notes section.
Returns:
str: The extracted release notes as a string. If no release notes are found, returns an empty string.
"""
# TODO - this code will be changes soon, there is wish from project to manage different release notes
if not pull.body:
return ""
match record.body:
case None | "":
return ""
case str() as body:
lines = body.splitlines()

lines = pull.body.splitlines()
release_notes_lines = []

found_section = False
Expand Down
2 changes: 1 addition & 1 deletion release_notes_generator/model/pull_request_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def contributors(self) -> list[str]:
# methods - override Record methods

def to_chapter_row(self) -> str:
self.added_into_chapters()
super().to_chapter_row()
row_prefix = f"{ActionInputs.get_duplicity_icon()} " if self.present_in_chapters() > 1 else ""
format_values: dict[str, Any] = {}

Expand Down
8 changes: 5 additions & 3 deletions release_notes_generator/model/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,16 @@ def authors(self) -> list[str]:
list[str]: A list of authors associated with the record.
"""

# abstract methods

@abstractmethod
# to be overridden by subclasses and called via super() as the first line
def to_chapter_row(self) -> str:
"""
Converts the record to a string row in a chapter.
@return: The record as a row string.
"""
self.added_into_chapters()
return ""

# abstract methods

@abstractmethod
def get_rls_notes(self, line_marks: Optional[list[str]] = None) -> str:
Expand Down
2 changes: 1 addition & 1 deletion release_notes_generator/utils/github_rate_limiter.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import logging
import time
from datetime import datetime
from typing import Optional, Callable, Any, cast
from typing import Optional, Callable, Any
from github import Github

logger = logging.getLogger(__name__)
Expand Down
4 changes: 4 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ def mock_issue_open(mocker):
issue.number = 122
issue.title = "I1 open"
issue.state_reason = None
issue.body = "I1 open"

label1 = mocker.Mock(spec=MockLabel)
label1.name = "label1"
Expand All @@ -146,6 +147,7 @@ def mock_issue_open_2(mocker):
issue.number = 123
issue.title = "I2 open"
issue.state_reason = None
issue.body = "I2 open"

label1 = mocker.Mock(spec=MockLabel)
label1.name = "label1"
Expand All @@ -162,6 +164,7 @@ def mock_issue_closed(mocker):
issue.state = IssueRecord.ISSUE_STATE_CLOSED
issue.title = "Fix the bug"
issue.number = 121
issue.body = "Some issue body text"

label1 = mocker.Mock(spec=MockLabel)
label1.name = "label1"
Expand All @@ -178,6 +181,7 @@ def mock_issue_closed_i1_bug(mocker):
issue.state = IssueRecord.ISSUE_STATE_CLOSED
issue.title = "I1+bug"
issue.number = 122
issue.body = "Some issue body text\nRelease Notes:\n- Fixed bug\n- Improved performance\n+ More nice code\n * Awesome architecture"

label1 = mocker.Mock(spec=MockLabel)
label1.name = "label1"
Expand Down
16 changes: 16 additions & 0 deletions tests/release_notes/test_release_notes_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ def __init__(self, name):

RELEASE_NOTES_DATA_CUSTOM_CHAPTERS_ONE_LABEL = """### Chapter 1 🛠
- #122 _I1+bug_ in #101, #102
- Fixed bug
- Improved performance
+ More nice code
* Awesome architecture
- PR 101 1st release note
- PR 101 2nd release note
- PR 102 1st release note
Expand All @@ -151,6 +155,10 @@ def __init__(self, name):

RELEASE_NOTES_DATA_CUSTOM_CHAPTERS_MORE_LABELS_DUPLICITY_REDUCTION_ON = """### Chapter 1 🛠
- #122 _I1+bug-enhancement_ in #101, #102
- Fixed bug
- Improved performance
+ More nice code
* Awesome architecture
- PR 101 1st release note
- PR 101 2nd release note
- PR 102 1st release note
Expand Down Expand Up @@ -237,6 +245,10 @@ def __init__(self, name):

RELEASE_NOTES_DATA_CLOSED_ISSUE_WITH_PR_WITHOUT_USER_LABELS = """### Closed Issues without User Defined Labels ⚠️
- #122 _I1_ in #101, #102
- Fixed bug
- Improved performance
+ More nice code
* Awesome architecture
- PR 101 1st release note
- PR 101 2nd release note
- PR 102 1st release note
Expand Down Expand Up @@ -293,6 +305,10 @@ def __init__(self, name):
- #122 _I1+bug_ in #123
- Fixed bug
- Improved performance
+ More nice code
* Awesome architecture
- Fixed bug
- Improved performance

#### Full Changelog
http://example.com/changelog
Expand Down
Loading