diff --git a/README.md b/README.md index c928988..2837350 100644 --- a/README.md +++ b/README.md @@ -122,7 +122,7 @@ You can configure: * `latest_changes_file`: The file to modify with the latest changes. For example: `./docs/latest-changes.rst`. * `latest_changes_header`: The header to look for before adding a new message. for example: `# CHANGELOG`. * `template_file`: A custom Jinja2 template file to use to generate the message, you could use this to generate a different message or to use a different format, for example, HTML instead of the default Markdown. -* `end_regex`: A RegEx string that marks the end of this release, so it normally matches the start of the header of the next release section, normally the same header level as `latest_changes_header`, so, if the `latest_changes_header` is `### Latest Changes`, the content for the next release below is probably something like `### 0.2.0`, then the `end_regex` should be `^### `. This is used to limit the content updated as this will read the existing sub sections and possibly update them using the labels configuration and the labels in the PR. +* `end_regex`: A RegEx string that marks the end of this release, so it normally matches the start of the header of the next release section, normally the same header level as `latest_changes_header`, so, if the `latest_changes_header` is `### Latest Changes`, the content for the next release below is probably something like `### 0.2.0`, then the `end_regex` should be `^### `. This is used to limit the content updated as this will read the existing sub sections and possibly update them using the labels configuration and the labels in the PR. By default it is `(^### .*)|(^## .*)` to detect a possible next header, e.g. for the license. * `debug_logs`: Set to `'true'` to show logs with the current settings. * `labels`: A JSON array of JSON objects with a `label` that you would put in each PR and the `header` that would be used in the release notes. See the example below. * `label_header_prefix`: A prefix to put before each label's header. This is also used to detect where the next label header starts. By default it is `#### `, so the headers will look like `#### Features`. diff --git a/action.yml b/action.yml index 2a4e748..cea551b 100644 --- a/action.yml +++ b/action.yml @@ -21,8 +21,8 @@ inputs: required: false default: /app/latest_changes/latest-changes.jinja2 end_regex: - description: A RegEx string that marks the end of this release, so it normally matches the start of the header of the next release section, normally the same header level as `latest_changes_header`, so, if the `latest_changes_header` is `### Latest Changes`, the content for the next release below is probably something like `### 0.2.0`, then the `end_regex` should be `^### `. - default: '^### ' + description: A RegEx string that marks the end of this release, so it normally matches the start of the header of the next release section, normally the same header level as `latest_changes_header`, so, if the `latest_changes_header` is `### Latest Changes`, the content for the next release below is probably something like `### 0.2.0`, then the `end_regex` should be `^### `. By default it is `(^### .*)|(^## .*)` to detect a possible next header, e.g. for the license. + default: '(^### .*)|(^## .*)' required: false debug_logs: description: Use debug=True to enable more logging, useful to see the object shape for custom Jinja2 templates diff --git a/latest_changes/main.py b/latest_changes/main.py index 9198f1a..02ac7e7 100644 --- a/latest_changes/main.py +++ b/latest_changes/main.py @@ -25,7 +25,7 @@ class Settings(BaseSettings): input_latest_changes_file: Path = Path("README.md") input_latest_changes_header: str = "### Latest Changes" input_template_file: Path = Path(__file__).parent / "latest-changes.jinja2" - input_end_regex: str = "^### " + input_end_regex: str = "(^### .*)|(^## .*)" input_debug_logs: Optional[bool] = False input_labels: List[Section] = [ Section(label="breaking", header="Breaking Changes"), diff --git a/tests/test_generate_content.py b/tests/test_generate_content.py index 2fa686b..e68be99 100644 --- a/tests/test_generate_content.py +++ b/tests/test_generate_content.py @@ -1045,3 +1045,114 @@ def test_multiple_header_sections_label(): ) + "\n" ) + + +def test_first_change_with_extra_header(): + raw_content = """ + ## Release Notes + + ### Latest Changes + + ## License + + Released under the MIT License. + """ + + content = inspect.cleandoc(raw_content) + settings = Settings( + github_repository="tiangolo/latest-changes", + github_event_path="event.json", + input_token="secret", + ) + pr = TemplateDataPR( + title="Demo PR", + number=42, + html_url="https://example.com/pr/42", + user=TemplateDataUser(login="tiangolo", html_url="https://github.com/tiangolo"), + ) + new_content = generate_content( + content=content, settings=settings, pr=pr, labels=["feature"] + ) + assert ( + new_content + == inspect.cleandoc( + """ + ## Release Notes + + ### Latest Changes + + #### Features + + * Demo PR. PR [#42](https://example.com/pr/42) by [@tiangolo](https://github.com/tiangolo). + + ## License + + Released under the MIT License. + """ + ) + + "\n" + ) + + +def test_first_release_existing_content_with_extra_header(): + raw_content = """ + ## Release Note + + ### Latest Changes + + * 🔥 Remove config. PR [#47](https://github.com/tiangolo/latest-changes/pull/47) by [@tiangolo](https://github.com/tiangolo). + + #### Features + + * 🚀 Publish amd64 and arm64 versions. PR [#46](https://github.com/tiangolo/latest-changes/pull/46) by [@tiangolo](https://github.com/tiangolo). + + #### Docs + + * 📝 Add docs. PR [#43](https://github.com/tiangolo/latest-changes/pull/43) by [@tiangolo](https://github.com/tiangolo). + + ## License + + Released under the MIT License. + """ + + content = inspect.cleandoc(raw_content) + settings = Settings( + github_repository="tiangolo/latest-changes", + github_event_path="event.json", + input_token="secret", + ) + pr = TemplateDataPR( + title="Demo PR", + number=42, + html_url="https://example.com/pr/42", + user=TemplateDataUser(login="tiangolo", html_url="https://github.com/tiangolo"), + ) + new_content = generate_content( + content=content, settings=settings, pr=pr, labels=["feature"] + ) + assert ( + new_content + == inspect.cleandoc( + """ + ## Release Note + + ### Latest Changes + + * 🔥 Remove config. PR [#47](https://github.com/tiangolo/latest-changes/pull/47) by [@tiangolo](https://github.com/tiangolo). + + #### Features + + * Demo PR. PR [#42](https://example.com/pr/42) by [@tiangolo](https://github.com/tiangolo). + * 🚀 Publish amd64 and arm64 versions. PR [#46](https://github.com/tiangolo/latest-changes/pull/46) by [@tiangolo](https://github.com/tiangolo). + + #### Docs + + * 📝 Add docs. PR [#43](https://github.com/tiangolo/latest-changes/pull/43) by [@tiangolo](https://github.com/tiangolo). + + ## License + + Released under the MIT License. + """ + ) + + "\n" + )