forked from forgejo/forgejo
Language statistics bar for repositories (#8037)
* Implementation for calculating language statistics Impement saving code language statistics to database Implement rendering langauge stats Add primary laguage to show in repository list Implement repository stats indexer queue Add indexer test Refactor to use queue module * Do not timeout for queues
This commit is contained in:
parent
37892be635
commit
ad2642a8aa
89 changed files with 182950 additions and 57 deletions
35
vendor/github.com/src-d/enry/v2/data/heuristics.go
generated
vendored
Normal file
35
vendor/github.com/src-d/enry/v2/data/heuristics.go
generated
vendored
Normal file
|
@ -0,0 +1,35 @@
|
|||
package data
|
||||
|
||||
import "github.com/src-d/enry/v2/data/rule"
|
||||
|
||||
// Heuristics implements a rule-based content matching engine.
|
||||
|
||||
// Heuristics is a number of sequntially applied rule.Heuristic where a
|
||||
// matching one disambiguages language(s) for a single file extension.
|
||||
type Heuristics []rule.Heuristic
|
||||
|
||||
// Match returns languages identified by the matching rule of the heuristic.
|
||||
func (hs Heuristics) Match(data []byte) []string {
|
||||
var matchedLangs []string
|
||||
for _, heuristic := range hs {
|
||||
if heuristic.Match(data) {
|
||||
for _, langOrAlias := range heuristic.Languages() {
|
||||
lang, ok := LanguageByAlias(langOrAlias)
|
||||
if !ok { // should never happen
|
||||
// reaching here means language name/alias in heuristics.yml
|
||||
// is not consistent with languages.yml
|
||||
// but we do not surface any such error at the API
|
||||
continue
|
||||
}
|
||||
matchedLangs = append(matchedLangs, lang)
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
return matchedLangs
|
||||
}
|
||||
|
||||
// matchString is a convenience used only in tests.
|
||||
func (hs *Heuristics) matchString(data string) []string {
|
||||
return hs.Match([]byte(data))
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue