Skip to content

Commit

Permalink
fix: Prevent PR number and misshapen title (#10)
Browse files Browse the repository at this point in the history
* Prevent PR number and misshapen subject

* Update built action
ivov authored Jan 10, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent c97ff72 commit 13d0ee9
Showing 5 changed files with 45 additions and 2 deletions.
11 changes: 11 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
@@ -29390,11 +29390,14 @@ const ERRORS = {
SKIP_CHANGELOG_NOT_IN_FINAL_POSITION: `\`${NO_CHANGELOG}\` must be located at the end of the subject`,
MISSING_WHITESPACE_AFTER_COMMA:
"Missing whitespace after comma to separate multiple scopes",
INITIAL_PAREN_IN_SUBJECT: "Subject must not start with parens",
PR_NUMBER_PRESENT: "Title must not include pull request number",
};

const REGEXES = {
CONVENTIONAL_SCHEMA: /(?<type>\w+)(\((?<scope>.*)\))?!?: (?<subject>.*)/,
TICKET: /n8n-\d{3,5}/i,
PR_NUMBER: /#\d{5,7}/,
};

module.exports = {
@@ -29460,6 +29463,8 @@ async function validatePrTitle(title) {

if (containsTicketNumber(title)) return [ERRORS.TICKET_NUMBER_PRESENT];

if (containsPrNumber(title)) return [ERRORS.PR_NUMBER_PRESENT];

const issues = [];

// type validation
@@ -29497,6 +29502,10 @@ async function validatePrTitle(title) {
issues.push(ERRORS.LOWERCASE_INITIAL_IN_SUBJECT);
}

if (subject.startsWith("(")) {
issues.push(ERRORS.INITIAL_PAREN_IN_SUBJECT);
}

if (endsWithPeriod(subject)) {
issues.push(ERRORS.FINAL_PERIOD_IN_SUBJECT);
}
@@ -29516,6 +29525,8 @@ async function validatePrTitle(title) {
* Helpers
*/

const containsPrNumber = (str) => REGEXES.PR_NUMBER.test(str);

const isInvalidType = (str) => !TYPES.includes(str);

const isInvalidNodeScope = (str, allNodesDisplayNames) =>
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
@@ -34,11 +34,14 @@ const ERRORS = {
SKIP_CHANGELOG_NOT_IN_FINAL_POSITION: `\`${NO_CHANGELOG}\` must be located at the end of the subject`,
MISSING_WHITESPACE_AFTER_COMMA:
"Missing whitespace after comma to separate multiple scopes",
INITIAL_PAREN_IN_SUBJECT: "Subject must not start with parens",
PR_NUMBER_PRESENT: "Title must not include pull request number",
};

const REGEXES = {
CONVENTIONAL_SCHEMA: /(?<type>\w+)(\((?<scope>.*)\))?!?: (?<subject>.*)/,
TICKET: /n8n-\d{3,5}/i,
PR_NUMBER: /#\d{5,7}/,
};

module.exports = {
8 changes: 8 additions & 0 deletions src/validatePrTitle.js
Original file line number Diff line number Diff line change
@@ -16,6 +16,8 @@ async function validatePrTitle(title) {

if (containsTicketNumber(title)) return [ERRORS.TICKET_NUMBER_PRESENT];

if (containsPrNumber(title)) return [ERRORS.PR_NUMBER_PRESENT];

const issues = [];

// type validation
@@ -53,6 +55,10 @@ async function validatePrTitle(title) {
issues.push(ERRORS.LOWERCASE_INITIAL_IN_SUBJECT);
}

if (subject.startsWith("(")) {
issues.push(ERRORS.INITIAL_PAREN_IN_SUBJECT);
}

if (endsWithPeriod(subject)) {
issues.push(ERRORS.FINAL_PERIOD_IN_SUBJECT);
}
@@ -72,6 +78,8 @@ async function validatePrTitle(title) {
* Helpers
*/

const containsPrNumber = (str) => REGEXES.PR_NUMBER.test(str);

const isInvalidType = (str) => !TYPES.includes(str);

const isInvalidNodeScope = (str, allNodesDisplayNames) =>
23 changes: 22 additions & 1 deletion src/validatePrTitle.test.js
Original file line number Diff line number Diff line change
@@ -34,6 +34,17 @@ describe("schema", () => {
expect(issues).toHaveLength(1).toContain(ERRORS.TICKET_NUMBER_PRESENT);
});
});

test("Validation should fail for PR number in schema", () => {
[
"feat(Mattermost node): Add new resource #12345",
"feat(Mattermost node): Add new #123445 resource",
"feat(Mattermost node): #12345 Add new resource",
].forEach(async (title) => {
const issues = await validate(title);
expect(issues).toHaveLength(1).toContain(ERRORS.PR_NUMBER_PRESENT);
});
});
});

describe("type", () => {
@@ -152,12 +163,22 @@ describe("subject", () => {
[
"docs(Oura Node): Fix (no-changelog) typo",
"docs(Oura Node): Fix typo(no-changelog) ",
"docs(Oura Node): (no-changelog) Fix typo",
"docs(Oura Node): Fix (no-changelog) typo",
].forEach(async (title) => {
const issues = await validate(title);
expect(issues)
.toHaveLength(1)
.toContain(ERRORS.SKIP_CHANGELOG_NOT_IN_FINAL_POSITION);
});
});

test("Validation should fail for initial paren in subject", () => {
[
"feat(Mattermost Node): (Add new resource",
"feat(Mattermost Node): (Add new resource)",
].forEach(async (title) => {
const issues = await validate(title);
expect(issues).toHaveLength(1).toContain(ERRORS.INITIAL_PAREN_IN_SUBJECT);
});
});
});

0 comments on commit 13d0ee9

Please sign in to comment.