Skip to content

Commit

Permalink
Add verbal-description to the failure message when the regex fails (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
AmirTugi authored Dec 9, 2024
1 parent bffd54c commit c5ab11c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ steps:
prefix_case_sensitive: false # title prefix are case insensitive
min_length: 5 # Min length of the title
max_length: 20 # Max length of the title
verbal_description: 'Two words with a slash (/) between' # Verbal description of the regex rule
github_token: ${{ github.token }} # Default: ${{ github.token }}
```
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ inputs:
description: 'Max length of title. -1 to ignore the rule'
required: false
default: '-1'
verbal_description:
description: 'Description of the title rules to display when the action fails'
required: false
default: ''
github_token:
description: >
Personal access token (PAT) used to fetch the repository. The PAT is configured
Expand Down
7 changes: 5 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ function validateTitlePrefix(title, prefix, caseSensitive) {

async function run() {
try {
const verbalDescription = core.getInput('verbal_description')
const authToken = core.getInput('github_token', {required: true})
const eventName = github.context.eventName;
core.info(`Event name: ${eventName}`);
Expand All @@ -36,13 +37,15 @@ async function run() {
});

const title = pullRequest.title;

core.info(`Pull Request title: "${title}"`);

// Check if title pass regex
const regex = RegExp(core.getInput('regex'));
if (!regex.test(title)) {
core.setFailed(`Pull Request title "${title}" failed to pass match regex - ${regex}`);
const messageSuffix = verbalDescription ? `rule - ${verbalDescription}` : `match regex - ${regex}`;

core.setFailed(`Pull Request title "${title}" failed to pass ${messageSuffix}`);
return
}

Expand Down

0 comments on commit c5ab11c

Please sign in to comment.