Skip to content

Commit e110fc3

Browse files
committed
#85 - Wrong type used in chapters definition
- Change format of input from json string to yaml array. - Several small improvement required by pylint.
1 parent 6b1f57c commit e110fc3

File tree

10 files changed

+68
-59
lines changed

10 files changed

+68
-59
lines changed

.github/workflows/release_draft.yml

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,16 @@ jobs:
5151
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5252
with:
5353
tag-name: ${{ github.event.inputs.tag-name }}
54-
chapters: '[
55-
{"title": "No entry 🚫", "label": "duplicate"},
56-
{"title": "No entry 🚫", "label": "invalid"},
57-
{"title": "No entry 🚫", "label": "wontfix"},
58-
{"title": "No entry 🚫", "label": "no RN"},
59-
{"title": "Breaking Changes 💥", "label": "breaking-change"},
60-
{"title": "New Features 🎉", "label": "enhancement"},
61-
{"title": "New Features 🎉", "label": "feature"},
62-
{"title": "Bugfixes 🛠", "label": "bug"},
63-
{"title": "Infrastructure ⚙️", "label": "infrastructure"},
64-
{"title": "Silent-live 🤫", "label": "silent-live"},
65-
{"title": "Documentation 📜", "label": "documentation"}
66-
]'
54+
chapters: |
55+
- { title: No entry 🚫, label: duplicate }
56+
- { title: Breaking Changes 💥, label: breaking-change }
57+
- { title: New Features 🎉, label: enhancement }
58+
- { title: New Features 🎉, label: feature }
59+
- { title: Bugfixes 🛠, label: bug }
60+
- { title: Infrastructure ⚙️, label: infrastructure }
61+
- { title: Silent-live 🤫, label: silent-live }
62+
- { title: Documentation 📜, label: documentation }
63+
6764
skip-release-notes-label: 'no RN'
6865
verbose: true
6966

README.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ Generate Release Notes action is dedicated to enhance the quality and organizati
5151
- **Required**: Yes
5252

5353
### `chapters`
54-
- **Description**: A JSON string defining chapters and corresponding labels for categorization. Each chapter should have a title and a label matching your GitHub issues and PRs.
54+
- **Description**: An Yaml array defining chapters and corresponding labels for categorization. Each chapter should have a title and a label matching your GitHub issues and PRs.
5555
- **Required**: Yes
5656

5757
### `row-format-issue`
@@ -374,11 +374,16 @@ Create *.sh file and place it in the project root.
374374
375375
# Set environment variables based on the action inputs
376376
export INPUT_TAG_NAME="v0.2.0"
377+
377378
export INPUT_CHAPTERS='[
378-
{"title": "Breaking Changes 💥", "label": "breaking-change"},
379-
{"title": "New Features 🎉", "label": "enhancement"},
380-
{"title": "New Features 🎉", "label": "feature"},
381-
{"title": "Bugfixes 🛠", "label": "bug"}
379+
{ title: No entry 🚫, label: duplicate },
380+
{ title: Breaking Changes 💥, label: breaking-change },
381+
{ title: New Features 🎉, label: enhancement },
382+
{ title: New Features 🎉, label: feature },
383+
{ title: Bugfixes 🛠, label: bug },
384+
{ title: Infrastructure ⚙️, label: infrastructure },
385+
{ title: Silent-live 🤫, label: silent-live },
386+
{ title: Documentation 📜, label: documentation }
382387
]'
383388
export INPUT_WARNINGS="true"
384389
export INPUT_PUBLISHED_AT="true"

action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ inputs:
2121
description: 'The tag name of the release to generate notes for.'
2222
required: true
2323
chapters:
24-
description: 'JSON string defining chapters and corresponding labels for categorization.'
24+
description: 'Yaml array defining chapters and corresponding labels for categorization.'
2525
required: false
2626
default: ''
2727
duplicity-scope:

examples/release_draft.yml

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,16 @@ jobs:
3838
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3939
with:
4040
tag-name: ${{ github.event.inputs.tag-name }}
41-
chapters: '[
42-
{"title": "No entry 🚫", "label": "duplicate"},
43-
{"title": "No entry 🚫", "label": "invalid"},
44-
{"title": "No entry 🚫", "label": "wontfix"},
45-
{"title": "No entry 🚫", "label": "no RN"},
46-
{"title": "Breaking Changes 💥", "label": "breaking-change"},
47-
{"title": "New Features 🎉", "label": "enhancement"},
48-
{"title": "New Features 🎉", "label": "feature"},
49-
{"title": "Bugfixes 🛠", "label": "bug"},
50-
{"title": "Infrastructure ⚙️", "label": "infrastructure"},
51-
{"title": "Silent-live 🤫", "label": "silent-live"},
52-
{"title": "Documentation 📜", "label": "documentation"}
53-
]'
41+
chapters: |
42+
- { title: No entry 🚫, label: duplicate }
43+
- { title: Breaking Changes 💥, label: breaking-change }
44+
- { title: New Features 🎉, label: enhancement }
45+
- { title: New Features 🎉, label: feature }
46+
- { title: Bugfixes 🛠, label: bug }
47+
- { title: Infrastructure ⚙️, label: infrastructure }
48+
- { title: Silent-live 🤫, label: silent-live }
49+
- { title: Documentation 📜, label: documentation }
50+
5451
skip-release-notes-label: 'no RN'
5552
verbose: true
5653

