From 91a14afece050666834d9aa3bdedf4e7b4d3522d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o?= Date: Fri, 15 Dec 2023 17:46:59 +0000 Subject: [PATCH] test: add test and readme --- README.md | 5 +++++ action.yml | 2 +- src/validateTitle.test.js | 6 ++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index fac5d220..abfe0a12 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,11 @@ See [Conventional Commits](https://www.conventionalcommits.org/) for sample titl **Optional.** URL to be used when linking the "Details" in the actions overview. > Default: `"https://www.conventionalcommits.org/en/v1.0.0/#summary"`. +### `scope-required` + +**Optional.** Set to `true` if you want to fail in case the scope isn't set. +> Default: `false`. + ## Outputs ### `success` diff --git a/action.yml b/action.yml index af10acce..b559bfa4 100644 --- a/action.yml +++ b/action.yml @@ -23,7 +23,7 @@ inputs: required: false default: https://www.conventionalcommits.org/en/v1.0.0/#summary scope-required: - description: Set to true if you want to fail in case the scope isn't set + description: Set to true if you want to fail in case the scope isn't set. required: false default: false type: boolean diff --git a/src/validateTitle.test.js b/src/validateTitle.test.js index 661f7dc3..fb5ab3dc 100644 --- a/src/validateTitle.test.js +++ b/src/validateTitle.test.js @@ -41,3 +41,9 @@ it('throws for PR titles with an unknown type', async () => { /Unknown release type "foo" found in pull request title "foo: Bar"./ ); }); + +it('throws for PR titles without a scope when its required', async () => { + await expect(validateTitle(preset, 'feat: Add feature', true)).rejects.toThrow( + /No scope found in pull request title "feat: Add feature" but it's required./ + ); +});