Skip to content

Commit

Permalink
[Refactor:System] change the content of the "title check" to be more …
Browse files Browse the repository at this point in the history
…descriptive (#8)

Co-authored-by: Matthew Peveler <[email protected]>
  • Loading branch information
kacperswis and MasterOdin authored Nov 3, 2023
1 parent d740eb9 commit bbe95bb
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 24 deletions.
23 changes: 15 additions & 8 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

20 changes: 12 additions & 8 deletions src/validate.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const sysadminTag = "[SYSADMIN ACTION]";
const securityTag = "[SECURITY]";
const allowedTypes = [
export const allowedTypes = [
"Bugfix",
"Feature",
"Refactor",
Expand All @@ -11,7 +11,7 @@ const allowedTypes = [
"Dependency",
"DevDependency",
];
const allowedModules = [
export const allowedModules = [
"Submission",
"Autograding",
"Forum",
Expand All @@ -33,7 +33,6 @@ export function checkTitle(fullTitle: string): true {
let title = fullTitle;
let hasSysadminTag = false;
let hasSecurityTag = false;

if (title.startsWith(sysadminTag)) {
hasSysadminTag = true;
title = title.substring(sysadminTag.length);
Expand All @@ -58,11 +57,16 @@ export function checkTitle(fullTitle: string): true {

if (!/^\[[a-zA-Z0-9\\/]+(?::[a-zA-Z0-9\\/]+)?\] /.test(title)) {
throw new Error(
`Invalid title format, must start with ${
hasSysadminTag ? sysadminTag : ""
}${
hasSecurityTag ? securityTag : ""
}[<TYPE>:<MODULE>] and have space before description.`
`Invalid PR title format. ${
hasSysadminTag
? `Your title must start with ${sysadminTag} and`
: hasSecurityTag
? `Your title must start with ${securityTag} and`
: "Your title"
} should adhere to the format: [<TYPE>:<MODULE>] <SUBJECT> followed by a space before the description.\n` +
`Where <TYPE> is one of: ${allowedTypes.join(", ")}\n` +
`And <MODULE> is one of: ${allowedModules.join(", ")}\n` +
`For detailed guidelines, refer to https://submitty.org/developer/getting_started/make_a_pull_request.`
);
}

Expand Down
38 changes: 31 additions & 7 deletions test/validate.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from "chai";
import { checkTitle } from "../src/validate";
import { allowedModules, allowedTypes, checkTitle } from "../src/validate";

describe("validate", () => {
describe("checkTitle", () => {
Expand Down Expand Up @@ -30,39 +30,63 @@ describe("validate", () => {
[
[
"[Refactor:RainbowGrades]",
"Invalid title format, must start with [<TYPE>:<MODULE>] and have space before description.",
`Invalid PR title format. ` +
`Your title should adhere to the format: [<TYPE>:<MODULE>] <SUBJECT> followed by a space before the description.\n` +
`Where <TYPE> is one of: ${allowedTypes.join(", ")}\n` +
`And <MODULE> is one of: ${allowedModules.join(", ")}\n` +
`For detailed guidelines, refer to https://submitty.org/developer/getting_started/make_a_pull_request.`,
],
[
"[SYSADMINACTION][Refactor:Autograding] xxxx",
"Invalid title format, must start with [<TYPE>:<MODULE>] and have space before description.",
`Invalid PR title format. ` +
`Your title should adhere to the format: [<TYPE>:<MODULE>] <SUBJECT> followed by a space before the description.\n` +
`Where <TYPE> is one of: ${allowedTypes.join(", ")}\n` +
`And <MODULE> is one of: ${allowedModules.join(", ")}\n` +
`For detailed guidelines, refer to https://submitty.org/developer/getting_started/make_a_pull_request.`,
],
[
"[SYSADMIN ACTION] [Refactor:Submission] test",
"There should not be a space following [SYSADMIN ACTION].",
],
[
"[SYSADMIN ACTION][Refactor:Autograding]foo",
"Invalid title format, must start with [SYSADMIN ACTION][<TYPE>:<MODULE>] and have space before description.",
`Invalid PR title format. ` +
`Your title must start with [SYSADMIN ACTION] and should adhere to the format: [<TYPE>:<MODULE>] <SUBJECT> followed by a space before the description.\n` +
`Where <TYPE> is one of: ${allowedTypes.join(", ")}\n` +
`And <MODULE> is one of: ${allowedModules.join(", ")}\n` +
`For detailed guidelines, refer to https://submitty.org/developer/getting_started/make_a_pull_request.`,
],
[
"[SECURITY] [Refactor:Submission] test",
"There should not be a space following [SECURITY].",
],
[
"[SECURITY][Refactor:Autograding]foo",
"Invalid title format, must start with [SECURITY][<TYPE>:<MODULE>] and have space before description.",
`Invalid PR title format. ` +
`Your title must start with [SECURITY] and should adhere to the format: [<TYPE>:<MODULE>] <SUBJECT> followed by a space before the description.\n` +
`Where <TYPE> is one of: ${allowedTypes.join(", ")}\n` +
`And <MODULE> is one of: ${allowedModules.join(", ")}\n` +
`For detailed guidelines, refer to https://submitty.org/developer/getting_started/make_a_pull_request.`,
],
[
"[Bugfix: Submission] xxx",
"Unexpected space between <TYPE> and <MODULE> (e.g. [<TYPE>: <MODULE>]), there should be no space (e.g. [<TYPE>:<MODULE>]).",
],
[
"[SYSADMIN ACTION][SECURITY][Refactor:Autograding]foo",
"Invalid title format, must start with [SYSADMIN ACTION][SECURITY][<TYPE>:<MODULE>] and have space before description.",
`Invalid PR title format. ` +
`Your title must start with [SYSADMIN ACTION] and should adhere to the format: [<TYPE>:<MODULE>] <SUBJECT> followed by a space before the description.\n` +
`Where <TYPE> is one of: ${allowedTypes.join(", ")}\n` +
`And <MODULE> is one of: ${allowedModules.join(", ")}\n` +
`For detailed guidelines, refer to https://submitty.org/developer/getting_started/make_a_pull_request.`,
],
[
"[SECURITY][SYSADMIN ACTION][Refactor:Autograding] foo",
"Invalid title format, must start with [SECURITY][<TYPE>:<MODULE>] and have space before description.",
`Invalid PR title format. ` +
`Your title must start with [SECURITY] and should adhere to the format: [<TYPE>:<MODULE>] <SUBJECT> followed by a space before the description.\n` +
`Where <TYPE> is one of: ${allowedTypes.join(", ")}\n` +
`And <MODULE> is one of: ${allowedModules.join(", ")}\n` +
`For detailed guidelines, refer to https://submitty.org/developer/getting_started/make_a_pull_request.`,
],
].forEach(([value, expectedException]) => {
it(`checkTitle should throw: ${value}`, () => {
Expand Down

0 comments on commit bbe95bb

Please sign in to comment.