From 704bcd35ba19b8b2a821f0c4ce3b658d474e0e5d Mon Sep 17 00:00:00 2001 From: Piotr Karpala Date: Wed, 8 May 2024 13:55:10 -0400 Subject: [PATCH 1/3] Adding output - result of the check --- action.yml | 3 +++ dist/index.js | 4 ++++ index.ts | 4 ++++ 3 files changed, 11 insertions(+) diff --git a/action.yml b/action.yml index a2a8e88..3f22ab4 100644 --- a/action.yml +++ b/action.yml @@ -34,6 +34,9 @@ inputs: github_configuration_token: description: the github access token to be used to access the config file using other github_configuration_* parameters. can differ from GITHUB_TOKEN. defaults to GITHUB_TOKEN required: false +outputs: + success: + description: true if the PR title is valid, false otherwise. Undefined if an error occurred. runs: using: node20 main: dist/index.js diff --git a/dist/index.js b/dist/index.js index dff2dfb..b3ab71f 100644 --- a/dist/index.js +++ b/dist/index.js @@ -10050,6 +10050,7 @@ const run = ({ configPath, localConfigPath, remoteConfigURL, GitHubConfigOwner, if (labels[i].name == CHECKS.ignoreLabels[j]) { core.info(`Ignoring Title Check for label - ${labels[i].name}`); removeLabel({ labels, name: LABEL.name }); + core.setOutput("success", true); return; } } @@ -10060,6 +10061,7 @@ const run = ({ configPath, localConfigPath, remoteConfigURL, GitHubConfigOwner, if (title.startsWith(CHECKS.prefixes[i])) { removeLabel({ labels, name: LABEL.name }); core.info(MESSAGES.success); + core.setOutput("success", true); return; } } @@ -10069,10 +10071,12 @@ const run = ({ configPath, localConfigPath, remoteConfigURL, GitHubConfigOwner, if (re.test(title)) { removeLabel({ labels, name: LABEL.name }); core.info(MESSAGES.success); + core.setOutput("success", true); return; } } yield titleCheckFailed({ config: { LABEL, CHECKS, MESSAGES } }); + core.setOutput("success", false); } catch (error) { core.info(error); diff --git a/index.ts b/index.ts index 420abae..f960920 100644 --- a/index.ts +++ b/index.ts @@ -283,6 +283,7 @@ const run = async ({ if (labels[i].name == CHECKS.ignoreLabels[j]) { core.info(`Ignoring Title Check for label - ${labels[i].name}`); removeLabel({ labels, name: LABEL.name }); + core.setOutput("success", true); return; } } @@ -295,6 +296,7 @@ const run = async ({ if (title.startsWith(CHECKS.prefixes[i])) { removeLabel({ labels, name: LABEL.name }); core.info(MESSAGES.success); + core.setOutput("success", true); return; } } @@ -305,11 +307,13 @@ const run = async ({ if (re.test(title)) { removeLabel({ labels, name: LABEL.name }); core.info(MESSAGES.success); + core.setOutput("success", true); return; } } await titleCheckFailed({ config: { LABEL, CHECKS, MESSAGES } }); + core.setOutput("success", false); } catch (error) { core.info(error); } From 64416c2651a332bdbb6ff3e4afe79ee127863885 Mon Sep 17 00:00:00 2001 From: Piotr Karpala Date: Wed, 8 May 2024 14:17:42 -0400 Subject: [PATCH 2/3] Updates to readme --- README.md | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/README.md b/README.md index 4defe93..a61aad3 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,8 @@ The config file is always pulled from the action's context, i.e., the branch fro See [other ways to specify config file.](#other-ways-to-specify-config-file) +Action returns a single output: `success` that indicates if check has passed or failed. + ## Create Workflow Create a workflow file (eg: `.github/workflows/pr-title-checker.yml`) with the following content: @@ -115,6 +117,44 @@ Note that this has to be a url pointing to a valid, raw json file. See [#28](htt ``` This is useful if a repo containing the config file is pulled in a previous step using, for e.g., actions/checkout. See [#36](https://github.com/thehanimo/pr-title-checker/issues/36) +### Using output result + +You can use the action output to execute follow up steps e.g. adding a comment. + +```yml + steps: + - uses: thehanimo/pr-title-checker@v1.4.1 + id: check + continue-on-error: true + with: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + pass_on_octokit_error: false + + - name: Add comment to fix PR title + uses: marocchino/sticky-pull-request-comment@v2 + if: ${{ steps.check.outputs.success == 'false'}} + with: + header: 'PR Title Check' + recreate: true + message: | + ### 🚨 PR Title Needs Formatting 🚨 + The title of this PR needs to be formatted correctly and include an Azure Boards Reference. + Please update the title to match the format `type: description AB#xxx`. Examples: + * `bugfix: fix typo in README.md AB#123` + * `chore: update dependencies AB#456` + * `feat: add new feature AB#789` + * `chore: fixing build pipeline` - no AB reference + + - name: Add comment that PR title is fixed + if: ${{ steps.check.outputs.success == 'true'}} + uses: marocchino/sticky-pull-request-comment@v2 + with: + header: 'PR Title Check' + recreate: true + message: | + ### ✅ PR Title Fixed ✅ + The title of this PR has been updated to match the correct format. Thank you! +``` ## NOTE: * [`pull_request_target`](https://docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows#pull_request_target) event trigger should be used (not [`pull_request`](https://docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows#pull_request)) in order to support checking PRs from forks. This was added in `v1.3.2`. See [#8.](https://github.com/thehanimo/pr-title-checker/issues/8) From 17e25bb6933565a71dbb8ee6e4201101da6f20c5 Mon Sep 17 00:00:00 2001 From: Hani Date: Sun, 24 Nov 2024 23:18:14 -0500 Subject: [PATCH 3/3] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a61aad3..e940602 100644 --- a/README.md +++ b/README.md @@ -137,7 +137,7 @@ You can use the action output to execute follow up steps e.g. adding a comment. header: 'PR Title Check' recreate: true message: | - ### 🚨 PR Title Needs Formatting 🚨 + ### 🚨 PR Title Needs Formatting The title of this PR needs to be formatted correctly and include an Azure Boards Reference. Please update the title to match the format `type: description AB#xxx`. Examples: * `bugfix: fix typo in README.md AB#123` @@ -152,7 +152,7 @@ You can use the action output to execute follow up steps e.g. adding a comment. header: 'PR Title Check' recreate: true message: | - ### ✅ PR Title Fixed ✅ + ### ✅ PR Title Formatted Correctly The title of this PR has been updated to match the correct format. Thank you! ```