Skip to content

Commit

Permalink
feat: elax parse ticket in pr title and add status
Browse files Browse the repository at this point in the history
  • Loading branch information
christophehurpeau committed Oct 4, 2024
1 parent 2c10c7b commit 0c23252
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
44 changes: 42 additions & 2 deletions src/accountConfigs/Elax-Energie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,47 @@ const config: Config<never> = {
deleteAfterMerge: true,
},
parsePR: {
title: [],
title: [
{
regExp: /\s([A-Z][\dA-Z]+-(\d+)|\[no issue])$/,
status: "notion-ticket",
createStatusInfo: (match, prInfo, isPrFromBot) => {
if (match) {
const ticket = match[1];
if (ticket === "[no ticket]") {
return {
type: "success",
title: "✓ No ticket",
summary: "",
};
}

const url = `https://www.notion.so/elaxenergie/${ticket}`;
return {
type: "success",
inBody: true,
title: `✓ Notion ticket: ${ticket}`,
summary: `[${ticket}](${url})`,
url,
};
}

if (isPrFromBot) {
return {
type: "success",
title: "Title does not have Notion ticket but PR created by bot",
summary: "",
};
}

return {
type: "failure",
title: "Title does not have Notion ticket",
summary: "The PR title should end with GEN-0000, or [no ticket]",
};
},
},
],
body: [
{
bot: false,
Expand All @@ -30,7 +70,7 @@ const config: Config<never> = {
.replace(/^\s*#+\s+.*/gm, "")
.replace(/(<!--.*?-->)|(<!--[\S\s]+?-->)|(<!--[\S\s]*?$)/gs, "");

if (!descriptionStripTitlesAndComments?.trim()) {
if (!descriptionStripTitlesAndComments.trim()) {
return {
type: "failure",
title: "Body has no meaningful content",
Expand Down
3 changes: 3 additions & 0 deletions src/events/pr-handlers/actions/utils/prTitle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,8 @@ describe("cleanTitle", () => {
expect(cleanTitle("feat: add something - [no-issue]", true)).toBe(
"feat: add something [no issue]",
);
expect(cleanTitle("feat: add something - [no-ticket]", true)).toBe(
"feat: add something [no ticket]",
);
});
});
5 changes: 3 additions & 2 deletions src/events/pr-handlers/actions/utils/prTitle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ export const cleanTitle = (
)
.replace(/^([A-Za-z]+)[/:;]\s*/, (s, arg1) => `${arg1.toLowerCase()}: `)
.replace(/\s+(-\s*)?[()[\]]\s*no[\s-]*isss?ue\s*[()[\]]$/i, " [no issue]")
.replace(/^Revert "([^"]+)"( \[no issue])?$/, "revert: $1$2")
.replace(/^(revert:.*)(\s+\(#\d+\))( \[no issue])?$/, "$1$3")
.replace(/\s+(-\s*)?[()[\]]\s*no[\s-]*ticket\s*[()[\]]$/i, " [no ticket]")
.replace(/^Revert "([^"]+)"( \[no (issue|ticket)])?$/, "revert: $1$2")
.replace(/^(revert:.*)(\s+\(#\d+\))( \[no (issue|ticket)])?$/, "$1$3")
.replace(/^(?:revert: ){2}/, "");
};

0 comments on commit 0c23252

Please sign in to comment.