Skip to content

Commit

Permalink
Merge pull request #75 from tarurar/tarurar/issue57
Browse files Browse the repository at this point in the history
Tarurar/issue57
  • Loading branch information
tarurar authored May 10, 2024
2 parents fe12d6e + a2ce20e commit d41d270
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 28 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ This section is used to configure the connection to Bitbucket.
This section is used to configure the release process.

- `branch`: The branch to release from.
- `notesFolderPathTemplate`: The template for the path where release notes should be stored. `{nova}` and `{delivery}{hotfix}` are placeholders that will be replaced with actual values during the release process.
- `artifactsFolderPathTemplate`: The template for the path where release artifacts should be stored. `{nova}` and `{delivery}{hotfix}` are placeholders that will be replaced with actual values during the release process.
- `packageTags`: This section is used to configure the tagging of packages.
- `exceptions`: An array of exceptions for package tagging. Each exception has:
- `name`: The name of the package.
Expand Down Expand Up @@ -112,7 +112,7 @@ Here is configuration file example:
},
"release": {
"branch": "<RELEASE_BRANCH>",
"notesFolderPathTemplate": "{nova}{delivery}{hotfix}",
"artifactsFolderPathTemplate": "{nova}{delivery}{hotfix}",
"packageTags": {
"exceptions": [
{
Expand Down Expand Up @@ -141,8 +141,8 @@ The application has three modes of operation:
- Optionally updating versions in .csproj files.
- Tagging the repository.
- Moving tasks to the next status (`DONE`).
- `list-packages`: This mode is used to list the package versions created since the date specified. Option `--since` is used to specify the date. The date should be in the format `YYYY-MM-DD`. Option is not mandatory. If it is not specified, the application will try to detect the latest release date and list the packages created since that date. If neither the date is specified nor the latest release date is detected, the application will raise an error.
- `generate-notes`: This mode is used to generate release notes for the specified delivery. It created a .pdf file for every component which has CHANGELOG.md file in the root folder. The .pdf file is created in the folder specified in the `notesFolderPathTemplate` configuration option.
- `list-packages`: This mode is used to list the package versions created since the date specified. Option `--since` is used to specify the date. The date should be in the format `YYYY-MM-DD`. Option is not mandatory. If it is not specified, the application will try to detect the latest release date and list the packages created since that date. If neither the date is specified nor the latest release date is detected, the application will raise an error. The .csv file is created in the folder specified in the `artifactsFolderPathTemplate` configuration option.
- `generate-notes`: This mode is used to generate release notes for the specified delivery. It created a .pdf file for every component which has CHANGELOG.md file in the root folder. The .pdf file is created in the folder specified in the `artifactsFolderPathTemplate` configuration option.

Please note, the application heavily depends on the JIRA's `Components` feature. It is assumed that every component has its own `Component` in JIRA and every task is assigned to the corresponding `Component`. The `Component` name is used as the name of the component in the application. It means the registry of components in JIRA is the single source of truth for the application and should be managed with care.

Expand Down
22 changes: 13 additions & 9 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from dataclasses import dataclass
import json
from typing import Any, Optional
import fs_utils as fs


@dataclass
Expand Down Expand Up @@ -37,28 +38,31 @@ def __new__(cls, config_path: str = DEFAULT_CONFIG_PATH):
cls._instance.data = json.load(file)
return cls._instance

def get_notes_folder_path(
def get_artifacts_folder_path(
self, nova_version: str, delivery: str, hotfix: Optional[str] = None
):
"""
Returns path to the folder where release notes should be stored
Returns path to the folder where release artifacts should be stored.
Path is sanitized which guarantees the folder can be created if required.
:param nova_version: nova version
:param delivery: delivery number
:param hotfix: hotfix number
:return: path to the folder where release notes should be stored
:return: path to the folder where release artifacts should be stored
"""
template = self.data["release"]["notesFolderPathTemplate"]
template = self.data["release"]["artifactsFolderPathTemplate"]
if not template:
raise ValueError(
"notesFolderPathTemplate is not specified in config"
"artifactsFolderPathTemplate is not specified in config"
)
return template.format(
nova=f"Nova {nova_version}.",
delivery=f"Delivery {delivery}.",
hotfix=f" Hotfix {hotfix}" if hotfix else "",
formatted = template.format(
nova=f"Nova {nova_version}",
delivery=f"Delivery {delivery}",
hotfix=f"Hotfix {hotfix}" if hotfix else "",
)

return fs.sanitize_path(formatted)

def get_package_tag_exceptions(self) -> list[PackageTagException]:
"""
Reads a list of package tag exceptions from configuration file
Expand Down
17 changes: 5 additions & 12 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,6 @@ def choose_component_from_release(rel: NovaRelease) -> Optional[NovaComponent]:
""",
)

parser.add_argument(
"--csv-output",
type=str,
required=False,
help="""
The path to CSV file to output the result.
Applicable only for 'list-packages' command.
""",
)

parser.add_argument(
"--config-path",
type=str,
Expand Down Expand Up @@ -235,8 +225,11 @@ def choose_component_from_release(rel: NovaRelease) -> Optional[NovaComponent]:
)

if all_tags_info:
path = export_packages_to_csv(all_tags_info, args.csv_output)
print(f"CSV file has been created: {path}")
output_path = config.get_artifacts_folder_path(
args.version, args.delivery, ""
)
csv_file_path = export_packages_to_csv(all_tags_info, output_path)
print(f"CSV file has been created: {csv_file_path}")
else:
print("No tags found")

Expand Down
3 changes: 1 addition & 2 deletions notes_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,9 @@ def __init__(
self.__release = release
self.__gi = gi

output_path = config.get_notes_folder_path(
self.__output_path = config.get_artifacts_folder_path(
self.__release.version, self.__release.delivery, ""
)
self.__output_path = fs.sanitize_path(output_path)

def __ensure_output_folder_exists(self) -> None:
"""
Expand Down
4 changes: 3 additions & 1 deletion tests/test_notes_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
@pytest.fixture(name="mock_config")
def fixture_mock_config():
mock_config = Mock()
mock_config.get_notes_folder_path.return_value = "path_to_notes_folder"
mock_config.get_artifacts_folder_path.return_value = (
"path_to_artifacts_folder"
)
return mock_config


Expand Down

0 comments on commit d41d270

Please sign in to comment.