Skip to content

Commit

Permalink
Add Contacts for each Repo
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
smalleni committed Apr 14, 2023
1 parent a8a8f34 commit a9a28c9
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 8 deletions.
16 changes: 14 additions & 2 deletions scraper/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const (
repositoriesFile = "../public/repositories.json"
ignoredTopicsFile = "../public/ignored-topics.json"
ignoreRepositoriesFile = "../public/ignored-repositories.json"
topContributorsCount = 3
)

var (
Expand Down Expand Up @@ -69,6 +70,7 @@ func main() {
loadConfiguration()

var repoData types.RepoData
var contactData []types.Contact
ir := *ignoredRepositories
for _, o := range *sOrgs {
ghrepos := github.GitHubRepositories(ctx, o)
Expand All @@ -88,8 +90,17 @@ func main() {
}
if !ignored {
topics := r.Topics
repo := types.Repo{Org: r.Owner.GetLogin(), Name: r.GetName(), URL: r.GetHTMLURL(), Description: r.GetDescription(), Labels: topics}
repoData.Repos = append(repoData.Repos, repo)
contributors := github.ListContrib(ctx, r.Owner.GetLogin(), r.GetName())
for n, contributor := range contributors {
if n > topContributorsCount-1 {
break
}
contacts := types.Contact{Username: *contributor.Login, URL: *contributor.HTMLURL}
contactData = append(contactData, contacts)
}
repo := types.Repo{Org: r.Owner.GetLogin(), Name: r.GetName(), URL: r.GetHTMLURL(), Description: r.GetDescription(), Labels: topics, Contacts: contactData}
repoData.Repos = append(repoData.Repos, repo)

}
}
}
Expand All @@ -98,5 +109,6 @@ func main() {
if err != nil {
log.Fatalf("Error marshaling Repositories: %s", err)
}
// fmt.Println(repoData.Repos)
os.WriteFile(repositoriesFile, reposJson, 0666)
}
13 changes: 12 additions & 1 deletion scraper/pkg/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"log"

"github.com/google/go-github/github"
"github.com/google/go-github/v51/github"
)

func GitHubRepositories(ctx context.Context, org string) []*github.Repository {
Expand All @@ -16,3 +16,14 @@ func GitHubRepositories(ctx context.Context, org string) []*github.Repository {
}
return ghrepos
}

func ListContrib(ctx context.Context, org string, repository string) []*github.Contributor {
//Using Unauthenticated client
client := github.NewClient(nil)
opts := &github.ListContributorsOptions{Anon: "false"}
contributors, _, err := client.Repositories.ListContributors(ctx, org, repository, opts)
if err != nil {
log.Fatalf("Error getting contributors: %s", err)
}
return contributors
}
21 changes: 16 additions & 5 deletions scraper/pkg/types/repodata.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
package types

type Repo struct {
Org string `json:"org"`
Name string `json:"name"`
Description string `json:"description"`
URL string `json:"url"`
Labels []string `json:"labels"`
Org string `json:"org"`
Name string `json:"name"`
Description string `json:"description"`
URL string `json:"url"`
Labels []string `json:"labels"`
Contacts []Contact `json:"contacts"`
}

type RepoData struct {
Repos []Repo `json:"repos"`
}

type Contact struct {
Username string `json:"username"`
URL string `json:"htmlurl"`
}

type ContactData struct {
Contacts []Contact `json:"contact"`
}

0 comments on commit a9a28c9

Please sign in to comment.