Commit 7a73aee9 authored by Ma_124's avatar Ma_124

added --gh-token and --gh-max-reqs

parent 7d45710d
Pipeline #45133888 failed with stages
in 52 seconds
......@@ -87,6 +87,8 @@ type OutputCfg struct {
func mainCompile() {
flag := flagpkg.NewFlagSet("awesome compile", flagpkg.ExitOnError)
cfgFile := flag.String("config", "awesome.toml", "path of a config file as described at <https://godoc.org/gitlab.com/Ma_124/awesome-framework/cmd/awesome>")
ghAccessToken := flag.String("gh-token", "", "Generate one at https://github.com/settings/tokens")
ghMaxRequests := flag.Int("gh-max-reqs", 6000, "Only for development.")
flag.Parse(os.Args[2:])
cfgData, err := ioutil.ReadFile(*cfgFile)
......@@ -246,7 +248,9 @@ func mainCompile() {
return
}
awesomefw.CompileFile(list.Input.File, outF, iff, off)
awesomefw.CompileFile(list.Input.File, outF, iff, off, &awesomefw.ApisCfg{
&awesomefw.ApiCfg{ *ghAccessToken, *ghMaxRequests },
})
}()
}
......
......@@ -16,6 +16,7 @@ type Ctx struct {
InFFCtx map[string]interface{}
OutFFCtx map[string]interface{}
fetchMetaGhRequests int
ApisCfg *ApisCfg
}
type OutputFileFormat struct {
......@@ -23,7 +24,16 @@ type OutputFileFormat struct {
Item func(out io.Writer, name, url, desc string, ctx *Ctx)
}
func CompileFile(inpPath string, out io.Writer, inFF *InputFileFormat, outFF *OutputFileFormat) {
type ApisCfg struct {
GitHubCfg *ApiCfg
}
type ApiCfg struct {
AccessToken string
MaxRequests int
}
func CompileFile(inpPath string, out io.Writer, inFF *InputFileFormat, outFF *OutputFileFormat, apis *ApisCfg) {
fi, err := os.Stat(inpPath)
if err != nil {
panic(err)
......@@ -35,10 +45,10 @@ func CompileFile(inpPath string, out io.Writer, inFF *InputFileFormat, outFF *Ou
}
defer f.Close()
Compile(f, int(fi.Size()), out, inFF, outFF)
Compile(f, int(fi.Size()), out, inFF, outFF, apis)
}
func Compile(in io.Reader, size int, out io.Writer, inFF *InputFileFormat, outFF *OutputFileFormat) {
func Compile(in io.Reader, size int, out io.Writer, inFF *InputFileFormat, outFF *OutputFileFormat, apis *ApisCfg) {
pb := progressbar.New(size)
r := bufio.NewReader(in)
......@@ -48,6 +58,7 @@ func Compile(in io.Reader, size int, out io.Writer, inFF *InputFileFormat, outFF
InLiteral: false,
InFFCtx: make(map[string]interface{}),
OutFFCtx: make(map[string]interface{}),
ApisCfg: apis,
}
eofReached := false
......
......@@ -39,7 +39,7 @@ A curated list of awesome curated lists of many topics.
For contributing, [open an issue](https://github.com/emijrp/awesome-awesome/issues) and/or a [pull request](https://github.com/emijrp/awesome-awesome/pulls). Above there are some ideas for missing lists, be bold!
`[1:]
Compile(strings.NewReader(in), len(in), out, IFFMarkdown, OFFTabSep)
Compile(strings.NewReader(in), len(in), out, IFFMarkdown, OFFTabSep, &ApisCfg{&ApiCfg{}})
t.Log(assert.Equal(t, awesomeAwesomeShortOut, out.String()))
}
......@@ -28,7 +28,7 @@ awesome-sysadmin https://github.com/kahun/awesome-sysadmin Backups, configuratio
func TestCompile_TabSepTabSep(t *testing.T) {
out := &strings.Builder{}
Compile(strings.NewReader(awesomeAwesomeShortInp), len(awesomeAwesomeShortInp), out, IFFTabSep, OFFTabSep)
Compile(strings.NewReader(awesomeAwesomeShortInp), len(awesomeAwesomeShortInp), out, IFFTabSep, OFFTabSep, &ApisCfg{&ApiCfg{}})
t.Log(assert.Equal(t, `
'# Awesome
......@@ -50,7 +50,7 @@ awesome-sysadmin https://github.com/kahun/awesome-sysadmin Backups, configuratio
func TestCompile_TabSepSimpleMarkdown(t *testing.T) {
out := &strings.Builder{}
Compile(strings.NewReader(awesomeAwesomeShortInp), len(awesomeAwesomeShortInp), out, IFFTabSep, OFFSimpleMarkdown)
Compile(strings.NewReader(awesomeAwesomeShortInp), len(awesomeAwesomeShortInp), out, IFFTabSep, OFFSimpleMarkdown, &ApisCfg{&ApiCfg{}})
t.Log(assert.Equal(t, `
# Awesome Awesome
......@@ -74,7 +74,7 @@ For contributing, [open an issue](https://github.com/emijrp/awesome-awesome/issu
func TestCompile_TabSepMarkdown(t *testing.T) {
out := &strings.Builder{}
Compile(strings.NewReader(awesomeAwesomeShortInp), len(awesomeAwesomeShortInp), out, IFFTabSep, OFFMarkdown)
Compile(strings.NewReader(awesomeAwesomeShortInp), len(awesomeAwesomeShortInp), out, IFFTabSep, OFFMarkdown, &ApisCfg{&ApiCfg{}})
t.Log(assert.Equal(t, `
# Awesome Awesome
......
......@@ -85,9 +85,9 @@ func (m ghMeta) LastCommit() string {
func fetchGitHub(repo string, ctx *Ctx) Meta {
var data []byte
if ctx.fetchMetaGhRequests < /*ctx.MaxGitHubRequests*/ 0 { // TODO
if ctx.fetchMetaGhRequests < ctx.ApisCfg.GitHubCfg.MaxRequests { // TODO
ctx.fetchMetaGhRequests++
resp, err := http.Get("https://api.github.com/repos/" + repo /*+ "?access_token=" + ctx.GitHubToken*/) // TODO
resp, err := http.Get("https://api.github.com/repos/" + repo + "?access_token=" + ctx.ApisCfg.GitHubCfg.AccessToken) // TODO
if err != nil {
panic(err)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment