-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/120 change latest tag selection from time to semantic #124
Merged
miroslavpojer
merged 9 commits into
master
from
feature/120-Change-latest-tag-selection-from-time-to-semantic
Dec 9, 2024
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
0d5fafe
#119 - Add ability to define RLS from which to detect changes
miroslavpojer 940fc2b
- Black tool applied.
miroslavpojer b336cbd
- Black tool applied.
miroslavpojer 7fa21b1
- New version-tag-check version used.
miroslavpojer 669302e
- Review comments fix.
miroslavpojer c8e5252
#120 - Change latest tag selection from time to semantic
miroslavpojer c00f063
Merge branch 'master' into feature/120-Change-latest-tag-selection-fr…
miroslavpojer 181c8ca
- Remove duplicated tests after merge.
miroslavpojer 379c61a
- Fix review comments.
miroslavpojer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,20 +23,21 @@ | |
import sys | ||
|
||
from typing import Optional | ||
import semver | ||
|
||
from github import Github | ||
from github.GitRelease import GitRelease | ||
from github.Repository import Repository | ||
|
||
from release_notes_generator.action_inputs import ActionInputs | ||
from release_notes_generator.builder import ReleaseNotesBuilder | ||
from release_notes_generator.model.custom_chapters import CustomChapters | ||
from release_notes_generator.model.record import Record | ||
from release_notes_generator.builder import ReleaseNotesBuilder | ||
from release_notes_generator.record.record_factory import RecordFactory | ||
from release_notes_generator.action_inputs import ActionInputs | ||
from release_notes_generator.utils.constants import ISSUE_STATE_ALL | ||
|
||
from release_notes_generator.utils.decorators import safe_call_decorator | ||
from release_notes_generator.utils.utils import get_change_url | ||
from release_notes_generator.utils.github_rate_limiter import GithubRateLimiter | ||
from release_notes_generator.utils.utils import get_change_url | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
@@ -81,7 +82,7 @@ def generate(self) -> Optional[str]: | |
return None | ||
|
||
# get the latest release | ||
rls: GitRelease = self.get_latest_release(repo) | ||
rls = self.get_latest_release(repo) | ||
|
||
# default is repository creation date if no releases OR created_at of latest release | ||
since = rls.created_at if rls else repo.created_at | ||
|
@@ -134,17 +135,19 @@ def get_latest_release(self, repo: Repository) -> Optional[GitRelease]: | |
@param repo: The repository to get the latest release from. | ||
@return: The latest release of the repository, or None if no releases are found. | ||
""" | ||
# check if from-tag name is defined | ||
if ActionInputs.is_from_tag_name_defined(): | ||
logger.info("Getting latest release by from-tag name %s", ActionInputs.get_tag_name()) | ||
rls: GitRelease = self._safe_call(repo.get_release)(ActionInputs.get_from_tag_name()) | ||
rls = self._safe_call(repo.get_release)(ActionInputs.get_from_tag_name()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Keep. |
||
|
||
if rls is None: | ||
logger.info("Latest release not found for received tag %s. Ending!", ActionInputs.get_from_tag_name()) | ||
sys.exit(1) | ||
|
||
else: | ||
logger.info("Getting latest release by time.") | ||
rls: GitRelease = self._safe_call(repo.get_latest_release)() | ||
logger.info("Getting latest release by semantic ordering (could not be the last one by time).") | ||
gh_releases: list = list(self._safe_call(repo.get_releases)()) | ||
rls: GitRelease = self.__get_latest_semantic_release(gh_releases) | ||
|
||
if rls is None: | ||
logger.info("Latest release not found for %s. 1st release for repository!", repo.full_name) | ||
|
@@ -158,3 +161,25 @@ def get_latest_release(self, repo: Repository) -> Optional[GitRelease]: | |
) | ||
|
||
return rls | ||
|
||
def __get_latest_semantic_release(self, releases) -> Optional[GitRelease]: | ||
published_releases = [release for release in releases if not release.draft and not release.prerelease] | ||
latest_version: Optional[semver.Version] = None | ||
rls: Optional[GitRelease] = None | ||
|
||
for release in published_releases: | ||
try: | ||
version_str = release.tag_name.lstrip("v") | ||
current_version: Optional[semver.Version] = semver.VersionInfo.parse(version_str) | ||
except ValueError: | ||
logger.debug("Skipping invalid value of version tag: %s", release.tag_name) | ||
continue | ||
except TypeError: | ||
logger.debug("Skipping invalid type of version tag: %s", release.tag_name) | ||
continue | ||
|
||
if latest_version is None or current_version > latest_version: | ||
latest_version = current_version | ||
rls = release | ||
|
||
return rls |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ PyGithub==1.59.0 | |
pylint==3.2.6 | ||
requests==2.31.0 | ||
black==24.8.0 | ||
semver==3.0.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keep the type hints.