Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.claude
.serena
.mcp.json
commands.nu
/gh-oss-stats
scripts/
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Track and display your merged PRs, commits, and contributions to external reposi
- 🔍 **External Contribution Tracking** - Discovers all your merged PRs to repos you don't own
- 📊 **Comprehensive Stats** - Total PRs, commits, lines of code, and repository stars
- ⭐ **Smart Filtering** - Filter by minimum stars, exclude organizations
- 🎭 18 **Color Themes** - Match your profile's aesthetic
- 🎭 **18 Color Themes** - Match your profile's aesthetic
- 📦 **Developer-Friendly** - Use as a Go library or standalone CLI, outputs JSON


Expand Down Expand Up @@ -72,9 +72,9 @@ jobs:

### Run it manually
If you don't want to wait for the end of the week, you can run this action manually
1. G to `your github repo`
1. Go to your github repo
2. Click `actions` tab
3. On the left side, you shouls see your action named `Generate OSS Badge`, click on it
3. On the left side, you should see your action named `Generate OSS Badge`, click on it
4. Click on `run workflow` drop down, then click `run workflow`

That is it. It will run and generate the badge for you.
Expand Down
20 changes: 20 additions & 0 deletions cmd/gh-oss-stats/badgeConfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ type BadgeConfig struct {
output string
sort string
limit int
// Custom color overrides (empty = use theme default)
colorBackground string
colorBackgroundAlt string
colorText string
colorTextSecondary string
colorBorder string
colorAccent string
colorPositive string
colorNegative string
colorStar string
}

// newBadgeConfig creates a new BadgeConfig with default values
Expand All @@ -34,4 +44,14 @@ func (bf *BadgeConfig) registerBadgeFlags(fs *flag.FlagSet) {
fs.StringVar(&bf.output, "badge-output", "", "Badge output file (default: badge.svg)")
fs.StringVar(&bf.sort, "badge-sort", string(badge.DefaultSortBy), "Sort contributions by: prs, stars, commits")
fs.IntVar(&bf.limit, "badge-limit", badge.DefaultPRsLimit, "Number of contributions to show")

fs.StringVar(&bf.colorBackground, "badge-color-background", "", "Custom background color (hex, e.g. #1a1b26)")
fs.StringVar(&bf.colorBackgroundAlt, "badge-color-background-alt", "", "Custom alt background color (hex)")
fs.StringVar(&bf.colorText, "badge-color-text", "", "Custom primary text color (hex)")
fs.StringVar(&bf.colorTextSecondary, "badge-color-text-secondary", "", "Custom secondary text color (hex)")
fs.StringVar(&bf.colorBorder, "badge-color-border", "", "Custom border color (hex)")
fs.StringVar(&bf.colorAccent, "badge-color-accent", "", "Custom accent/brand color (hex)")
fs.StringVar(&bf.colorPositive, "badge-color-positive", "", "Custom positive/additions color (hex)")
fs.StringVar(&bf.colorNegative, "badge-color-negative", "", "Custom negative/deletions color (hex)")
fs.StringVar(&bf.colorStar, "badge-color-star", "", "Custom star count color (hex)")
}
109 changes: 108 additions & 1 deletion cmd/gh-oss-stats/badgeConfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,115 @@ func TestBadgeConfigPointerReturn(t *testing.T) {

// Modifying bc1 should not affect bc2
bc1.style = "modified"

if bc2.style == "modified" {
t.Error("Modifying bc1 affected bc2; they should be independent instances")
}
}

func TestBadgeColorFlagsRegistered(t *testing.T) {
bc := newBadgeConfig()
fs := flag.NewFlagSet("test", flag.ContinueOnError)
bc.registerBadgeFlags(fs)

colorFlags := []string{
"badge-color-background",
"badge-color-background-alt",
"badge-color-text",
"badge-color-text-secondary",
"badge-color-border",
"badge-color-accent",
"badge-color-positive",
"badge-color-negative",
"badge-color-star",
}

for _, name := range colorFlags {
t.Run(name, func(t *testing.T) {
f := fs.Lookup(name)
if f == nil {
t.Errorf("flag --%s not registered", name)
return
}
if f.DefValue != "" {
t.Errorf("flag --%s default = %q, want %q", name, f.DefValue, "")
}
})
}
}

func TestBadgeColorFlagDefaults(t *testing.T) {
bc := newBadgeConfig()
fs := flag.NewFlagSet("test", flag.ContinueOnError)
bc.registerBadgeFlags(fs)

// Parse with no color flags — all color fields should remain empty
if err := fs.Parse([]string{}); err != nil {
t.Fatalf("Parse failed: %v", err)
}

fields := []struct {
name string
got string
}{
{"colorBackground", bc.colorBackground},
{"colorBackgroundAlt", bc.colorBackgroundAlt},
{"colorText", bc.colorText},
{"colorTextSecondary", bc.colorTextSecondary},
{"colorBorder", bc.colorBorder},
{"colorAccent", bc.colorAccent},
{"colorPositive", bc.colorPositive},
{"colorNegative", bc.colorNegative},
{"colorStar", bc.colorStar},
}

for _, f := range fields {
if f.got != "" {
t.Errorf("%s default = %q, want empty string", f.name, f.got)
}
}
}

