From 95fe5fb628f9247d648a202eea721f91b269f0f4 Mon Sep 17 00:00:00 2001 From: CirnoT <1447794+CirnoT@users.noreply.github.com> Date: Fri, 29 May 2020 10:48:11 +0200 Subject: [PATCH 1/3] Exclude certain languages from repo stats --- modules/git/repo_language_stats.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/modules/git/repo_language_stats.go b/modules/git/repo_language_stats.go index 8ff8fa20c1f6a..7a359aa2a7d75 100644 --- a/modules/git/repo_language_stats.go +++ b/modules/git/repo_language_stats.go @@ -20,6 +20,16 @@ import ( const fileSizeLimit int64 = 16 * 1024 * 1024 +// specialLanguages defines list of languages that are excluded from calculation +// unless they are the only language present in repository +var specialLanguages = []string{ + "YAML", + "JSON", + "SVG", + "Text", + "Markdown", +} + // 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) @@ -72,6 +82,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 { From d636cbae20797e73cf6e8906bc70fa057ef3656b Mon Sep 17 00:00:00 2001 From: Cirno the Strongest <1447794+CirnoT@users.noreply.github.com> Date: Fri, 29 May 2020 15:11:29 +0200 Subject: [PATCH 2/3] Update modules/git/repo_language_stats.go Co-authored-by: silverwind --- modules/git/repo_language_stats.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/git/repo_language_stats.go b/modules/git/repo_language_stats.go index 7a359aa2a7d75..d99ca275eeae9 100644 --- a/modules/git/repo_language_stats.go +++ b/modules/git/repo_language_stats.go @@ -20,8 +20,9 @@ import ( const fileSizeLimit int64 = 16 * 1024 * 1024 -// specialLanguages defines list of languages that are excluded from calculation -// unless they are the only language present in repository +// 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", From e165b34a9d981f8affdddca3d84f12eae5b43ad5 Mon Sep 17 00:00:00 2001 From: Cirno the Strongest <1447794+CirnoT@users.noreply.github.com> Date: Fri, 29 May 2020 16:25:15 +0200 Subject: [PATCH 3/3] Add TOML --- modules/git/repo_language_stats.go | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/git/repo_language_stats.go b/modules/git/repo_language_stats.go index d99ca275eeae9..2e5a0534c4510 100644 --- a/modules/git/repo_language_stats.go +++ b/modules/git/repo_language_stats.go @@ -29,6 +29,7 @@ var specialLanguages = []string{ "SVG", "Text", "Markdown", + "TOML", } // GetLanguageStats calculates language stats for git repository at specified commit