Merge pull request #10 from thehanimo/add-message-customization
Add message customization
This commit is contained in:
@@ -20,6 +20,11 @@ Create a config file `.github/pr-title-checker-config.json` like this one below:
|
|||||||
"regexp": "docs\\(v[0-9]\\): ",
|
"regexp": "docs\\(v[0-9]\\): ",
|
||||||
"regexpFlags": "i",
|
"regexpFlags": "i",
|
||||||
"ignoreLabels" : ["dont-check-PRs-with-this-label", "meta"]
|
"ignoreLabels" : ["dont-check-PRs-with-this-label", "meta"]
|
||||||
|
},
|
||||||
|
"MESSAGES": {
|
||||||
|
"success": "All OK",
|
||||||
|
"failure": "Failing CI test",
|
||||||
|
"notice": ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -51,7 +56,7 @@ jobs:
|
|||||||
check:
|
check:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: thehanimo/[email protected].2
|
- uses: thehanimo/[email protected].3
|
||||||
with:
|
with:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
pass_on_octokit_error: false
|
pass_on_octokit_error: false
|
||||||
|
|||||||
Vendored
+1837
-44867
File diff suppressed because one or more lines are too long
Vendored
+1
-1
File diff suppressed because one or more lines are too long
@@ -21,15 +21,20 @@ async function run() {
|
|||||||
core.setFailed(`Couldn't retrieve the config file specified - ${e}`);
|
core.setFailed(`Couldn't retrieve the config file specified - ${e}`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let { CHECKS, LABEL } = JSON.parse(config);
|
let { CHECKS, LABEL, MESSAGES } = JSON.parse(config);
|
||||||
LABEL.name = LABEL.name || "title needs formatting";
|
LABEL.name = LABEL.name || "title needs formatting";
|
||||||
LABEL.color = LABEL.color || "eee";
|
LABEL.color = LABEL.color || "eee";
|
||||||
CHECKS.ignoreLabels = CHECKS.ignoreLabels || [];
|
CHECKS.ignoreLabels = CHECKS.ignoreLabels || [];
|
||||||
|
MESSAGES = MESSAGES || {};
|
||||||
|
MESSAGES.success = MESSAGES.success || "All OK";
|
||||||
|
MESSAGES.failure = MESSAGES.failure || "Failing CI test";
|
||||||
|
MESSAGES.notice = MESSAGES.notice || "";
|
||||||
|
|
||||||
for (let i = 0; i < labels.length; i++) {
|
for (let i = 0; i < labels.length; i++) {
|
||||||
for (let j = 0; j < CHECKS.ignoreLabels.length; j++) {
|
for (let j = 0; j < CHECKS.ignoreLabels.length; j++) {
|
||||||
if (labels[i].name == CHECKS.ignoreLabels[j]) {
|
if (labels[i].name == CHECKS.ignoreLabels[j]) {
|
||||||
core.info(`Ignoring Title Check for label - ${labels[i].name}`);
|
core.info(`Ignoring Title Check for label - ${labels[i].name}`);
|
||||||
|
removeLabel(labels, LABEL.name, true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -51,52 +56,72 @@ async function run() {
|
|||||||
if (CHECKS.prefixes && CHECKS.prefixes.length) {
|
if (CHECKS.prefixes && CHECKS.prefixes.length) {
|
||||||
for (let i = 0; i < CHECKS.prefixes.length; i++) {
|
for (let i = 0; i < CHECKS.prefixes.length; i++) {
|
||||||
if (title.startsWith(CHECKS.prefixes[i])) {
|
if (title.startsWith(CHECKS.prefixes[i])) {
|
||||||
removeLabel(LABEL.name);
|
removeLabel(labels, LABEL.name, CHECKS.alwaysPassCI);
|
||||||
|
core.info(MESSAGES.success);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CHECKS.regexp) {
|
if (CHECKS.regexp) {
|
||||||
let re = new RegExp(CHECKS.regexp, CHECKS.regexpFlags || '');
|
let re = new RegExp(CHECKS.regexp, CHECKS.regexpFlags || "");
|
||||||
if (re.test(title)) {
|
if (re.test(title)) {
|
||||||
removeLabel(LABEL.name);
|
removeLabel(labels, LABEL.name, CHECKS.alwaysPassCI);
|
||||||
|
core.info(MESSAGES.success);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
addLabel(LABEL.name, CHECKS.alwaysPassCI);
|
await titleCheckFailed(CHECKS, LABEL, MESSAGES);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
core.info(error);
|
core.info(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function addLabel(name, alwaysPassCI) {
|
async function titleCheckFailed(CHECKS, LABEL, MESSAGES) {
|
||||||
try {
|
try {
|
||||||
core.info(`Adding label (${name}) to PR...`);
|
if (MESSAGES.notice.length) {
|
||||||
let addLabelResponse = await octokit.issues.addLabels({
|
core.notice(MESSAGES.notice);
|
||||||
owner,
|
|
||||||
repo,
|
|
||||||
issue_number,
|
|
||||||
labels: [name],
|
|
||||||
});
|
|
||||||
core.info(`Added label (${name}) to PR - ${addLabelResponse.status}`);
|
|
||||||
if (!alwaysPassCI) {
|
|
||||||
core.setFailed("Failing CI test");
|
|
||||||
}
|
}
|
||||||
core.info("All OK");
|
|
||||||
} catch (error) {
|
await addLabel(LABEL.name);
|
||||||
core.info(error);
|
|
||||||
if (alwaysPassCI) {
|
if (CHECKS.alwaysPassCI) {
|
||||||
core.info(`Failed to add label (${name}) to PR`);
|
core.info(MESSAGES.failure);
|
||||||
} else {
|
} else {
|
||||||
core.setFailed(`Failed to add label (${name}) to PR`);
|
core.setFailed(MESSAGES.failure);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
core.info(error);
|
||||||
|
if (CHECKS.alwaysPassCI) {
|
||||||
|
core.info(`Failed to add label (${LABEL.name}) to PR`);
|
||||||
|
} else {
|
||||||
|
core.setFailed(`Failed to add label (${LABEL.name}) to PR`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function removeLabel(name) {
|
async function addLabel(name) {
|
||||||
|
core.info(`Adding label (${name}) to PR...`);
|
||||||
|
let addLabelResponse = await octokit.issues.addLabels({
|
||||||
|
owner,
|
||||||
|
repo,
|
||||||
|
issue_number,
|
||||||
|
labels: [name],
|
||||||
|
});
|
||||||
|
core.info(`Added label (${name}) to PR - ${addLabelResponse.status}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function removeLabel(labels, name, alwaysPassCI) {
|
||||||
try {
|
try {
|
||||||
|
if (
|
||||||
|
!labels
|
||||||
|
.map((label) => label.name.toLowerCase())
|
||||||
|
.includes(name.toLowerCase())
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
core.info("No formatting necessary. Removing label...");
|
core.info("No formatting necessary. Removing label...");
|
||||||
let removeLabelResponse = await octokit.issues.removeLabel({
|
let removeLabelResponse = await octokit.issues.removeLabel({
|
||||||
owner,
|
owner,
|
||||||
|
|||||||
Reference in New Issue
Block a user