forked from metafates/mangal
-
Notifications
You must be signed in to change notification settings - Fork 1
/
collector.go
43 lines (36 loc) 路 920 Bytes
/
collector.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package installer
import (
"github.com/belphemur/mangal/key"
"github.com/belphemur/mangal/util"
"github.com/samber/lo"
"github.com/spf13/viper"
"path/filepath"
)
var collector *githubFilesCollector
// Scrapers gets available scrapers from GitHub repo.
// See https://github.com/metafates/mangal-scrapers
func Scrapers() ([]*Scraper, error) {
if collector == nil {
setupCollector()
}
err := collector.collect()
if err != nil {
return nil, err
}
return lo.FilterMap(collector.Files, func(f *GithubFile, _ int) (*Scraper, bool) {
if filepath.Ext(f.Path) != ".lua" {
return nil, false
}
return &Scraper{
Name: util.FileStem(filepath.Base(f.Path)),
URL: f.Url,
}, true
}), nil
}
func setupCollector() {
collector = &githubFilesCollector{
user: viper.GetString(key.InstallerUser),
repo: viper.GetString(key.InstallerRepo),
branch: viper.GetString(key.InstallerBranch),
}
}