Skip to content

Commit 3aa6f71

Browse files
authored
fix(linear-sync): support variable-length team keys in issue regex (loft-sh#3469)
DEVOPS-471 Hardcoded \w{3}-\d{4} regex only matched 3-letter team keys like ENG or OPS. Linear renamed OPS to DEVOPS (6 chars), breaking issue detection in PR bodies and branch names. New regex \w{2,10}-\d{1,5} supports: - Team keys from 2-10 characters (QA, ENG, DEVOPS, etc.) - Issue numbers from 1-5 digits (realistic for any team) Added test cases for DEVOPS, QA, mixed team keys, and edge cases.
1 parent 3deada2 commit 3aa6f71

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

hack/linear-sync/linear_test.go

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,9 +244,9 @@ func TestIssueIDsExtraction(t *testing.T) {
244244
issuesInBodyREs = originalRegex
245245
}()
246246

247-
// For testing, use a regex that matches any 3-letter prefix format
247+
// For testing, use a regex that matches team keys of 2-10 chars and issue numbers 1-5 digits
248248
issuesInBodyREs = []*regexp.Regexp{
249-
regexp.MustCompile(`(?P<issue>\w{3}-\d{4})`),
249+
regexp.MustCompile(`(?P<issue>\w{2,10}-\d{1,5})`),
250250
}
251251

252252
testCases := []struct {
@@ -285,6 +285,36 @@ func TestIssueIDsExtraction(t *testing.T) {
285285
headRefName: "security/fix",
286286
expected: []string{},
287287
},
288+
{
289+
name: "Long team key (DEVOPS)",
290+
body: "This PR fixes DEVOPS-471",
291+
headRefName: "feature/infra-update",
292+
expected: []string{"devops-471"},
293+
},
294+
{
295+
name: "Short team key (QA)",
296+
body: "This PR fixes QA-42",
297+
headRefName: "feature/test-fix",
298+
expected: []string{"qa-42"},
299+
},
300+
{
301+
name: "Mixed team keys",
302+
body: "This PR fixes ENG-1234 and DEVOPS-471",
303+
headRefName: "feature/QA-99-cross-team",
304+
expected: []string{"eng-1234", "devops-471", "qa-99"},
305+
},
306+
{
307+
name: "Issue with short number",
308+
body: "This PR fixes ENG-1",
309+
headRefName: "feature/quick-fix",
310+
expected: []string{"eng-1"},
311+
},
312+
{
313+
name: "Issue with long number",
314+
body: "This PR fixes ENG-12345",
315+
headRefName: "feature/big-project",
316+
expected: []string{"eng-12345"},
317+
},
288318
}
289319

290320
for _, tc := range testCases {

hack/linear-sync/pr.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
)
99

1010
var issuesInBodyREs = []*regexp.Regexp{
11-
regexp.MustCompile(`(?P<issue>\w{3}-\d{4})`),
11+
regexp.MustCompile(`(?i)(?P<issue>[A-Z]{2,10}-\d{1,5})`),
1212
}
1313

1414
const PageSize = 100
@@ -64,4 +64,4 @@ func (p LinearPullRequest) IssueIDs() []string {
6464
}
6565

6666
return issueIDs
67-
}
67+
}

0 commit comments

Comments
 (0)