Skip to content

Commit ea8de71

Browse files
kacperswisMasterOdin
authored andcommitted
[Refactor:System] change the content of the "title check" to be more helpful
1 parent d740eb9 commit ea8de71

File tree

4 files changed

+59
-24
lines changed

4 files changed

+59
-24
lines changed

dist/index.js

Lines changed: 15 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/validate.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const sysadminTag = "[SYSADMIN ACTION]";
22
const securityTag = "[SECURITY]";
3-
const allowedTypes = [
3+
export const allowedTypes = [
44
"Bugfix",
55
"Feature",
66
"Refactor",
@@ -11,7 +11,7 @@ const allowedTypes = [
1111
"Dependency",
1212
"DevDependency",
1313
];
14-
const allowedModules = [
14+
export const allowedModules = [
1515
"Submission",
1616
"Autograding",
1717
"Forum",
@@ -33,7 +33,6 @@ export function checkTitle(fullTitle: string): true {
3333
let title = fullTitle;
3434
let hasSysadminTag = false;
3535
let hasSecurityTag = false;
36-
3736
if (title.startsWith(sysadminTag)) {
3837
hasSysadminTag = true;
3938
title = title.substring(sysadminTag.length);
@@ -58,11 +57,16 @@ export function checkTitle(fullTitle: string): true {
5857

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

test/validate.spec.ts

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expect } from "chai";
2-
import { checkTitle } from "../src/validate";
2+
import { allowedModules, allowedTypes, checkTitle } from "../src/validate";
33

44
describe("validate", () => {
55
describe("checkTitle", () => {
@@ -30,39 +30,63 @@ describe("validate", () => {
3030
[
3131
[
3232
"[Refactor:RainbowGrades]",
33-
"Invalid title format, must start with [<TYPE>:<MODULE>] and have space before description.",
33+
`Invalid PR title format. ` +
34+
`Your title should adhere to the format: [<TYPE>:<MODULE>] <SUBJECT> followed by a space before the description.\n` +
35+
`Where <TYPE> is one of: ${allowedTypes.join(", ")}\n` +
36+
`And <MODULE> is one of: ${allowedModules.join(", ")}\n` +
37+
`For detailed guidelines, refer to https://submitty.org/developer/getting_started/make_a_pull_request.`,
3438
],
3539
[
3640
"[SYSADMINACTION][Refactor:Autograding] xxxx",
37-
"Invalid title format, must start with [<TYPE>:<MODULE>] and have space before description.",
41+
`Invalid PR title format. ` +
42+
`Your title should adhere to the format: [<TYPE>:<MODULE>] <SUBJECT> followed by a space before the description.\n` +
43+
`Where <TYPE> is one of: ${allowedTypes.join(", ")}\n` +
44+
`And <MODULE> is one of: ${allowedModules.join(", ")}\n` +
45+
`For detailed guidelines, refer to https://submitty.org/developer/getting_started/make_a_pull_request.`,
3846
],
3947
[
4048
"[SYSADMIN ACTION] [Refactor:Submission] test",
4149
"There should not be a space following [SYSADMIN ACTION].",
4250
],
4351
[
4452
"[SYSADMIN ACTION][Refactor:Autograding]foo",
45-
"Invalid title format, must start with [SYSADMIN ACTION][<TYPE>:<MODULE>] and have space before description.",
53+
`Invalid PR title format. ` +
54+
`Your title must start with [SYSADMIN ACTION] and should adhere to the format: [<TYPE>:<MODULE>] <SUBJECT> followed by a space before the description.\n` +
55+
`Where <TYPE> is one of: ${allowedTypes.join(", ")}\n` +
56+
`And <MODULE> is one of: ${allowedModules.join(", ")}\n` +
57+
`For detailed guidelines, refer to https://submitty.org/developer/getting_started/make_a_pull_request.`,
4658
],
4759
[
4860
"[SECURITY] [Refactor:Submission] test",
4961
"There should not be a space following [SECURITY].",
5062
],
5163
[
5264
"[SECURITY][Refactor:Autograding]foo",
53-
"Invalid title format, must start with [SECURITY][<TYPE>:<MODULE>] and have space before description.",
65+
`Invalid PR title format. ` +
66+
`Your title must start with [SECURITY] and should adhere to the format: [<TYPE>:<MODULE>] <SUBJECT> followed by a space before the description.\n` +
67+
`Where <TYPE> is one of: ${allowedTypes.join(", ")}\n` +
68+
`And <MODULE> is one of: ${allowedModules.join(", ")}\n` +
69+
`For detailed guidelines, refer to https://submitty.org/developer/getting_started/make_a_pull_request.`,
5470
],
5571
[
5672
"[Bugfix: Submission] xxx",
5773
"Unexpected space between <TYPE> and <MODULE> (e.g. [<TYPE>: <MODULE>]), there should be no space (e.g. [<TYPE>:<MODULE>]).",
5874
],
5975
[
6076
"[SYSADMIN ACTION][SECURITY][Refactor:Autograding]foo",
61-
"Invalid title format, must start with [SYSADMIN ACTION][SECURITY][<TYPE>:<MODULE>] and have space before description.",
77+
`Invalid PR title format. ` +
78+
`Your title must start with [SYSADMIN ACTION] and should adhere to the format: [<TYPE>:<MODULE>] <SUBJECT> followed by a space before the description.\n` +
79+
`Where <TYPE> is one of: ${allowedTypes.join(", ")}\n` +
80+
`And <MODULE> is one of: ${allowedModules.join(", ")}\n` +
81+
`For detailed guidelines, refer to https://submitty.org/developer/getting_started/make_a_pull_request.`,
6282
],
6383
[
6484
"[SECURITY][SYSADMIN ACTION][Refactor:Autograding] foo",
65-
"Invalid title format, must start with [SECURITY][<TYPE>:<MODULE>] and have space before description.",
85+
`Invalid PR title format. ` +
86+
`Your title must start with [SECURITY] and should adhere to the format: [<TYPE>:<MODULE>] <SUBJECT> followed by a space before the description.\n` +
87+
`Where <TYPE> is one of: ${allowedTypes.join(", ")}\n` +
88+
`And <MODULE> is one of: ${allowedModules.join(", ")}\n` +
89+
`For detailed guidelines, refer to https://submitty.org/developer/getting_started/make_a_pull_request.`,
6690
],
6791
].forEach(([value, expectedException]) => {
6892
it(`checkTitle should throw: ${value}`, () => {

0 commit comments

Comments
 (0)