func TestBadgeColorFlagsParsed(t *testing.T) {
bc := newBadgeConfig()
fs := flag.NewFlagSet("test", flag.ContinueOnError)
bc.registerBadgeFlags(fs)

args := []string{
"--badge-color-background", "#0d1117",
"--badge-color-background-alt", "#161b22",
"--badge-color-text", "#c9d1d9",
"--badge-color-text-secondary", "#8b949e",
"--badge-color-border", "#30363d",
"--badge-color-accent", "#58a6ff",
"--badge-color-positive", "#3fb950",
"--badge-color-negative", "#f85149",
"--badge-color-star", "#e3b341",
}

if err := fs.Parse(args); err != nil {
t.Fatalf("Parse failed: %v", err)
}

tests := []struct {
name string
got string
want string
}{
{"colorBackground", bc.colorBackground, "#0d1117"},
{"colorBackgroundAlt", bc.colorBackgroundAlt, "#161b22"},
{"colorText", bc.colorText, "#c9d1d9"},
{"colorTextSecondary", bc.colorTextSecondary, "#8b949e"},
{"colorBorder", bc.colorBorder, "#30363d"},
{"colorAccent", bc.colorAccent, "#58a6ff"},
{"colorPositive", bc.colorPositive, "#3fb950"},
{"colorNegative", bc.colorNegative, "#f85149"},
{"colorStar", bc.colorStar, "#e3b341"},
}

for _, tt := range tests {
if tt.got != tt.want {
t.Errorf("%s = %q, want %q", tt.name, tt.got, tt.want)
}
}
}
61 changes: 56 additions & 5 deletions cmd/gh-oss-stats/badgeGeneration.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,21 @@ package main
import (
"fmt"
"os"
"regexp"

"github.com/mabd-dev/gh-oss-stats/pkg/ossstats"
"github.com/mabd-dev/gh-oss-stats/pkg/ossstats/badge"
)

var hexColorRE = regexp.MustCompile(`^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$`)

func validateHexColor(flag, value string) error {
if !hexColorRE.MatchString(value) {
return fmt.Errorf("invalid color for --%s: %q (expected hex format, e.g. #rgb, #rrggbb, #rrggbbaa)", flag, value)
}
return nil
}

func createBadgeOptions(conf BadgeConfig) (badge.BadgeOptions, error) {
badgeStyle, err := badge.BadgeStyleFromName(conf.style)
if err != nil {
Expand All @@ -33,12 +43,53 @@ func createBadgeOptions(conf BadgeConfig) (badge.BadgeOptions, error) {
os.Exit(1)
}

colorFlags := []struct {
flag string
value string
}{
{"badge-color-background", conf.colorBackground},
{"badge-color-background-alt", conf.colorBackgroundAlt},
{"badge-color-text", conf.colorText},
{"badge-color-text-secondary", conf.colorTextSecondary},
{"badge-color-border", conf.colorBorder},
{"badge-color-accent", conf.colorAccent},
{"badge-color-positive", conf.colorPositive},
{"badge-color-negative", conf.colorNegative},
{"badge-color-star", conf.colorStar},
}
for _, cf := range colorFlags {
if cf.value != "" {
if err := validateHexColor(cf.flag, cf.value); err != nil {
return badge.BadgeOptions{}, err
}
}
}

var customColors *badge.ThemeColors
if conf.colorBackground != "" || conf.colorBackgroundAlt != "" ||
conf.colorText != "" || conf.colorTextSecondary != "" ||
conf.colorBorder != "" || conf.colorAccent != "" ||
conf.colorPositive != "" || conf.colorNegative != "" || conf.colorStar != "" {
customColors = &badge.ThemeColors{
Background: conf.colorBackground,
BackgroundAlt: conf.colorBackgroundAlt,
Text: conf.colorText,
TextSecondary: conf.colorTextSecondary,
Border: conf.colorBorder,
Accent: conf.colorAccent,
Positive: conf.colorPositive,
Negative: conf.colorNegative,
Star: conf.colorStar,
}
}

return badge.BadgeOptions{
Style: badgeStyle,
Variant: badgeVariant,
Theme: badgeTheme,
SortBy: badgeSortBy,
Limit: conf.limit,
Style: badgeStyle,
Variant: badgeVariant,
Theme: badgeTheme,
SortBy: badgeSortBy,
Limit: conf.limit,
CustomColors: customColors,
}, nil
}

Expand Down
Loading
Loading