Skip to content

Commit

Permalink
- Finished logical test coverage of possible input for release notes …
Browse files Browse the repository at this point in the history
…builder.
  • Loading branch information
miroslavpojer committed Jun 27, 2024
1 parent b4bf2e7 commit e10094a
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/github_integration/github_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def fetch_issues(self, since: datetime = None, state: str = None) -> list[Issue]

return parsed_issues

def fetch_pull_requests(self, since: datetime = None, state: str = 'all') -> list[PullRequest]:
def fetch_pull_requests(self, since: datetime = None) -> list[PullRequest]:
"""
Fetches all pull requests from the current repository.
If a 'since' datetime is provided, fetches all pull requests since that time.
Expand All @@ -159,7 +159,7 @@ def fetch_pull_requests(self, since: datetime = None, state: str = 'all') -> lis
:return: A list of PullRequest objects.
"""
logging.info(f"Fetching all closed PRs for {self.__repository.full_name}")
pulls = self.__repository.get_pulls(state=state)
pulls = self.__repository.get_pulls(state="closed")

pull_requests = []
logging.info(f"Found {len(list(pulls))} PRs for {self.__repository.full_name}")
Expand Down
3 changes: 0 additions & 3 deletions src/release_notes/model/service_chapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ def populate(self, records: dict[int, Record]):
if records[nr].is_open_issue or records[nr].is_present_in_chapters:
pass
else:
print(f"XXX 3")
self.chapters[self.OTHERS_NO_TOPIC].add_row(nr, records[nr].to_chapter_row())

def __populate_closed_issues(self, record: Record, nr: int):
Expand All @@ -101,7 +100,6 @@ def __populate_closed_issues(self, record: Record, nr: int):
self.chapters[self.CLOSED_ISSUES_WITHOUT_USER_DEFINED_LABELS].add_row(nr, record.to_chapter_row())

if not record.is_present_in_chapters:
print(f"XXX 2")
self.chapters[self.OTHERS_NO_TOPIC].add_row(nr, record.to_chapter_row())

def __populate_pr(self, record: Record, nr: int):
Expand All @@ -128,5 +126,4 @@ def __populate_pr(self, record: Record, nr: int):
self.chapters[self.CLOSED_PRS_WITHOUT_ISSUE_AND_USER_DEFINED_LABELS].add_row(nr, record.to_chapter_row())

if not record.is_present_in_chapters:
print(f"XXX 1")
self.chapters[self.OTHERS_NO_TOPIC].add_row(nr, record.to_chapter_row())
125 changes: 119 additions & 6 deletions tests/release_notes/test_release_notes_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,25 +128,56 @@ def __get_default_pull_request_mock(issue_number: Optional[int] = None, state="c


def __get_record_mock_1_issue_with_2_prs(issue_state: str = "closed", issue_labels: list[str] = None,
pr_with_rls_notes: bool = True, second_pr_merged: bool = True) -> dict[int, Record]:
# create 1 closed issue without PR
issue = __get_default_issue_mock(number=1, state=issue_state, labels=issue_labels)
pr_with_rls_notes: bool = True, second_pr_merged: bool = True,
is_closed_not_planned:bool = False) -> dict[int, Record]:
# create 1 issue
state_reason = None
if is_closed_not_planned:
state_reason = "not_planned"

issue = __get_default_issue_mock(number=1, state=issue_state, labels=issue_labels, state_reason=state_reason)

# create 2 PRs
pr1 = __get_default_pull_request_mock(issue_number=1, number=101, with_rls_notes=pr_with_rls_notes)
pr2 = __get_default_pull_request_mock(issue_number=1, number=102, with_rls_notes=pr_with_rls_notes,
is_merged=second_pr_merged)

records = {}
if issue_state == "closed":
records[0] = Record(issue)
else:
records[0] = Record() # Note: Issue in open state is not registered to record set
records[0] = Record()
records[0].register_pull_request(pr1)
records[0].register_pull_request(pr2)

return records


def __get_record_mock_2_issue_with_2_prs(issue_1_state: str = "closed", issue_2_state: str = "closed",
issue_1_labels: list[str] = None, issue_2_labels: list[str] = None,
pr_with_rls_notes: bool = True, second_pr_merged: bool = True)-> dict[int, Record]:
# create 2 issues
issue1 = __get_default_issue_mock(number=1, state=issue_1_state, labels=issue_1_labels)
issue2 = __get_default_issue_mock(number=2, state=issue_2_state, labels=issue_2_labels)
# create 2 PRs per issue
pr1 = __get_default_pull_request_mock(issue_number=1, number=101, with_rls_notes=pr_with_rls_notes)
pr2 = __get_default_pull_request_mock(issue_number=1, number=102, with_rls_notes=pr_with_rls_notes,
is_merged=second_pr_merged)

