@@ -10,6 +10,7 @@ import (
1010 "os"
1111 "path/filepath"
1212 "strconv"
13+ "strings"
1314 "time"
1415
1516 "github.com/spf13/cobra"
@@ -24,6 +25,36 @@ import (
2425 "github.com/mrz1836/go-broadcast/coverage/internal/urlutil"
2526)
2627
28+ // getMainBranches returns the list of main branches from environment variable or default
29+ func getMainBranches () []string {
30+ mainBranches := os .Getenv ("MAIN_BRANCHES" )
31+ if mainBranches == "" {
32+ mainBranches = "master,main"
33+ }
34+
35+ branches := strings .Split (mainBranches , "," )
36+ for i , branch := range branches {
37+ branches [i ] = strings .TrimSpace (branch )
38+ }
39+
40+ return branches
41+ }
42+
43+ // getPrimaryMainBranch returns the primary main branch from environment variable or default
44+ func getPrimaryMainBranch () string {
45+ if branch := os .Getenv ("DEFAULT_MAIN_BRANCH" ); branch != "" {
46+ return strings .TrimSpace (branch )
47+ }
48+
49+ // Return first main branch from the list
50+ mainBranches := getMainBranches ()
51+ if len (mainBranches ) > 0 {
52+ return mainBranches [0 ]
53+ }
54+
55+ return "master"
56+ }
57+
2758// getDefaultBranch returns the default branch name, checking environment variables first
2859func getDefaultBranch () string {
2960 if branch := os .Getenv ("GITHUB_REF_NAME" ); branch != "" {
@@ -368,13 +399,14 @@ update history, and create GitHub PR comment if in PR context.`,
368399
369400 trendData , err := tracker .GetTrend (historyCtx , history .WithTrendBranch (branch ), history .WithTrendDays (30 ))
370401
371- // If no history for current branch and it's not master, try to get master branch history
372- if (err != nil || trendData == nil || trendData .Summary .TotalEntries == 0 ) && branch != "master" {
373- cmd .Printf (" 📊 No history for branch '%s', checking master branch...\n " , branch )
374- if masterTrendData , masterErr := tracker .GetTrend (historyCtx , history .WithTrendBranch ("master" ), history .WithTrendDays (30 )); masterErr == nil && masterTrendData != nil {
375- // Use master branch data for comparison
376- trendData = masterTrendData
377- cmd .Printf (" ✅ Found %d history entries from master branch\n " , trendData .Summary .TotalEntries )
402+ // If no history for current branch and it's not a main branch, try to get primary main branch history
403+ primaryMainBranch := getPrimaryMainBranch ()
404+ if (err != nil || trendData == nil || trendData .Summary .TotalEntries == 0 ) && branch != primaryMainBranch {
405+ cmd .Printf (" 📊 No history for branch '%s', checking %s branch...\n " , branch , primaryMainBranch )
406+ if mainTrendData , mainErr := tracker .GetTrend (historyCtx , history .WithTrendBranch (primaryMainBranch ), history .WithTrendDays (30 )); mainErr == nil && mainTrendData != nil {
407+ // Use primary main branch data for comparison
408+ trendData = mainTrendData
409+ cmd .Printf (" ✅ Found %d history entries from %s branch\n " , trendData .Summary .TotalEntries , primaryMainBranch )
378410 }
379411 }
380412
0 commit comments