Skip to content

Commit a9a28c9

Browse files
committed
Add Contacts for each Repo
Adds an additional field to each repo dictionary in the JSON consisting of top 3 contributor's GitHub id and the URL - which can both be used to render contacts on the frontend. This partially implements redhat-performance#5 Signed-off-by: Sai Sindhur Malleni <[email protected]>
1 parent a8a8f34 commit a9a28c9

File tree

3 files changed

+42
-8
lines changed

3 files changed

+42
-8
lines changed

scraper/main.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const (
1515
repositoriesFile = "../public/repositories.json"
1616
ignoredTopicsFile = "../public/ignored-topics.json"
1717
ignoreRepositoriesFile = "../public/ignored-repositories.json"
18+
topContributorsCount = 3
1819
)
1920

2021
var (
@@ -69,6 +70,7 @@ func main() {
6970
loadConfiguration()
7071

7172
var repoData types.RepoData
73+
var contactData []types.Contact
7274
ir := *ignoredRepositories
7375
for _, o := range *sOrgs {
7476
ghrepos := github.GitHubRepositories(ctx, o)
@@ -88,8 +90,17 @@ func main() {
8890
}
8991
if !ignored {
9092
topics := r.Topics
91-
repo := types.Repo{Org: r.Owner.GetLogin(), Name: r.GetName(), URL: r.GetHTMLURL(), Description: r.GetDescription(), Labels: topics}
92-
repoData.Repos = append(repoData.Repos, repo)
93+
contributors := github.ListContrib(ctx, r.Owner.GetLogin(), r.GetName())
94+
for n, contributor := range contributors {
95+
if n > topContributorsCount-1 {
96+
break
97+
}
98+
contacts := types.Contact{Username: *contributor.Login, URL: *contributor.HTMLURL}
99+
contactData = append(contactData, contacts)
100+
}
101+
repo := types.Repo{Org: r.Owner.GetLogin(), Name: r.GetName(), URL: r.GetHTMLURL(), Description: r.GetDescription(), Labels: topics, Contacts: contactData}
102+
repoData.Repos = append(repoData.Repos, repo)
103+
93104
}
94105
}
95106
}
@@ -98,5 +109,6 @@ func main() {
98109
if err != nil {
99110
log.Fatalf("Error marshaling Repositories: %s", err)
100111
}
112+
// fmt.Println(repoData.Repos)
101113
os.WriteFile(repositoriesFile, reposJson, 0666)
102114
}

scraper/pkg/github/github.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"context"
55
"log"
66

7-
"github.com/google/go-github/github"
7+
"github.com/google/go-github/v51/github"
88
)
99

1010
func GitHubRepositories(ctx context.Context, org string) []*github.Repository {
@@ -16,3 +16,14 @@ func GitHubRepositories(ctx context.Context, org string) []*github.Repository {
1616
}
1717
return ghrepos
1818
}
19+
20+
func ListContrib(ctx context.Context, org string, repository string) []*github.Contributor {
21+
//Using Unauthenticated client
22+
client := github.NewClient(nil)
23+
opts := &github.ListContributorsOptions{Anon: "false"}
24+
contributors, _, err := client.Repositories.ListContributors(ctx, org, repository, opts)
25+
if err != nil {
26+
log.Fatalf("Error getting contributors: %s", err)
27+
}
28+
return contributors
29+
}

scraper/pkg/types/repodata.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
11
package types
22

33
type Repo struct {
4-
Org string `json:"org"`
5-
Name string `json:"name"`
6-
Description string `json:"description"`
7-
URL string `json:"url"`
8-
Labels []string `json:"labels"`
4+
Org string `json:"org"`
5+
Name string `json:"name"`
6+
Description string `json:"description"`
7+
URL string `json:"url"`
8+
Labels []string `json:"labels"`
9+
Contacts []Contact `json:"contacts"`
910
}
1011

1112
type RepoData struct {
1213
Repos []Repo `json:"repos"`
1314
}
15+
16+
type Contact struct {
17+
Username string `json:"username"`
18+
URL string `json:"htmlurl"`
19+
}
20+
21+
type ContactData struct {
22+
Contacts []Contact `json:"contact"`
23+
}
24+

0 commit comments

Comments
 (0)