@@ -264,17 +264,65 @@ func (c *Config) GetBadgeURL() string {
264264 if c .GitHub .Owner == "" || c .GitHub .Repository == "" {
265265 return ""
266266 }
267- return fmt .Sprintf ("https://raw.githubusercontent.com/%s/%s/main/%s/%s" ,
268- c .GitHub .Owner , c .GitHub .Repository , c .Storage .BaseDir , c .Badge .OutputFile )
267+
268+ // Use GitHub Pages URL structure
269+ baseURL := fmt .Sprintf ("https://%s.github.io/%s" , c .GitHub .Owner , c .GitHub .Repository )
270+
271+ // If in PR context, return PR-specific badge URL
272+ if c .IsPullRequestContext () {
273+ return fmt .Sprintf ("%s/badges/pr/%d/coverage.svg" , baseURL , c .GitHub .PullRequest )
274+ }
275+
276+ // For branch-specific badges, get current branch (default to master)
277+ branch := c .getCurrentBranch ()
278+ if branch == "master" || branch == "main" {
279+ // Main branch badge at root badges directory
280+ return fmt .Sprintf ("%s/badges/coverage.svg" , baseURL )
281+ }
282+
283+ // Branch-specific badge
284+ return fmt .Sprintf ("%s/badges/%s/coverage.svg" , baseURL , branch )
269285}
270286
271287// GetReportURL returns the URL for the coverage report
272288func (c * Config ) GetReportURL () string {
273289 if c .GitHub .Owner == "" || c .GitHub .Repository == "" {
274290 return ""
275291 }
276- return fmt .Sprintf ("https://raw.githubusercontent.com/%s/%s/main/%s/%s" ,
277- c .GitHub .Owner , c .GitHub .Repository , c .Storage .BaseDir , c .Report .OutputFile )
292+
293+ // Use GitHub Pages URL structure
294+ baseURL := fmt .Sprintf ("https://%s.github.io/%s" , c .GitHub .Owner , c .GitHub .Repository )
295+
296+ // If in PR context, return PR-specific report URL
297+ if c .IsPullRequestContext () {
298+ return fmt .Sprintf ("%s/reports/pr/%d/coverage.html" , baseURL , c .GitHub .PullRequest )
299+ }
300+
301+ // For branch-specific reports, get current branch (default to master)
302+ branch := c .getCurrentBranch ()
303+ if branch == "master" || branch == "main" {
304+ // Main branch report at root coverage directory
305+ return fmt .Sprintf ("%s/coverage/" , baseURL )
306+ }
307+
308+ // Branch-specific report
309+ return fmt .Sprintf ("%s/reports/branch/%s/coverage.html" , baseURL , branch )
310+ }
311+
312+ // getCurrentBranch returns the current branch name, defaulting to master
313+ func (c * Config ) getCurrentBranch () string {
314+ // Try to get branch from environment variables (GitHub Actions context)
315+ if branch := os .Getenv ("GITHUB_REF_NAME" ); branch != "" {
316+ return branch
317+ }
318+ if ref := os .Getenv ("GITHUB_REF" ); ref != "" {
319+ // Extract branch name from refs/heads/branch-name
320+ if strings .HasPrefix (ref , "refs/heads/" ) {
321+ return strings .TrimPrefix (ref , "refs/heads/" )
322+ }
323+ }
324+ // Default to master (this repo's default branch)
325+ return "master"
278326}
279327
280328// Helper functions for environment variable parsing
0 commit comments