mirror of
https://github.com/Luzifer/badge-gen.git
synced 2024-09-19 23:32:56 +00:00
Add Github stars by repo
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
820c81f62f
commit
76da5c2921
@ -37,6 +37,10 @@ type githubAsset struct {
|
|||||||
Downloads int64 `json:"download_count"`
|
Downloads int64 `json:"download_count"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type githubRepo struct {
|
||||||
|
StargazersCount int64 `json:"stargazers_count"`
|
||||||
|
}
|
||||||
|
|
||||||
type githubServiceHandler struct{}
|
type githubServiceHandler struct{}
|
||||||
|
|
||||||
func (g githubServiceHandler) GetDocumentation() serviceHandlerDocumentationList {
|
func (g githubServiceHandler) GetDocumentation() serviceHandlerDocumentationList {
|
||||||
@ -71,6 +75,11 @@ func (g githubServiceHandler) GetDocumentation() serviceHandlerDocumentationList
|
|||||||
DemoPath: "/github/downloads/atom/atom/v1.8.0/atom-amd64.deb",
|
DemoPath: "/github/downloads/atom/atom/v1.8.0/atom-amd64.deb",
|
||||||
Arguments: []string{"downloads", "<user>", "<repo>", "<tag or \"latest\">", "<asset>"},
|
Arguments: []string{"downloads", "<user>", "<repo>", "<tag or \"latest\">", "<asset>"},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
ServiceName: "Github stars by repository",
|
||||||
|
DemoPath: "/github/stars/atom/atom",
|
||||||
|
Arguments: []string{"stars", "<user>", "<repo>"},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,6 +98,8 @@ func (g githubServiceHandler) Handle(ctx context.Context, params []string) (titl
|
|||||||
title, text, color, err = g.handleLatestRelease(ctx, params[1:])
|
title, text, color, err = g.handleLatestRelease(ctx, params[1:])
|
||||||
case "downloads":
|
case "downloads":
|
||||||
title, text, color, err = g.handleDownloads(ctx, params[1:])
|
title, text, color, err = g.handleDownloads(ctx, params[1:])
|
||||||
|
case "stars":
|
||||||
|
title, text, color, err = g.handleStargazers(ctx, params[1:])
|
||||||
default:
|
default:
|
||||||
err = errors.New("An unknown service command was called")
|
err = errors.New("An unknown service command was called")
|
||||||
}
|
}
|
||||||
@ -96,6 +107,27 @@ func (g githubServiceHandler) Handle(ctx context.Context, params []string) (titl
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (g githubServiceHandler) handleStargazers(ctx context.Context, params []string) (title, text, color string, err error) {
|
||||||
|
path := strings.Join([]string{"repos", params[0], params[1]}, "/")
|
||||||
|
|
||||||
|
text, err = cacheStore.Get("github_repo_stargazers", path)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
r := githubRepo{}
|
||||||
|
|
||||||
|
if err = g.fetchAPI(ctx, path, nil, &r); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
text = metricFormat(r.StargazersCount)
|
||||||
|
cacheStore.Set("github_repo_stargazers", path, text, 10*time.Minute)
|
||||||
|
}
|
||||||
|
|
||||||
|
title = "stars"
|
||||||
|
color = "brightgreen"
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func (g githubServiceHandler) handleDownloads(ctx context.Context, params []string) (title, text, color string, err error) {
|
func (g githubServiceHandler) handleDownloads(ctx context.Context, params []string) (title, text, color string, err error) {
|
||||||
switch len(params) {
|
switch len(params) {
|
||||||
case 2:
|
case 2:
|
||||||
|
Loading…
Reference in New Issue
Block a user