Skip to content

Commit

Permalink
Merge branch 'master' into feature/120-Change-latest-tag-selection-fr…
Browse files Browse the repository at this point in the history
…om-time-to-semantic

# Conflicts:
#	release_notes_generator/generator.py
#	release_notes_generator/utils/pull_reuqest_utils.py
#	tests/test_action_inputs.py
#	tests/test_release_notes_generator.py
  • Loading branch information
miroslavpojer committed Dec 9, 2024
2 parents c8e5252 + 7a51e9f commit c00f063
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 2 deletions.
20 changes: 20 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
## Release Notes:
> Provide a concise summary of changes for the release notes. Include any new features, bug fixes, or other significant updates. Keep it brief and to the point.
## Checklist:
> Ensure the following tasks are completed before submission.
- [ ] My code follows the project style guidelines.
- [ ] I have performed a self-review of my code.
- [ ] I have commented my code, particularly in hard-to-understand areas.
- [ ] I have added tests that prove my fix is effective or my feature works.
- [ ] New and existing tests pass locally with my changes.
- [ ] I have used a code formatting tool to ensure consistent style.
- [ ] I have run a linter to check for code quality issues.

## Additional Context:
> Add any other context about the pull request here.
---
> **Note:** Remember to link this PR to the related issue by adding `Fixes #issue_number` to the description above.
Fixes **or** Closes #(issue)
1 change: 1 addition & 0 deletions release_notes_generator/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import logging
import sys

from typing import Optional
import semver

Expand Down
2 changes: 1 addition & 1 deletion release_notes_generator/utils/pull_reuqest_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#

"""
This module contains the main script for the Release Notes Generator GH Action.
This module contains the PullRequestUtils class which is responsible for extracting information from pull requests.
"""

import re
Expand Down
3 changes: 3 additions & 0 deletions tests/test_action_inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ def test_get_skip_release_notes_label(mocker):
mocker.patch("release_notes_generator.action_inputs.get_action_input", return_value="skip-release-notes")
assert ActionInputs.get_skip_release_notes_labels() == ["skip-release-notes"]


def test_get_skip_release_notes_label_not_defined(mocker):
mocker.patch("release_notes_generator.action_inputs.get_action_input", return_value="")
assert ActionInputs.get_skip_release_notes_labels() == ["skip-release-notes"]
Expand All @@ -135,10 +136,12 @@ def test_get_skip_release_notes_labels(mocker):
mocker.patch("release_notes_generator.action_inputs.get_action_input", return_value="skip-release-notes, another-skip-label")
assert ActionInputs.get_skip_release_notes_labels() == ["skip-release-notes", "another-skip-label"]


def test_get_skip_release_notes_labels_no_space(mocker):
mocker.patch("release_notes_generator.action_inputs.get_action_input", return_value="skip-release-notes,another-skip-label")
assert ActionInputs.get_skip_release_notes_labels() == ["skip-release-notes", "another-skip-label"]


def test_get_print_empty_chapters(mocker):
mocker.patch("release_notes_generator.action_inputs.get_action_input", return_value="true")
assert ActionInputs.get_print_empty_chapters() is True
Expand Down
54 changes: 53 additions & 1 deletion tests/test_release_notes_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ def test_generate_release_notes_latest_release_not_found(

release_notes = ReleaseNotesGenerator(github_mock, custom_chapters).generate()

print(release_notes)
assert release_notes is not None
assert "- #121 _Fix the bug_" in release_notes
assert "- #122 _I1+bug_" in release_notes
Expand Down Expand Up @@ -156,6 +155,7 @@ def test_generate_release_notes_latest_release_found_by_published_at(
mock_pull_closed_with_rls_notes_101.merged_at = mock_repo.created_at + timedelta(days=2)
mock_pull_closed_with_rls_notes_102.merged_at = mock_repo.created_at + timedelta(days=7)

github_mock.get_repo().get_latest_release.return_value = mock_git_release
mock_git_release.created_at = mock_repo.created_at + timedelta(days=5)
mock_git_release.published_at = mock_repo.created_at + timedelta(days=5)
mocker.patch("release_notes_generator.generator.ReleaseNotesGenerator.get_latest_release", return_value=mock_git_release)
Expand Down Expand Up @@ -201,6 +201,58 @@ def test_get_latest_release_from_tag_name_defined_no_release(mocker, mock_repo):
assert ('Latest release not found for received tag %s. Ending!', '') == mock_log_info.call_args_list[1][0]


def test_get_latest_release_from_tag_name_defined_release_exists(mocker, mock_repo):
mocker.patch("release_notes_generator.action_inputs.ActionInputs.is_from_tag_name_defined", return_value=True)
mock_exit = mocker.patch("sys.exit")
mock_log_info = mocker.patch("release_notes_generator.generator.logger.info")

github_mock = mocker.Mock(spec=Github)
github_mock.get_repo.return_value = mock_repo

rls_mock = mocker.Mock(spec=GitRelease)
mock_repo.get_release.return_value = rls_mock

mock_rate_limit = mocker.Mock()
mock_rate_limit.core.remaining = 1000
github_mock.get_rate_limit.return_value = mock_rate_limit

release_notes_generator = ReleaseNotesGenerator(github_mock, CustomChapters(print_empty_chapters=True))

latest_release = release_notes_generator.get_latest_release(mock_repo)

assert rls_mock == latest_release
mock_exit.assert_not_called()
assert mock_log_info.called_with(1)
assert ('Getting latest release by from-tag name %s', None) == mock_log_info.call_args_list[0][0]


# get_latest_release tests

def test_get_latest_release_from_tag_name_defined_no_release(mocker, mock_repo):
mocker.patch("release_notes_generator.action_inputs.ActionInputs.is_from_tag_name_defined", return_value=True)
mock_exit = mocker.patch("sys.exit")
mock_log_info = mocker.patch("release_notes_generator.generator.logger.info")

github_mock = mocker.Mock(spec=Github)
github_mock.get_repo.return_value = mock_repo

mock_repo.get_release.return_value = None

mock_rate_limit = mocker.Mock()
mock_rate_limit.core.remaining = 1000
github_mock.get_rate_limit.return_value = mock_rate_limit

release_notes_generator = ReleaseNotesGenerator(github_mock, CustomChapters(print_empty_chapters=True))

latest_release = release_notes_generator.get_latest_release(mock_repo)

assert latest_release is None
mock_exit.assert_called_once_with(1)
assert mock_log_info.called_with(2)
assert ('Getting latest release by from-tag name %s', None) == mock_log_info.call_args_list[0][0]
assert ('Latest release not found for received tag %s. Ending!', '') == mock_log_info.call_args_list[1][0]


def test_get_latest_release_from_tag_name_not_defined_no_release(mocker, mock_repo):
mocker.patch("release_notes_generator.action_inputs.ActionInputs.is_from_tag_name_defined", return_value=False)
mock_log_info = mocker.patch("release_notes_generator.generator.logger.info")
Expand Down

0 comments on commit c00f063

Please sign in to comment.