Skip to content

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

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

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 @@ export const allowedModules = [
"API",
];



export function checkTitle(fullTitle: string): true {
let title = fullTitle;
let hasSysadminTag = false;
let startsWithCapitalLetter=false;
let hasSecurityTag = false;
if (title.startsWith(sysadminTag)) {
hasSysadminTag = true;
function startsWithCapital(title: string): boolean {
// Use a regular expression to check if the first character is an uppercase letter
const regex: RegExp = /^[A-Z]/;

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

// Test the string against the regular expression
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 @@ -55,13 +66,11 @@ export function checkTitle(fullTitle: string): true {
);
}

if (!/^\[[a-zA-Z0-9\\/]+(?::[a-zA-Z0-9\\/]+)?\] /.test(title)) {
if (!/^[A-Z\[a-zA-Z0-9\\/]+(?::[a-zA-Z0-9\\/]+)?\]/.test(title)) {
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 @@ export function checkTitle(fullTitle: string): true {
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;

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