Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude certain languages from repo stats #11672

Closed
wants to merge 3 commits into from
Closed
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
20 changes: 20 additions & 0 deletions modules/git/repo_language_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@ import (

const fileSizeLimit int64 = 16 * 1024 * 1024

// specialLanguages defines list of languages that are excluded from the calculation
// unless they are the only language present in repository. Only languages which under
// normal circumstances are not considered to be code should be listed here.
var specialLanguages = []string{
"YAML",
"JSON",
"SVG",
"Text",
"Markdown",
"TOML",
}

// GetLanguageStats calculates language stats for git repository at specified commit
func (repo *Repository) GetLanguageStats(commitID string) (map[string]float32, error) {
r, err := git.PlainOpen(repo.Path)
Expand Down Expand Up @@ -72,6 +84,14 @@ func (repo *Repository) GetLanguageStats(commitID string) (map[string]float32, e
return nil, err
}

// filter special languages unless they are the only language
if len(sizes) > 1 {
for _, language := range specialLanguages {
total -= sizes[language]
delete(sizes, language)
}
}

stats := make(map[string]float32)
var otherPerc float32 = 100
for language, size := range sizes {
Expand Down