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

Changed the code to check for the first letter of the PR #10

Closed
Closed
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
12 changes: 5 additions & 7 deletions dist/index.js

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

29 changes: 18 additions & 11 deletions src/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,23 @@
"API",
];


Check failure on line 32 in src/validate.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Delete `⏎⏎`

export function checkTitle(fullTitle: string): true {
let title = fullTitle;
let hasSysadminTag = false;
let startsWithCapitalLetter=false;

Check failure on line 36 in src/validate.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Replace `=` with `·=·`
let hasSecurityTag = false;
if (title.startsWith(sysadminTag)) {
hasSysadminTag = true;
function startsWithCapital(title: string): boolean {

Check failure on line 38 in src/validate.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'title' is already declared in the upper scope on line 35 column 7
// Use a regular expression to check if the first character is an uppercase letter
const regex: RegExp = /^[A-Z]/;

Check failure on line 40 in src/validate.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Type RegExp trivially inferred from a RegExp literal, remove type annotation

Check failure on line 41 in src/validate.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Delete `····`
// Test the string against the regular expression
return regex.test(title);
}

Check failure on line 45 in src/validate.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Delete `····`
// Test the string against the regular expression

Check failure on line 46 in src/validate.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Delete `··`
if (startsWithCapital(title)) {
startsWithCapitalLetter = true;
title = title.substring(sysadminTag.length);
if (title.startsWith(" ")) {
throw new Error(`There should not be a space following ${sysadminTag}.`);
Expand All @@ -42,7 +53,7 @@
}

if (title.startsWith(securityTag)) {
hasSecurityTag = true;

Check failure on line 56 in src/validate.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'hasSecurityTag' is assigned a value but never used. Allowed unused vars must match /_.*/u
title = title.substring(securityTag.length);
if (title.startsWith(" ")) {
throw new Error(`There should not be a space following ${securityTag}.`);
Expand All @@ -55,13 +66,11 @@
);
}

if (!/^\[[a-zA-Z0-9\\/]+(?::[a-zA-Z0-9\\/]+)?\] /.test(title)) {
if (!/^[A-Z\[a-zA-Z0-9\\/]+(?::[a-zA-Z0-9\\/]+)?\]/.test(title)) {

Check failure on line 69 in src/validate.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Unnecessary escape character: \[
throw new Error(
`Invalid PR title format. ${
hasSysadminTag
? `Your title must start with ${sysadminTag} and`
: hasSecurityTag
? `Your title must start with ${securityTag} and`
startsWithCapitalLetter
? "Your title must start with capital letter 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` +
Expand All @@ -77,9 +86,7 @@
type,
module,
message,
] = /^\[([a-zA-Z0-9\\/]+)(?::([a-zA-Z0-9\\/]+))?\] (.*)/.exec(
title
) as RegExpMatchArray;
] = /^\[([A-Z][a-zA-Z0-9\\/]+)(?::([a-zA-Z0-9\\/]+))?\] (.*)/.exec(title) as RegExpMatchArray;

Check failure on line 89 in src/validate.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Replace `title` with `⏎····title⏎··`

const isDependency = type === "Dependency" || type === "DevDependency";
const minMessageLength = 2;
Expand Down
Loading