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 title_example input #20

Closed
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
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'
title_example:
description: 'An example of the PR title that will be displayed if the regex match fails'
required: false
default: ''
github_token:
description: >
Personal access token (PAT) used to fetch the repository. The PAT is configured
Expand Down
11 changes: 9 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,20 @@ async function run() {
});

const title = pullRequest.title;


// Compose detailed error message
const title_example = core.getInput('title_example')
let title_example_message = 'Please update the title according to the rules.'
if (title_example) {
title_example_message = `The example title is: "${title_example}"`
}

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}`);
core.setFailed(`Pull Request title "${title}" failed to pass match regex - ${regex}. ${title_example_message}`);
return
}

Expand Down