Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Contacts for each Repo #9

Merged
merged 2 commits into from
Apr 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions scraper/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.19
require github.com/google/go-github/v51 v51.0.0

require (
github.com/google/go-cmp v0.5.9 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8 // indirect
github.com/cloudflare/circl v1.1.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
Expand Down
6 changes: 3 additions & 3 deletions scraper/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaS
github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-github/v51 v51.0.0 h1:KCjsbgPV28VoRftdP+K2mQL16jniUsLAJknsOVKwHyU=
github.com/google/go-github/v51 v51.0.0/go.mod h1:kZj/rn/c1lSUbr/PFWl2hhusPV7a5XNYKcwPrd5L3Us=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-github v17.0.0+incompatible h1:N0LgJ1j65A7kfXrZnUDaYCs/Sf4rEjNlfyDHW9dolSY=
github.com/google/go-github v17.0.0+incompatible/go.mod h1:zLgOLi98H3fifZn+44m+umXrS52loVEgC2AApnigrVQ=
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
Expand Down
14 changes: 13 additions & 1 deletion 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}
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)
}
11 changes: 11 additions & 0 deletions scraper/pkg/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}