records = {}
if issue_1_state == "closed":
records[0] = Record(issue1)
else:
records[0] = Record()
if issue_2_state == "closed":
records[1] = Record(issue2)
else:
records[1] = Record()
records[0].register_pull_request(pr1)
records[1].register_pull_request(pr2)

return records


def __get_record_mock_1_pr_with_no_issue(state: str = "closed", is_merged: bool = True, labels: list[str] = None,
with_rls_notes: bool = True, is_draft: bool = False) -> dict[int, Record]:
# create 2 PRs
Expand Down Expand Up @@ -320,6 +351,49 @@ def __get_record_mock_1_pr_with_no_issue(state: str = "closed", is_merged: bool
http://example.com/changelog
"""

release_notes_data_merged_pr_with_user_labels_duplicity_reduction_on = """### New Features 🎉
- PR: #101 _PR 101_
- PR 101 1st release note
- PR 101 2nd release note
#### Full Changelog
http://example.com/changelog
"""

release_notes_data_merged_prs_with_open_issues = """### Merged PRs Linked to 'Not Closed' Issue ⚠️
- PR: #101 _PR 101_
- PR 101 1st release note
- PR 101 2nd release note
- PR: #102 _PR 102_
- PR 102 1st release note
- PR 102 2nd release note
#### Full Changelog
http://example.com/changelog
"""

release_notes_data_closed_issue_with_merged_prs_without_user_labels = """### Closed Issues without User Defined Labels ⚠️
- #1 _I1+0PR+0L_ in [#101](https://github.com/None/pull/101), [#102](https://github.com/None/pull/102)
- PR 101 1st release note
- PR 101 2nd release note
- PR 102 1st release note
- PR 102 2nd release note
#### Full Changelog
http://example.com/changelog
"""

release_notes_data_closed_issue_with_merged_prs_with_user_labels = """### New Features 🎉
- #1 _I1+0PR+2L-bug-enhancement_ in [#101](https://github.com/None/pull/101), [#102](https://github.com/None/pull/102)
- PR 101 1st release note
- PR 101 2nd release note
- PR 102 1st release note
- PR 102 2nd release note
#### Full Changelog
http://example.com/changelog
"""

# build


Expand Down Expand Up @@ -531,8 +605,47 @@ def test_build_no_data_no_empty_chapters():
# ---------------------------------------------------------------------------------------------
# Alternative paths - see pull request in all logical states ==> in correct service chapters

# TODO next
# Test: Merged PR without Issue without user label
# - covered in 'test_build_merged_pr_service_chapter_without_issue_and_user_labels'

{
# Test: Merged PR without Issue with more user label - duplicity reduction on
"test_name": "test_merged_pr_without_issue_with_more_user_labels_duplicity_reduction_on",
"expected_release_notes": release_notes_data_merged_pr_with_user_labels_duplicity_reduction_on,
"records": __get_record_mock_1_pr_with_no_issue(labels=['bug', 'enhancement'])
},
# {
# # Test: Merged PR without Issue with more user label - duplicity reduction off - TODO
# "test_name": "test_merged_pr_without_issue_with_more_user_labels_duplicity_reduction_on",
# "expected_release_notes": release_notes_data_service_chapters_merged_pr_no_issue_no_user_labels,
# "records": __get_record_mock_1_pr_with_no_issue(labels=['bug', 'enhancement'])
# },
{
# Test: Merged PR with mentioned Open (Init) Issues | same to Reopen as it is same state
"test_name": "test_merged_pr_with_open_init_issue_mention",
"expected_release_notes": release_notes_data_merged_prs_with_open_issues,
"records": __get_record_mock_2_issue_with_2_prs(issue_1_state="open", issue_2_state="open")
},


# Test: Merged PR with mentioned Closed Issues
# - covered in 'test_build_closed_issue_with_prs_without_user_label'
{
# Test: Merged PR with mentioned Closed (not planned) Issues - without user labels
"test_name": "test_merged_pr_with_closed_issue_mention_without_user_labels",
"expected_release_notes": release_notes_data_closed_issue_with_merged_prs_without_user_labels,
"records": __get_record_mock_1_issue_with_2_prs(issue_state="closed", is_closed_not_planned=True)
},
{
# Test: Merged PR with mentioned Closed (not planned) Issues - with user labels
"test_name": "test_merged_pr_with_closed_issue_mention_with_user_labels",
"expected_release_notes": release_notes_data_closed_issue_with_merged_prs_with_user_labels,
"records": __get_record_mock_1_issue_with_2_prs(issue_state="closed", is_closed_not_planned=True,
issue_labels=['bug', 'enhancement'])
},

# Test: Merged PR without mentioned Issue
# - covered in 'test_build_merged_pr_service_chapter_without_issue_and_user_labels'
]


Expand Down

0 comments on commit e10094a

Please sign in to comment.