Skip to content

Commit

Permalink
generateStandardPRTitles
Browse files Browse the repository at this point in the history
  • Loading branch information
simran142002 committed Jan 21, 2024
1 parent 306ccd7 commit 1fe3b03
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
30 changes: 30 additions & 0 deletions src/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,33 @@ export function checkTitle(fullTitle: string): true {

return true;
}

export function formatPRTitle(
type: string,
module: string,
subject: string
): string {
if (!allowedTypes.includes(type)) {
throw new Error(
`Invalid type, expected one of ${allowedTypes.join(", ")}. Got ${type}.`
);
}

if (!allowedModules.includes(module)) {
throw new Error(
`Invalid module, expected one of ${allowedModules.join(
", "
)}. Got ${module}.`
);
}

const prTitle = `[${type}:${module}] ${subject}`;
const maxLegnth = 50;
if (prTitle.length > maxLegnth) {
throw new Error(
`PR title exceeds the maximum allowed length of ${maxLegnth} characters.`
);
}

return prTitle;
}
19 changes: 18 additions & 1 deletion test/validate.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { expect } from "chai";
import { allowedModules, allowedTypes, checkTitle } from "../src/validate";
import {
allowedModules,
allowedTypes,
checkTitle,
formatPRTitle,
} from "../src/validate";

describe("validate", () => {
describe("checkTitle", () => {
Expand Down Expand Up @@ -146,4 +151,16 @@ describe("validate", () => {
});
});
});

describe("formatPRTitle", () => {
it("should format PR Title correctly", () => {
const type = "Feature";
const module = "Submission";
const subject = "Add support for file uploads";

const formattedTitle = formatPRTitle(type, module, subject);
const expectedTitle = `[${type}:${module}] ${subject}`;
expect(formattedTitle).to.equal(expectedTitle);
});
});
});

0 comments on commit 1fe3b03

Please sign in to comment.