⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.
TypeScript honoissue-managementissue-trackerjira-alternativekanbanlinear-alternativemcpproject-managementreactself-hostedtypescript
fix(github): match a branch whose title segment is empty (#1522)
Luan Taraschi829f5addf275
diff --git a/apps/api/src/plugins/github/utils/branch-matcher.ts b/apps/api/src/plugins/github/utils/branch-matcher.tsindex 9412b86df..6a2d9f63a 100644--- a/apps/api/src/plugins/github/utils/branch-matcher.ts+++ b/apps/api/src/plugins/github/utils/branch-matcher.ts@@ -29,7 +29,10 @@ export function createBranchRegex(const regexPattern = escapedPattern.replace("\\{slug\\}", projectSlug.toLowerCase()).replace("\\{number\\}", "(\\d+)")- .replace("\\{title\\}", "([a-z0-9-]+)");+ // The title segment can be empty: slugify keeps only ASCII alphanumerics,+ // so a title written in any other script leaves nothing behind and+ // generateBranchName emits the separator with no name after it.+ .replace("\\{title\\}", "([a-z0-9-]*)");// Allow optional suffix after the pattern (e.g., lif-3-part-1)return new RegExp(`^${regexPattern}(?:-.*)?$`, "i");diff --git a/tests/api/plugins/github/utils/branch-matcher.test.ts b/tests/api/plugins/github/utils/branch-matcher.test.tsindex ca8d8b6fd..997bfd5f3 100644--- a/tests/api/plugins/github/utils/branch-matcher.test.ts+++ b/tests/api/plugins/github/utils/branch-matcher.test.ts@@ -43,6 +43,33 @@ describe("createBranchRegex", () => {});});+describe("branch names round trip", () => {+ // slugify keeps only ASCII alphanumerics, so a title written in any other+ // script leaves nothing where {title} goes. Four of the eight patterns+ // offered in the integration settings carry {title}.+ const pattern = "{slug}-{number}-{title}";+ const config = { ...baseConfig, branchPattern: pattern };++ it.each([+ ["Проверка входа", "Cyrillic"],+ ["ログイン修正", "Japanese"],+ ["登录修复", "Chinese"],+ ["수정", "Korean"],+ ["Διόρθωση", "Greek"],+ ])("matches the branch it generated for %s (%s)", (title) => {+ const branch = generateBranchName(pattern, "KAN", 42, title);++ expect(extractTaskNumberFromBranch(branch, config, "KAN")).toBe(42);+ });++ it("matches the branch it generated for a Latin title", () => {+ const branch = generateBranchName(pattern, "KAN", 42, "Fix the login bug");++ expect(branch).toBe("kan-42-fix-the-login-bug");+ expect(extractTaskNumberFromBranch(branch, config, "KAN")).toBe(42);+ });+});+describe("extractTaskNumberFromBranch", () => {it("uses the default branch pattern", () => {expect(