Skip to content

Commit 5d398c9

Browse files
Add Contacts for each Repo (#9)
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 #5 Signed-off-by: Sai Sindhur Malleni <[email protected]> Co-authored-by: Dustin Black <[email protected]>
1 parent 0d70f6a commit 5d398c9

File tree

5 files changed

+44
-9
lines changed

5 files changed

+44
-9
lines changed

scraper/go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ go 1.19
55
require github.com/google/go-github/v51 v51.0.0
66

77
require (
8+
github.com/google/go-cmp v0.5.9 // indirect
89
github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8 // indirect
910
github.com/cloudflare/circl v1.1.0 // indirect
1011
github.com/golang/protobuf v1.5.2 // indirect

scraper/go.sum

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaS
88
github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
99
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
1010
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
11-
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
1211
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
13-
github.com/google/go-github/v51 v51.0.0 h1:KCjsbgPV28VoRftdP+K2mQL16jniUsLAJknsOVKwHyU=
14-
github.com/google/go-github/v51 v51.0.0/go.mod h1:kZj/rn/c1lSUbr/PFWl2hhusPV7a5XNYKcwPrd5L3Us=
12+
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
13+
github.com/google/go-github v17.0.0+incompatible h1:N0LgJ1j65A7kfXrZnUDaYCs/Sf4rEjNlfyDHW9dolSY=
14+
github.com/google/go-github v17.0.0+incompatible/go.mod h1:zLgOLi98H3fifZn+44m+umXrS52loVEgC2AApnigrVQ=
1515
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
1616
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
1717
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=

scraper/main.go

Lines changed: 13 additions & 1 deletion
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}
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}
92102
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: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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)