release_notes_generator/action_inputs.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
import sys
2424
import re
2525

26-
import yaml
2726
from typing import Optional
27+
import yaml
2828

2929

3030
from release_notes_generator.utils.constants import (
@@ -90,7 +90,7 @@ def get_chapters() -> Optional[list[dict[str, str]]]:
9090
Get list of the chapters from the action inputs. Each chapter is a dict.
9191
"""
9292
# Get the 'chapters' input from environment variables
93-
chapters_input: str = get_action_input(CHAPTERS, default='')
93+
chapters_input: str = get_action_input(CHAPTERS, default="")
9494

9595
# Parse the YAML input
9696
try:
@@ -99,7 +99,7 @@ def get_chapters() -> Optional[list[dict[str, str]]]:
9999
logger.error("Error: 'chapters' input is not a valid YAML list.")
100100
return None
101101
except yaml.YAMLError as exc:
102-
logger.error(f"Error parsing 'chapters' input: {exc}")
102+
logger.error("Error parsing 'chapters' input: {%s}", exc)
103103
return None
104104

105105
return chapters
@@ -240,7 +240,7 @@ def validate_inputs() -> None:
240240

241241
chapters = ActionInputs.get_chapters()
242242
if chapters is None:
243-
errors.append("Chapters JSON must be a valid JSON array.")
243+
errors.append("Chapters must be a valid yaml array.")
244244

245245
duplicity_icon = ActionInputs.get_duplicity_icon()
246246
if not isinstance(duplicity_icon, str) or not duplicity_icon.strip() or len(duplicity_icon) != 1:
@@ -286,7 +286,7 @@ def validate_inputs() -> None:
286286

287287
logger.debug("Repository: %s/%s", owner, repo_name)
288288
logger.debug("Tag name: %s", tag_name)
289-
logger.debug("Chapters JSON: %s", chapters)
289+
logger.debug("Chapters: %s", chapters)
290290
logger.debug("Published at: %s", published_at)
291291
logger.debug("Skip release notes labels: %s", ActionInputs.get_skip_release_notes_labels())
292292
logger.debug("Verbose logging: %s", verbose)
@@ -308,9 +308,10 @@ def _detect_row_format_invalid_keywords(row_format: str, row_type: str = "Issue"
308308
cleaned_row_format = row_format
309309
for invalid_keyword in invalid_keywords:
310310
logger.error(
311-
"Invalid `{}` detected in `{}` row format keyword(s) found: {}. Will be removed from string.".format(
312-
invalid_keyword, row_type, ", ".join(invalid_keywords)
313-
)
311+
"Invalid `%s` detected in `%s` row format keyword(s) found: %s. Will be removed from string.",
312+
invalid_keyword,
313+
row_type,
314+
", ".join(invalid_keywords),
314315
)
315316
if clean:
316317
cleaned_row_format = cleaned_row_format.replace(f"{{{invalid_keyword}}}", "")

release_notes_generator/model/custom_chapters.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
notes.
2020
"""
2121

22-
import json
23-
2422
from release_notes_generator.action_inputs import ActionInputs
2523
from release_notes_generator.model.base_chapters import BaseChapters
2624
from release_notes_generator.model.chapter import Chapter

release_notes_generator/utils/pull_reuqest_utils.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
# limitations under the License.
1515
#
1616

17+
"""
18+
This module contains the PullRequestRecord class which is responsible for representing a record in the release notes.
19+
"""
20+
1721
import re
1822

1923
from github.PullRequest import PullRequest

tests/release_notes/model/test_custom_chapters.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,17 +149,16 @@ def test_populate_none_duplicity_scope(custom_chapters, mocker):
149149
# from_json
150150

151151

152-
def test_custom_chapters_from_json():
152+
def test_custom_chapters_from_yaml_array():
153153
custom_chapters = CustomChapters()
154-
json_string = """
155-
[
154+
yaml_array_in_string = [
156155
{"title": "Breaking Changes 💥", "label": "breaking-change"},
157156
{"title": "New Features 🎉", "label": "enhancement"},
158157
{"title": "New Features 🎉", "label": "feature"},
159158
{"title": "Bugfixes 🛠", "label": "bug"}
160159
]
161-
"""
162-
custom_chapters.from_json(json_string)
160+
161+
custom_chapters.from_yaml_array(yaml_array_in_string)
163162

164163
assert "Breaking Changes 💥" in custom_chapters.titles
165164
assert "New Features 🎉" in custom_chapters.titles

tests/release_notes/test_release_notes_builder.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,12 @@ def __init__(self, name):
7878

7979

8080
DEFAULT_CHANGELOG_URL = "http://example.com/changelog"
81-
default_chapters_json = json.dumps(
82-
[
81+
default_chapters = [
8382
{"title": "Breaking Changes 💥", "label": "breaking-change"},
8483
{"title": "New Features 🎉", "label": "feature"},
8584
{"title": "New Features 🎉", "label": "enhancement"},
8685
{"title": "Bugfixes 🛠", "label": "bug"},
8786
]
88-
)
8987

9088
RELEASE_NOTES_NO_DATA = """### Breaking Changes 💥
9189
No entries detected.
@@ -302,7 +300,7 @@ def __init__(self, name):
302300

303301
def test_build_no_data():
304302
custom_chapters = CustomChapters()
305-
custom_chapters.from_json(default_chapters_json)
303+
custom_chapters.from_yaml_array(default_chapters)
306304

307305
expected_release_notes = RELEASE_NOTES_NO_DATA
308306

@@ -318,7 +316,7 @@ def test_build_no_data():
318316

319317
def test_build_no_data_no_warnings(mocker):
320318
custom_chapters = CustomChapters()
321-
custom_chapters.from_json(default_chapters_json)
319+
custom_chapters.from_yaml_array(default_chapters)
322320
mocker.patch("release_notes_generator.builder.ActionInputs.get_warnings", return_value=False)
323321

324322
expected_release_notes = RELEASE_NOTES_NO_DATA_NO_WARNING
@@ -335,7 +333,7 @@ def test_build_no_data_no_warnings(mocker):
335333

336334
def test_build_no_data_no_warnings_no_empty_chapters(mocker):
337335
custom_chapters_no_empty_chapters = CustomChapters()
338-
custom_chapters_no_empty_chapters.from_json(default_chapters_json)
336+
custom_chapters_no_empty_chapters.from_yaml_array(default_chapters)
339337
custom_chapters_no_empty_chapters.print_empty_chapters = False
340338
mocker.patch("release_notes_generator.builder.ActionInputs.get_warnings", return_value=False)
341339
mocker.patch("release_notes_generator.builder.ActionInputs.get_print_empty_chapters", return_value=False)
@@ -354,7 +352,7 @@ def test_build_no_data_no_warnings_no_empty_chapters(mocker):
354352

355353
def test_build_no_data_no_empty_chapters(mocker):
356354
custom_chapters_no_empty_chapters = CustomChapters()
357-
custom_chapters_no_empty_chapters.from_json(default_chapters_json)
355+
custom_chapters_no_empty_chapters.from_yaml_array(default_chapters)
358356
custom_chapters_no_empty_chapters.print_empty_chapters = False
359357
mocker.patch("release_notes_generator.builder.ActionInputs.get_print_empty_chapters", return_value=False)
360358

tests/test_action_inputs.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
success_case = {
2424
"get_github_repository": "owner/repo_name",
2525
"get_tag_name": "tag_name",
26-
"get_chapters_json": '{"chapter": "content"}',
26+
"get_chapters": [{"title": "Title", "label": "Label"}],
2727
"get_duplicity_scope": "custom",
2828
"get_duplicity_icon": "🔁",
2929
"get_warnings": True,
@@ -37,7 +37,7 @@
3737
("get_github_repository", "", "Owner and Repo must be a non-empty string."),
3838
("get_github_repository", "owner/", "Owner and Repo must be a non-empty string."),
3939
("get_tag_name", "", "Tag name must be a non-empty string."),
40-
("get_chapters_json", "invalid_json", "Chapters JSON must be a valid JSON string."),
40+
("get_chapters", None, "Chapters must be a valid yaml array."),
4141
("get_warnings", "not_bool", "Warnings must be a boolean."),
4242
("get_published_at", "not_bool", "Published at must be a boolean."),
4343
("get_print_empty_chapters", "not_bool", "Print empty chapters must be a boolean."),
@@ -104,9 +104,19 @@ def test_get_tag_name(mocker):
104104
assert ActionInputs.get_tag_name() == "v1.0.0"
105105

106106

107-
def test_get_chapters_json(mocker):
108-
mocker.patch("release_notes_generator.action_inputs.get_action_input", return_value='{"chapters": []}')
109-
assert ActionInputs.get_chapters_json() == '{"chapters": []}'
107+
def test_get_chapters_success(mocker):
108+
mocker.patch("release_notes_generator.action_inputs.get_action_input", return_value="[{\"title\": \"Title\", \"label\": \"Label\"}]")
109+
assert ActionInputs.get_chapters() == [{"title": "Title", "label": "Label"}]
110+
111+
112+
def test_get_chapters_exception(mocker):
113+
mocker.patch("release_notes_generator.action_inputs.get_action_input", return_value="wrong value")
114+
assert None == ActionInputs.get_chapters()
115+
116+
117+
def test_get_chapters_yaml_error(mocker):
118+
mocker.patch("release_notes_generator.action_inputs.get_action_input", return_value="[{\"title\": \"Title\" \"label\": \"Label\"}]")
119+
assert None == ActionInputs.get_chapters()
110120

111121

112122
def test_get_warnings(mocker):

0 commit comments

Comments
 (0)