From 40a4ee2574d0608f330b8e4df2c09c93ef588c0e Mon Sep 17 00:00:00 2001 From: miroslavpojer Date: Wed, 25 Sep 2024 09:36:32 +0200 Subject: [PATCH] #55 - Chapter line formatting - authors - Add limitation to avoid of usage black to tests. - Removed workflow copying Release notes from PR to Issue as no more supported. - Updated README.md to show example of row formatting as build-in feature and provide list of supported keywords. --- .../release_notes_comments_migration.yml | 110 ------------------ README.md | 15 ++- action.yml | 4 +- pyproject.toml | 1 + release_notes_generator/action_inputs.py | 2 +- release_notes_generator/model/record.py | 2 +- .../test_release_notes_builder.py | 6 +- 7 files changed, 22 insertions(+), 118 deletions(-) delete mode 100644 .github/workflows/release_notes_comments_migration.yml diff --git a/.github/workflows/release_notes_comments_migration.yml b/.github/workflows/release_notes_comments_migration.yml deleted file mode 100644 index 61103777..00000000 --- a/.github/workflows/release_notes_comments_migration.yml +++ /dev/null @@ -1,110 +0,0 @@ -# -# Copyright 2023 ABSA Group Limited -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -name: Copy Release Notes to Related Issues - -on: - pull_request: - types: [closed] - branches: [ master ] - -jobs: - copy_release_notes: - if: github.event.pull_request.merged == true - runs-on: ubuntu-latest - steps: - - name: Fetch PR Comments - id: get-comments - uses: actions/github-script@v7 - with: - github-token: ${{secrets.GITHUB_TOKEN}} - script: | - const prNumber = context.payload.pull_request.number; - const repoName = context.repo.repo; - const repoOwner = context.repo.owner; - const releaseNotesRegex = /release notes/i; - - const comments = await github.rest.issues.listComments({ - owner: repoOwner, - repo: repoName, - issue_number: prNumber, - }); - - const releaseNoteComment = comments.data.find(comment => releaseNotesRegex.test(comment.body)); - const releaseNoteBody = releaseNoteComment ? releaseNoteComment.body : ''; - console.log(`Release Note Body: ${releaseNoteBody}`); - core.setOutput('releaseNoteBody', releaseNoteBody); - - - name: Print Extracted releaseNoteBody - run: | - echo "Extracted Release Note Body:" - echo "${{ steps.get-comments.outputs.releaseNoteBody }}" - echo "RELEASE_NOTE_BODY<> $GITHUB_ENV - echo "${{ steps.get-comments.outputs.releaseNoteBody }}" >> $GITHUB_ENV - echo "EOF" >> $GITHUB_ENV - - - name: Parse PR Description for Related Issues - id: find-issues - uses: actions/github-script@v7 - with: - github-token: ${{secrets.GITHUB_TOKEN}} - script: | - const description = context.payload.pull_request.body; - const issueNumbers = []; - const regexPattern = /([Cc]los(e|es|ed)|[Ff]ix(es|ed)?|[Rr]esolv(e|es|ed))\s*#\s*([0-9]+)/g; - - let match; - while ((match = regexPattern.exec(description)) !== null) { - // This is necessary to avoid infinite loops with zero-width matches - if (match.index === regexPattern.lastIndex) { - regexPattern.lastIndex++; - } - - // The actual issue number is in the last group of the match - const issueNumber = match[match.length - 1]; - if (issueNumber) { - issueNumbers.push(issueNumber); - } - } - - core.setOutput('issueNumbers', issueNumbers.join(', ')); - - - name: Print Extracted Issue Numbers - run: | - echo "Extracted Issue Numbers: ${{ steps.find-issues.outputs.issueNumbers }}" - echo "ISSUE_NUMBERS=${{ steps.find-issues.outputs.issueNumbers }}" >> $GITHUB_ENV - - - name: Post Comment to Issues - if: ${{ steps.get-comments.outputs.releaseNoteBody }} && ${{ steps.find-issues.outputs.issueNumbers }} - uses: actions/github-script@v7 - with: - github-token: ${{secrets.GITHUB_TOKEN}} - script: | - const issueNumbers = process.env.ISSUE_NUMBERS; - const commentBody = process.env.RELEASE_NOTE_BODY; - const repoName = context.repo.repo; - const repoOwner = context.repo.owner; - - for (const issueNumber of issueNumbers.split(', ')) { - if (issueNumber && commentBody) { - await github.rest.issues.createComment({ - owner: repoOwner, - repo: repoName, - issue_number: issueNumber, - body: commentBody - }); - } - } diff --git a/README.md b/README.md index 8f943f89..964c2e71 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ Generate Release Notes action is dedicated to enhance the quality and organizati ### `row-format-issue` - **Description**: The format of the row for the issue in the release notes. The format can contain placeholders for the issue `number`, `title`, and issues `pull-requests`. The placeholders are case-sensitive. - **Required**: No -- **Default**: `#{number} _{title}_ in {pull-requests}"` +- **Default**: `#{number} _{title}_ {pull-requests}"` ### `row-format-pr` - **Description**: The format of the row for the PR in the release notes. The format can contain placeholders for the PR `number`, `title`, and PR `pull-requests`. The placeholders are case-sensitive. @@ -166,6 +166,9 @@ Add the following step to your GitHub workflow (in example are used non-default warnings: false print-empty-chapters: false chapters-to-pr-without-issue: false + row-format-issue: '#{number} _{title}_ {pull-requests}"' + row-format-pr: '#{number} _{title}_"' + row-format-link-pr: true ``` ## Features @@ -197,6 +200,16 @@ If an issue is linked to multiple PRs, the action fetches and aggregates contrib #### No Release Notes Found If no valid "Release Notes" comment is found in an issue, it will be marked accordingly. This helps maintainers quickly identify which issues need attention for documentation. +#### Row formatting +Format of the row for the issue and PR in the release notes can be customized. The placeholders are case-sensitive. + +**Supported row format keywords:** +- `{number}`: Issue or PR number. +- `{title}`: Issue or PR title. +- `{pull-requests}`: List of PRs linked to the issue. Adds a list of PRs linked to the issue in the row with `in` prefix: + - `#{number} _{title}_ {pull-requests}` => "[#43]() _title_ in [#PR1](), [#PR2](), [#PR3]()" + - Not used in PR row format. See default value. + ### Select start date for closed issues and PRs By set **published-at** to true the action will use the `published-at` timestamp of the latest release as the reference point for searching closed issues and PRs, instead of the `created-at` date. If first release, repository creation date is used. diff --git a/action.yml b/action.yml index 45a06a21..310abd6e 100644 --- a/action.yml +++ b/action.yml @@ -58,11 +58,11 @@ inputs: row-format-issue: description: 'Format of the issue row in the release notes. Available placeholders: {link}, {title}, {pull-requests}. Placeholders are case-insensitive.' required: false - default: '#{number} _{title}_ in {pull-requests}' + default: '#{number} _{title}_ {pull-requests} {authors}' row-format-pr: description: 'Format of the pr row in the release notes. Available placeholders: {link}, {title}, {pull-requests}. Placeholders are case-insensitive.' required: false - default: '#{number} _{title}_' + default: '#{number} _{title}_ {authors}' row-format-link-pr: description: 'Add prefix "PR:" before link to PR when not linked an Issue.' required: false diff --git a/pyproject.toml b/pyproject.toml index 474d0aff..68eb39c1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,4 @@ [tool.black] line-length = 120 target-version = ['py311'] +force-exclude = '''test''' diff --git a/release_notes_generator/action_inputs.py b/release_notes_generator/action_inputs.py index 519b689d..9868561d 100644 --- a/release_notes_generator/action_inputs.py +++ b/release_notes_generator/action_inputs.py @@ -167,7 +167,7 @@ def get_row_format_issue() -> str: """ Get the issue row format for the release notes. """ - return get_action_input(ROW_FORMAT_ISSUE, "#{number} _{title}_ in {pull-requests}").strip() + return get_action_input(ROW_FORMAT_ISSUE, "#{number} _{title}_ {pull-requests}").strip() @staticmethod def get_row_format_pr() -> str: diff --git a/release_notes_generator/model/record.py b/release_notes_generator/model/record.py index c14f4b90..9a50e6f4 100644 --- a/release_notes_generator/model/record.py +++ b/release_notes_generator/model/record.py @@ -287,7 +287,7 @@ def to_chapter_row(self) -> str: else: format_values["number"] = self.__gh_issue.number format_values["title"] = self.__gh_issue.title - format_values["pull-requests"] = self.pr_links if len(self.__pulls) > 0 else "" + format_values["pull-requests"] = f"in {self.pr_links}" if len(self.__pulls) > 0 else "" format_values["authors"] = self.authors if self.authors is not None else "" format_values["contributors"] = self.contributors if self.contributors is not None else "" diff --git a/tests/release_notes/test_release_notes_builder.py b/tests/release_notes/test_release_notes_builder.py index 9002b719..599617d6 100644 --- a/tests/release_notes/test_release_notes_builder.py +++ b/tests/release_notes/test_release_notes_builder.py @@ -173,10 +173,10 @@ def __init__(self, name): """ RELEASE_NOTES_DATA_SERVICE_CHAPTERS_CLOSED_ISSUE_NO_PR_NO_USER_LABELS = """### Closed Issues without Pull Request ⚠️ -- #121 _Fix the bug_ in +- #121 _Fix the bug_ ### Closed Issues without User Defined Labels ⚠️ -- 🔔 #121 _Fix the bug_ in +- 🔔 #121 _Fix the bug_ #### Full Changelog http://example.com/changelog @@ -224,7 +224,7 @@ def __init__(self, name): """ RELEASE_NOTES_DATA_CLOSED_ISSUE_NO_PR_WITH_USER_LABELS = """### Closed Issues without Pull Request ⚠️ -- #121 _Fix the bug_ in +- #121 _Fix the bug_ #### Full Changelog http://example.com/changelog