Skip to content

Commit

Permalink
Merge pull request #52 from philips-labs/feature/gh-forks-start-watchers
Browse files Browse the repository at this point in the history
Add github stars, watchers and fork counts to repositories
  • Loading branch information
JeroenKnoops authored Aug 28, 2020
2 parents 0730a71 + f7723aa commit 922efcf
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 38 deletions.
37 changes: 24 additions & 13 deletions lib/github/graphql/graphql.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,22 @@ type Owner struct {
}

type Repository struct {
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
URL string `json:"url,omitempty"`
SSHURL string `json:"ssh_url,omitempty"`
Owner Owner `json:"owner,omitempty"`
IsPrivate bool `json:"is_private,omitempty"`
CreatedAt time.Time `json:"created_at,omitempty"`
UpdatedAt time.Time `json:"updated_at,omitempty"`
PushedAt time.Time `json:"pushed_at,omitempty"`
RepositoryTopics RepositoryTopics `graphql:"repositoryTopics(first: 25)" json:"repository_topics,omitempty"`
Collaborators Collaborators `graphql:"collaborators(first: 15, affiliation: DIRECT)" json:"collaborators,omitempty"`
Languages Languages `graphql:"languages(first: 10, orderBy: {field: SIZE, direction: DESC})" json:"languages,omitempty"`
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
URL string `json:"url,omitempty"`
SSHURL string `json:"ssh_url,omitempty"`
Owner Owner `json:"owner,omitempty"`
IsPrivate bool `json:"is_private,omitempty"`
CreatedAt time.Time `json:"created_at,omitempty"`
UpdatedAt time.Time `json:"updated_at,omitempty"`
PushedAt time.Time `json:"pushed_at,omitempty"`
RepositoryTopics RepositoryTopics `graphql:"repositoryTopics(first: 25)" json:"repository_topics,omitempty"`
Collaborators Collaborators `graphql:"collaborators(first: 15, affiliation: DIRECT)" json:"collaborators,omitempty"`
Languages Languages `graphql:"languages(first: 10, orderBy: {field: SIZE, direction: DESC})" json:"languages,omitempty"`
ForkCount int `json:"fork_count,omitempty"`
Stargazers StargazersConnection `graphql:"stargazers(first: 0)" json:"stargazers,omitempty"`
Watchers UserConnection `graphql:"watchers(first: 0)" json:"watchers,omitempty"`
}

type Languages struct {
Expand Down Expand Up @@ -76,6 +79,14 @@ type Collaborator struct {
AvatarURL string `json:"avatar_url,omitempty"`
}

type StargazersConnection struct {
TotalCount int `json:"total_count,omitempty"`
}

type UserConnection struct {
TotalCount int `json:"total_count,omitempty"`
}

type Organization struct {
Repositories Repositories `graphql:"repositories(first: 100, after: $repoCursor)" json:"repositories,omitempty"`
}
56 changes: 31 additions & 25 deletions lib/github/repositories.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,22 @@ type RestRepo struct {
}

type Repository struct {
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
URL string `json:"url,omitempty"`
SSHURL string `json:"ssh_url,omitempty"`
Owner string `json:"owner,omitempty"`
Visibility Visibility `json:"visibility"`
CreatedAt time.Time `json:"created_at,omitempty"`
UpdatedAt time.Time `json:"updated_at,omitempty"`
PushedAt time.Time `json:"pushed_at,omitempty"`
Topics []Topic `json:"topics,omitempty"`
Languages []Language `json:"languages,omitempty"`
Collaborators []Collaborator `json:"collaborators,omitempty"`
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
URL string `json:"url,omitempty"`
SSHURL string `json:"ssh_url,omitempty"`
Owner string `json:"owner,omitempty"`
Visibility Visibility `json:"visibility"`
CreatedAt time.Time `json:"created_at,omitempty"`
UpdatedAt time.Time `json:"updated_at,omitempty"`
PushedAt time.Time `json:"pushed_at,omitempty"`
ForkCount int `json:"fork_count,omitempty"`
StargazerCount int `json:"stargazer_count,omitempty"`
WatcherCount int `json:"watcher_count,omitempty"`
Topics []Topic `json:"topics,omitempty"`
Languages []Language `json:"languages,omitempty"`
Collaborators []Collaborator `json:"collaborators,omitempty"`
}

type Collaborator struct {
Expand Down Expand Up @@ -140,18 +143,21 @@ func Map(repositories []graphql.Repository, privateRepositories []*github.Reposi
repos := make([]Repository, len(repositories))
for i, repo := range repositories {
repos[i] = Repository{
ID: repo.ID,
Name: repo.Name,
Description: strings.TrimSpace(repo.Description),
URL: repo.URL,
SSHURL: repo.SSHURL,
Owner: repo.Owner.Login,
CreatedAt: repo.CreatedAt,
UpdatedAt: repo.UpdatedAt,
PushedAt: repo.PushedAt,
Topics: mapTopics(repo.RepositoryTopics),
Languages: mapLanguages(repo.Languages),
Collaborators: mapCollaborators(repo.Collaborators),
ID: repo.ID,
Name: repo.Name,
Description: strings.TrimSpace(repo.Description),
URL: repo.URL,
SSHURL: repo.SSHURL,
Owner: repo.Owner.Login,
CreatedAt: repo.CreatedAt,
UpdatedAt: repo.UpdatedAt,
PushedAt: repo.PushedAt,
ForkCount: repo.ForkCount,
StargazerCount: repo.Stargazers.TotalCount,
WatcherCount: repo.Watchers.TotalCount,
Topics: mapTopics(repo.RepositoryTopics),
Languages: mapLanguages(repo.Languages),
Collaborators: mapCollaborators(repo.Collaborators),
}

if repo.IsPrivate {
Expand Down

0 comments on commit 922efcf

Please sign in to comment.