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

fix: Prevent PR number and misshapen title #10

Merged
merged 2 commits into from
Jan 10, 2025
Merged
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
11 changes: 11 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
Expand All @@ -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) =>
Expand Down
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
Expand Up @@ -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 = {
Expand Down
8 changes: 8 additions & 0 deletions src/validatePrTitle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
Expand All @@ -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) =>
Expand Down
23 changes: 22 additions & 1 deletion src/validatePrTitle.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down Expand Up @@ -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);
});
});
});
Loading