Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add verbal-description to the failure message when the regex fails #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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