Skip to content
This repository was archived by the owner on May 11, 2025. It is now read-only.

Commit bcbefd7

Browse files
committed
add contributor api
1 parent 3044fb4 commit bcbefd7

2 files changed

Lines changed: 45 additions & 0 deletions

File tree

api.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,21 @@ func GetLanguages(username string, repo string) (data map[string]float64, err er
3333
return data, err
3434
}
3535

36+
func getRelease(username string, repo string, tag string) (data map[string]float64, err error) {
37+
err = Get(fmt.Sprintf("repos/%s/%s/releases/tags/%s", username, repo, tag), &data)
38+
return data, err
39+
}
40+
41+
func getLatestRelease(username string, repo string) (data map[string]float64, err error) {
42+
err = Get(fmt.Sprintf("repos/%s/%s/releases/latest", username, repo), &data)
43+
return data, err
44+
}
45+
46+
func getContributors(username string, repo string) (data []interface{}, err error) {
47+
err = Get(fmt.Sprintf("repos/%s/%s/contributors", username, repo), &data)
48+
return data, err
49+
}
50+
3651
func getLicense(license interface{}) string {
3752
if license != nil {
3853
return license.(map[string]interface{})["spdx_id"].(string)
@@ -167,3 +182,26 @@ func AnalysisRepo(username string, repo string) AnalysisData {
167182
}, "", iris.StatusOK,
168183
}
169184
}
185+
186+
func AnalysisContributor(username string, repo string) AnalysisData {
187+
res, err := getContributors(username, repo)
188+
if err != nil {
189+
return AnalysisData{nil, err.Error(), iris.StatusNotFound}
190+
}
191+
var contributors []map[string]any
192+
for _, v := range res {
193+
v := v.(map[string]interface{})
194+
contributors = append(contributors, map[string]any{
195+
"username": v["login"],
196+
"avatar": v["avatar_url"],
197+
"commits": v["contributions"],
198+
})
199+
}
200+
return AnalysisData{
201+
iris.Map{
202+
"username": username,
203+
"repo": repo,
204+
"contributors": contributors,
205+
}, "", iris.StatusOK,
206+
}
207+
}

server.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ func RunServer() {
1010
{
1111
app.Get("/api/user/{username:string}", CachedHandler(UserAPI))
1212
app.Get("/api/repo/{username:string}/{repo:string}", CachedHandler(RepoAPI))
13+
app.Get("/api/contributor/{username:string}/{repo:string}", CachedHandler(ContributorAPI))
1314
}
1415
app.Listen(fmt.Sprintf(":%d", conf.Server.Port))
1516
}
@@ -25,3 +26,9 @@ func RepoAPI(ctx iris.Context) {
2526
data := AnalysisRepo(username, repo)
2627
EndBodyWithCache(ctx, data)
2728
}
29+
30+
func ContributorAPI(ctx iris.Context) {
31+
username, repo := ctx.Params().Get("username"), ctx.Params().Get("repo")
32+
data := AnalysisContributor(username, repo)
33+
EndBodyWithCache(ctx, data)
34+
}

0 commit comments

Comments
 (0)