@@ -55,26 +55,38 @@ func (stats LanguageStatList) getLanguagePercentages() map[string]float32 {
55
55
langPerc := make (map [string ]float32 )
56
56
var otherPerc float32 = 100
57
57
var total int64
58
+ // Check that repository has at least one non-special language
59
+ var skipSpecial bool
58
60
for _ , stat := range stats {
59
- // Exclude specific languages from percentage calculation
60
- if _ , ok := specialLanguages [ stat . Language ]; ok && len ( stats ) > 1 {
61
- continue
61
+ if _ , ok := specialLanguages [ stat . Language ]; ! ok {
62
+ skipSpecial = true
63
+ break
62
64
}
63
- total += stat .Size
64
65
}
65
66
for _ , stat := range stats {
66
67
// Exclude specific languages from percentage calculation
67
- if _ , ok := specialLanguages [stat .Language ]; ok && len ( stats ) > 1 {
68
+ if _ , ok := specialLanguages [stat .Language ]; ok && skipSpecial {
68
69
continue
69
70
}
70
- perc := float32 (math .Round (float64 (stat .Size )/ float64 (total )* 1000 ) / 10 )
71
- if perc <= 0.1 {
72
- continue
71
+ total += stat .Size
72
+ }
73
+ if total > 0 {
74
+ for _ , stat := range stats {
75
+ // Exclude specific languages from percentage calculation
76
+ if _ , ok := specialLanguages [stat .Language ]; ok && skipSpecial {
77
+ continue
78
+ }
79
+ perc := float32 (math .Round (float64 (stat .Size )/ float64 (total )* 1000 ) / 10 )
80
+ if perc <= 0.1 {
81
+ continue
82
+ }
83
+ otherPerc -= perc
84
+ langPerc [stat .Language ] = perc
73
85
}
74
- otherPerc -= perc
75
- langPerc [stat .Language ] = perc
86
+ otherPerc = float32 (math .Round (float64 (otherPerc )* 10 ) / 10 )
87
+ } else {
88
+ otherPerc = 100
76
89
}
77
- otherPerc = float32 (math .Round (float64 (otherPerc )* 10 ) / 10 )
78
90
if otherPerc > 0 {
79
91
langPerc ["other" ] = otherPerc
80
92
}
0 commit comments