Skip to content

Commit 1307e78

Browse files
authored
[FEAT] Dir Sync Support (#11)
Full Directory Sync Support MVP
1 parent 4112dcd commit 1307e78

158 files changed

Lines changed: 29413 additions & 948 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/.env.shared

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ AUTO_MERGE_SKIP_BOT_PRS=true # Skip bot PRs
137137
# ENV: Internal Coverage System Configuration
138138
# ───────────────────────────────────────────────────────────────────────────────
139139
ENABLE_INTERNAL_COVERAGE=true # Enable internal coverage system (replaces Codecov)
140+
COVERAGE_TARGET_LIMIT_KB=1000 # Target size limit in KB for optimal performance
141+
COVERAGE_WARNING_LIMIT_KB=2500 # Warning threshold in KB for size monitoring
142+
COVERAGE_HARD_LIMIT_KB=5000 # Hard limit in KB for maximum allowable size
140143
COVERAGE_BADGE_STYLE=flat # Badge style: flat, flat-square, for-the-badge
141144
COVERAGE_BADGE_LABEL=coverage # Badge label text
142145
COVERAGE_BADGE_LOGO= # Badge logo: go, github, custom URL (empty for no logo)
@@ -198,6 +201,12 @@ COVERAGE_ERROR_RATE=0 # Error injection rate (0-1)
198201
# ───────────────────────────────────────────────────────────────────────────────
199202
GOOGLE_ANALYTICS_ID=G-VKFVWG6GXM # Google Analytics tracking ID for coverage dashboard/reports
200203

204+
# ───────────────────────────────────────────────────────────────────────────────
205+
# ENV: Main Branch Configuration
206+
# ───────────────────────────────────────────────────────────────────────────────
207+
MAIN_BRANCHES=master,main # Comma-separated list of protected main branches
208+
DEFAULT_MAIN_BRANCH=master # Primary main branch for this project
209+
201210
# ───────────────────────────────────────────────────────────────────────────────
202211
# ENV: Pull Request Management Workflow Configuration
203212
# ───────────────────────────────────────────────────────────────────────────────
@@ -208,7 +217,7 @@ PR_MANAGEMENT_APPLY_SIZE_LABELS=true # Apply size la
208217
PR_MANAGEMENT_APPLY_TYPE_LABELS=true # Apply type labels based on branch/title
209218
PR_MANAGEMENT_CLEAN_CACHE_ON_CLOSE=true # Clean runner cache when PR closes
210219
PR_MANAGEMENT_DELETE_BRANCH_ON_MERGE=true # Delete source branch after merge
211-
PR_MANAGEMENT_PROTECTED_BRANCHES=master,main,development # Branches that should never be deleted
220+
PR_MANAGEMENT_PROTECTED_BRANCHES=${MAIN_BRANCHES},development # Branches that should never be deleted
212221
PR_MANAGEMENT_SIZE_XS_THRESHOLD=10 # Max changes for XS size label
213222
PR_MANAGEMENT_SIZE_S_THRESHOLD=50 # Max changes for S size label
214223
PR_MANAGEMENT_SIZE_M_THRESHOLD=200 # Max changes for M size label

.github/coverage/cmd/gofortress-coverage/cmd/comment.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ Features:
126126
// Get latest entry to compare
127127
branch := cfg.GitHub.CommitSHA
128128
if branch == "" {
129-
branch = "main"
129+
branch = "master"
130130
}
131131

132132
if latest, latestErr := tracker.GetLatestEntry(ctx, branch); latestErr == nil {
@@ -189,7 +189,7 @@ Features:
189189
comparisonEngine := analysis.NewComparisonEngine(nil)
190190

191191
// Convert parser data to comparison snapshots
192-
baseSnapshot := convertToSnapshot(baseCoverage, "main", "")
192+
baseSnapshot := convertToSnapshot(baseCoverage, "master", "")
193193
prSnapshot := convertToSnapshot(coverage, "current", cfg.GitHub.CommitSHA)
194194

195195
comparisonResult, compErr := comparisonEngine.CompareCoverage(ctx, baseSnapshot, prSnapshot)
@@ -203,7 +203,7 @@ Features:
203203
TotalStatements: baseCoverage.TotalLines, // Actually statement count, not line count
204204
CoveredStatements: baseCoverage.CoveredLines, // Actually covered statement count, not line count
205205
CommitSHA: "",
206-
Branch: "main",
206+
Branch: "master",
207207
Timestamp: time.Now(),
208208
},
209209
PRCoverage: github.CoverageData{
@@ -344,7 +344,7 @@ Features:
344344
PRNumber: prNumber,
345345
Branch: "current",
346346
CommitSHA: cfg.GitHub.CommitSHA,
347-
BaseBranch: "main",
347+
BaseBranch: "master",
348348
Coverage: coverage.Percentage,
349349
BaseCoverage: comparison.BaseCoverage.Percentage,
350350
Trend: determineBadgeTrend(comparison.TrendAnalysis.Direction),
@@ -419,7 +419,7 @@ Features:
419419
CommitSHA: cfg.GitHub.CommitSHA,
420420
PRNumber: prNumber,
421421
Branch: "current",
422-
BaseBranch: "main",
422+
BaseBranch: "master",
423423
Coverage: github.CoverageStatusData{
424424
Percentage: coverage.Percentage,
425425
TotalStatements: coverage.TotalLines,
@@ -527,14 +527,14 @@ func buildTemplateData(cfg *config.Config, prNumber int, comparison *github.Cove
527527
Repository: templates.RepositoryInfo{
528528
Owner: cfg.GitHub.Owner,
529529
Name: cfg.GitHub.Repository,
530-
DefaultBranch: "main",
530+
DefaultBranch: "master",
531531
URL: fmt.Sprintf("https://github.com/%s/%s", cfg.GitHub.Owner, cfg.GitHub.Repository),
532532
},
533533
PullRequest: templates.PullRequestInfo{
534534
Number: prNumber,
535535
Title: "",
536536
Branch: "current",
537-
BaseBranch: "main",
537+
BaseBranch: "master",
538538
Author: "",
539539
CommitSHA: cfg.GitHub.CommitSHA,
540540
URL: fmt.Sprintf("https://github.com/%s/%s/pull/%d", cfg.GitHub.Owner, cfg.GitHub.Repository, prNumber),

.github/coverage/cmd/gofortress-coverage/cmd/comment_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,12 +229,12 @@ func TestBuildTemplateData(t *testing.T) {
229229
require.NotNil(t, result)
230230
require.Equal(t, "testowner", result.Repository.Owner)
231231
require.Equal(t, "testrepo", result.Repository.Name)
232-
require.Equal(t, "main", result.Repository.DefaultBranch)
232+
require.Equal(t, "master", result.Repository.DefaultBranch)
233233
require.Equal(t, "https://github.com/testowner/testrepo", result.Repository.URL)
234234

235235
require.Equal(t, prNumber, result.PullRequest.Number)
236236
require.Equal(t, "current", result.PullRequest.Branch)
237-
require.Equal(t, "main", result.PullRequest.BaseBranch)
237+
require.Equal(t, "master", result.PullRequest.BaseBranch)
238238
require.Equal(t, cfg.GitHub.CommitSHA, result.PullRequest.CommitSHA)
239239
require.Equal(t, "https://github.com/testowner/testrepo/pull/123", result.PullRequest.URL)
240240

.github/coverage/cmd/gofortress-coverage/cmd/complete.go

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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
2859
func 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

.github/coverage/cmd/gofortress-coverage/cmd/integration_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ func TestHistoryCommand(t *testing.T) {
491491
setupHistoryCmd.Flags().StringP("format", "f", "text", "Output format (text, json)")
492492

493493
addCmd.AddCommand(setupHistoryCmd)
494-
addCmd.SetArgs([]string{"history", "--add", coverageFile, "--branch", "main", "--commit", "abc123"})
494+
addCmd.SetArgs([]string{"history", "--add", coverageFile, "--branch", "master", "--commit", "abc123"})
495495
var addBuf bytes.Buffer
496496
addCmd.SetOut(&addBuf)
497497
addCmd.SetErr(&addBuf)
@@ -510,13 +510,13 @@ func TestHistoryCommand(t *testing.T) {
510510
args: []string{
511511
"history",
512512
"--add", coverageFile,
513-
"--branch", "main",
513+
"--branch", "master",
514514
"--commit", "abc123",
515515
},
516516
expectError: false,
517517
contains: []string{
518518
"Coverage recorded successfully!",
519-
"Branch: main",
519+
"Branch: master",
520520
"Commit: abc123",
521521
},
522522
envVars: map[string]string{
@@ -544,13 +544,13 @@ func TestHistoryCommand(t *testing.T) {
544544
args: []string{
545545
"history",
546546
"--trend",
547-
"--branch", "main",
547+
"--branch", "master",
548548
"--days", "30",
549549
},
550550
expectError: false,
551551
contains: []string{
552552
"Coverage Trend Analysis",
553-
"Branch: main",
553+
"Branch: master",
554554
"Period: 30 days",
555555
},
556556
envVars: map[string]string{
@@ -562,12 +562,12 @@ func TestHistoryCommand(t *testing.T) {
562562
name: "show latest entry",
563563
args: []string{
564564
"history",
565-
"--branch", "main",
565+
"--branch", "master",
566566
},
567567
expectError: false,
568568
contains: []string{
569569
"Latest Coverage Entry",
570-
"Branch: main",
570+
"Branch: master",
571571
},
572572
envVars: map[string]string{
573573
"COVERAGE_HISTORY_PATH": historyDir,
@@ -925,7 +925,7 @@ func TestCompleteCommand(t *testing.T) {
925925
testCompleteCmd := &cobra.Command{
926926
Use: "complete",
927927
Short: "Run complete coverage pipeline",
928-
Long: `Run the complete coverage pipeline: parse coverage, generate badge and report,
928+
Long: `Run the complete coverage pipeline: parse coverage, generate badge and report,
929929
update history, and create GitHub PR comment if in PR context.`,
930930
RunE: completeCmd.RunE,
931931
}

.github/coverage/docs/coverage-api.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ Flags:
282282
##### `history analyze`
283283
```bash
284284
Flags:
285-
--branch string Branch to analyze (default: "main")
285+
--branch string Branch to analyze (default: "master")
286286
--days int Days of history to analyze (default: 30)
287287
--output string Output analysis file
288288
--format string Output format: json, yaml, table (default: "json")
@@ -291,7 +291,7 @@ Flags:
291291
##### `history predict`
292292
```bash
293293
Flags:
294-
--branch string Branch to predict for (default: "main")
294+
--branch string Branch to predict for (default: "master")
295295
--horizon int Prediction horizon in days (default: 7)
296296
--model string Prediction model: linear, polynomial, seasonal (default: "linear")
297297
--confidence float Confidence interval (default: 0.95)
@@ -379,7 +379,7 @@ gofortress-coverage analytics dashboard [flags]
379379

380380
Flags:
381381
--output string Output directory (default: "analytics")
382-
--branch string Branch to analyze (default: "main")
382+
--branch string Branch to analyze (default: "master")
383383
--days int Days of data to include (default: 90)
384384
--theme string Dashboard theme (default: "github-dark")
385385
--include-team Include team analytics
@@ -399,7 +399,7 @@ Examples:
399399
gofortress-coverage analytics trends [flags]
400400

401401
Flags:
402-
--branch string Branch to analyze (default: "main")
402+
--branch string Branch to analyze (default: "master")
403403
--days int Days of history (default: 30)
404404
--output string Output file for trend data
405405
--chart Generate trend chart
@@ -480,7 +480,7 @@ GET /api/coverage.json?branch=main
480480
```json
481481
{
482482
"overall_coverage": 87.2,
483-
"branch": "main",
483+
"branch": "master",
484484
"commit": "abc123def456",
485485
"timestamp": "2025-01-27T10:30:00Z",
486486
"quality_score": 92,
@@ -514,7 +514,7 @@ GET /api/history.json?branch=main&days=30
514514
**Response:**
515515
```json
516516
{
517-
"branch": "main",
517+
"branch": "master",
518518
"period": {
519519
"start": "2024-12-28T00:00:00Z",
520520
"end": "2025-01-27T00:00:00Z",
@@ -552,7 +552,7 @@ GET /api/analytics.json?branch=main
552552
**Response:**
553553
```json
554554
{
555-
"branch": "main",
555+
"branch": "master",
556556
"generated_at": "2025-01-27T10:30:00Z",
557557
"quality_assessment": {
558558
"overall_score": 92,
@@ -869,4 +869,4 @@ gofortress-coverage parse --file coverage.out --log-level debug
869869
- **Issues**: Report bugs and request features via GitHub Issues
870870
- **Documentation**: Complete guides available in `/docs/` directory
871871
- **Contributing**: See [CONTRIBUTING.md](../CONTRIBUTING.md) for development guidelines
872-
- **CLI Help**: Use `gofortress-coverage --help` for command-specific help
872+
- **CLI Help**: Use `gofortress-coverage --help` for command-specific help

0 commit comments

Comments
 (0)