Skip to content

Self-hosted workflows for coding-agent delivery. Orchestrate CodeBuddy, Codex and Claude Code with scripts and human approval gates. Includes Local workflows for coding assistants.

refactor(domain): extract analyticsMRKey from SummarizeDeliveries (#331) (#332)

fx-kurumiac162fdf8280
diff --git a/internal/domain/mr.go b/internal/domain/mr.go
index b5ffa665..153e6a1d 100644
--- a/internal/domain/mr.go
+++ b/internal/domain/mr.go
@@ -47,7 +47,7 @@ func ParseGongfengMRs(text string) []GongfengMRRef {
if project == "" || iid <= 0 {
continue
}
- key := strings.ToLower(project) + "#" + strconv.Itoa(iid)
+ key := gongfengMRKey(project, iid)
if _, ok := seen[key]; ok {
continue
}
@@ -135,14 +135,7 @@ func SummarizeDeliveries(items []AnalyticsDelivery) AnalyticsDeliverySummary {
}
merged := false
for _, mr := range list {
- key := strings.TrimSpace(mr.URL)
- project, iid := mr.Project, mr.IID
- if p, n, _, ok := ParseGongfengMR(mr.URL); ok {
- project, iid = p, n
- }
- if project != "" && iid > 0 {
- key = strings.ToLower(project) + "#" + strconv.Itoa(iid)
- }
+ key := analyticsMRKey(mr)
if key == "" {
continue
}
@@ -184,6 +177,24 @@ func SummarizeDeliveries(items []AnalyticsDelivery) AnalyticsDeliverySummary {
return out
}
+// gongfengMRKey is the case-insensitive identity of a Gongfeng MR.
+func gongfengMRKey(project string, iid int) string {
+ return strings.ToLower(project) + "#" + strconv.Itoa(iid)
+}
+
+// analyticsMRKey dedups one delivery MR across URL forms: a parseable URL wins
+// over the stored project/iid, and the trimmed URL is the last resort.
+func analyticsMRKey(mr DeliveryMR) string {
+ project, iid := mr.Project, mr.IID
+ if p, n, _, ok := ParseGongfengMR(mr.URL); ok {
+ project, iid = p, n
+ }
+ if project != "" && iid > 0 {
+ return gongfengMRKey(project, iid)
+ }
+ return strings.TrimSpace(mr.URL)
+}
+
// analyticsPercentile 取最近邻分位数,输入允许无序(内部排序副本)。
func analyticsPercentile(values []int64, pct int) int64 {
if len(values) == 0 || pct <= 0 {
diff --git a/internal/domain/mr_key_test.go b/internal/domain/mr_key_test.go
new file mode 100644
index 00000000..30f6eabe
--- /dev/null
+++ b/internal/domain/mr_key_test.go
@@ -0,0 +1,30 @@
+package domain
+
+import "testing"
+
+func TestGongfengMRKey(t *testing.T) {
+ t.Parallel()
+ if got := gongfengMRKey("Team/Frontend", 7); got != "team/frontend#7" {
+ t.Fatalf("key=%q", got)
+ }
+}
+
+func TestAnalyticsMRKey(t *testing.T) {
+ t.Parallel()
+ cases := []struct {
+ name string
+ mr DeliveryMR
+ want string
+ }{
+ {"url wins over fields", DeliveryMR{Project: "other/repo", IID: 9, URL: "http://git.example.com/Team/Frontend/merge_requests/1"}, "team/frontend#1"},
+ {"fields when url unparseable", DeliveryMR{Project: "Team/Backend", IID: 2, URL: "local"}, "team/backend#2"},
+ {"trimmed url fallback", DeliveryMR{URL: " local-mr "}, "local-mr"},
+ {"invalid iid falls back to url", DeliveryMR{Project: "team/x", URL: "a"}, "a"},
+ {"empty", DeliveryMR{}, ""},
+ }
+ for _, tc := range cases {
+ if got := analyticsMRKey(tc.mr); got != tc.want {
+ t.Errorf("%s: key=%q want %q", tc.name, got, tc.want)
+ }
+ }
+}