Skip to content

Commit

Permalink
- Improve the since logic for no release exist.
Browse files Browse the repository at this point in the history
  • Loading branch information
miroslavpojer committed Jul 2, 2024
1 parent a7366de commit 29222e2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
9 changes: 4 additions & 5 deletions src/github_integration/github_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def fetch_issues(self, since: Optional[datetime] = None, state: Optional[str] =
logging.error("Repository is not set.")
return []

if not since:
if since is None:
since = self.__get_since()

try:
Expand Down Expand Up @@ -257,12 +257,11 @@ def __get_since(self) -> Optional[datetime]:
Gets the 'since' datetime for fetching issues, pull requests, and commits.
:return: The 'since' datetime, or None if it is not set.
"""
if not self.__repository:
if self.__repository is None:
logging.error("Repository is not set.")
return None

if not self.__git_release:
logging.error("Latest release is not set.")
return None
if self.__git_release is None:
return self.__repository.created_at

return self.__git_release.published_at if self.__git_release.published_at else self.__git_release.created_at
4 changes: 3 additions & 1 deletion tests/github_integration/test_github_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,16 @@ def test_fetch_issues_without_git_release():
github_mock = Mock(spec=Github)
GithubManager().github = github_mock
repository_mock = Mock(spec=Repository)
repository_created_at = datetime(2023, 1, 1)
repository_mock.created_at = repository_created_at
GithubManager()._GithubManager__repository = repository_mock
issues_mock = [Mock(), Mock()]
repository_mock.get_issues.return_value = issues_mock

result = GithubManager().fetch_issues()

assert len(issues_mock) == len(result)
repository_mock.get_issues.assert_called_with(state="all", since=None) # get all state of issues in 'one' call
repository_mock.get_issues.assert_called_with(state="all", since=repository_created_at) # get all state of issues in 'one' call


def test_fetch_issues_without_git_release_no_repository():
Expand Down

0 comments on commit 29222e2

Please sign in to comment.