mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-06-08 23:57:39 +00:00
fix: use linguist-generated
for language stats (#7685)
Some checks are pending
/ release (push) Waiting to run
testing / backend-checks (push) Has been skipped
testing / frontend-checks (push) Has been skipped
testing / test-unit (push) Has been skipped
testing / test-e2e (push) Has been skipped
testing / test-mysql (push) Has been skipped
testing / test-pgsql (push) Has been skipped
testing / test-sqlite (push) Has been skipped
testing / test-remote-cacher (redis) (push) Has been skipped
testing / test-remote-cacher (valkey) (push) Has been skipped
testing / test-remote-cacher (garnet) (push) Has been skipped
testing / test-remote-cacher (redict) (push) Has been skipped
testing / security-check (push) Has been skipped
Some checks are pending
/ release (push) Waiting to run
testing / backend-checks (push) Has been skipped
testing / frontend-checks (push) Has been skipped
testing / test-unit (push) Has been skipped
testing / test-e2e (push) Has been skipped
testing / test-mysql (push) Has been skipped
testing / test-pgsql (push) Has been skipped
testing / test-sqlite (push) Has been skipped
testing / test-remote-cacher (redis) (push) Has been skipped
testing / test-remote-cacher (valkey) (push) Has been skipped
testing / test-remote-cacher (garnet) (push) Has been skipped
testing / test-remote-cacher (redict) (push) Has been skipped
testing / security-check (push) Has been skipped
- Adds code comment to explain behavior of the `linguist-generated` gitattribute. - Adjusts the code to ignore the file if `linguist-generated` is true. - Resolves forgejo/forgejo#7677 - Adds unit testing. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/7685 Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org> Co-authored-by: Gusted <postmaster@gusted.xyz> Co-committed-by: Gusted <postmaster@gusted.xyz>
This commit is contained in:
parent
055fc6e0c3
commit
31cd8c6d38
23 changed files with 18 additions and 6 deletions
|
@ -204,7 +204,13 @@ func (repo *Repository) GetLanguageStats(commitID string) (map[string]int64, err
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !isTrue(isGenerated) && enry.IsGenerated(f.Name(), content) {
|
|
||||||
|
// We consider three cases:
|
||||||
|
// 1. linguist-generated=true, then we ignore the file.
|
||||||
|
// 2. linguist-generated=false, we don't ignore the file.
|
||||||
|
// 3. linguist-generated is not set, then `enry.IsGenerated` determines if the file is generated.
|
||||||
|
if isTrue(isGenerated) || !isFalse(isGenerated) && enry.IsGenerated(f.Name(), content) {
|
||||||
|
log.Trace("Ignore %q for language stats, because it is generated", f.Name())
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,15 @@ func TestRepository_GetLanguageStats(t *testing.T) {
|
||||||
"Python": 134,
|
"Python": 134,
|
||||||
"Java": 112,
|
"Java": 112,
|
||||||
}, stats)
|
}, stats)
|
||||||
|
|
||||||
|
stats, err = gitRepo.GetLanguageStats("95d3505f2db273e40be79f84416051ae85e9ea0d")
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
assert.Equal(t, map[string]int64{
|
||||||
|
"Cobra": 67,
|
||||||
|
"Python": 67,
|
||||||
|
"Java": 112,
|
||||||
|
}, stats)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMergeLanguageStats(t *testing.T) {
|
func TestMergeLanguageStats(t *testing.T) {
|
||||||
|
|
Binary file not shown.
|
@ -1,2 +0,0 @@
|
||||||
0000000000000000000000000000000000000000 8fee858da5796dfb37704761701bb8e800ad9ef3 Andrew Thornton <art27@cantab.net> 1632140318 +0100 commit (initial): Add some test files for GetLanguageStats
|
|
||||||
8fee858da5796dfb37704761701bb8e800ad9ef3 341fca5b5ea3de596dc483e54c2db28633cd2f97 oliverpool <git@olivier.pfad.fr> 1711278775 +0100 push
|
|
|
@ -1,2 +0,0 @@
|
||||||
0000000000000000000000000000000000000000 8fee858da5796dfb37704761701bb8e800ad9ef3 Andrew Thornton <art27@cantab.net> 1632140318 +0100 commit (initial): Add some test files for GetLanguageStats
|
|
||||||
8fee858da5796dfb37704761701bb8e800ad9ef3 341fca5b5ea3de596dc483e54c2db28633cd2f97 oliverpool <git@olivier.pfad.fr> 1711278775 +0100 push
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
2
modules/git/tests/repos/language_stats_repo/packed-refs
Normal file
2
modules/git/tests/repos/language_stats_repo/packed-refs
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
# pack-refs with: peeled fully-peeled sorted
|
||||||
|
95d3505f2db273e40be79f84416051ae85e9ea0d refs/heads/master
|
|
@ -1 +0,0 @@
|
||||||
341fca5b5ea3de596dc483e54c2db28633cd2f97
|
|
Loading…
Add table
Add a link
Reference in a new issue