Skip to content

Commit c195010

Browse files
loft-botPiotr1215
andauthored
fix(linear-sync): support variable-length team keys in issue regex (#3469) (#3472)
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. (cherry picked from commit 3aa6f71) # Conflicts: # hack/linear-sync/linear_test.go Co-authored-by: Piotr <[email protected]>
1 parent d893e31 commit c195010

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

hack/linear-sync/linear_test.go

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,10 +243,15 @@ func TestIssueIDsExtraction(t *testing.T) {
243243
defer func() {
244244
issuesInBodyREs = originalRegex
245245
}()
246+
<<<<<<< HEAD
246247

247248
// For testing, use a regex that matches any 3-letter prefix format
249+
=======
250+
251+
// For testing, use a regex that matches team keys of 2-10 chars and issue numbers 1-5 digits
252+
>>>>>>> 3aa6f7157 (fix(linear-sync): support variable-length team keys in issue regex (#3469))
248253
issuesInBodyREs = []*regexp.Regexp{
249-
regexp.MustCompile(`(?P<issue>\w{3}-\d{4})`),
254+
regexp.MustCompile(`(?P<issue>\w{2,10}-\d{1,5})`),
250255
}
251256

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

290325
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)