Skip to content

Commit

Permalink
Stars and forks
Browse files Browse the repository at this point in the history
Signed-off-by: AbstractionFactory <[email protected]>
  • Loading branch information
abstractionfactory committed Sep 10, 2024
1 parent 13386c1 commit 41915c7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
6 changes: 6 additions & 0 deletions vcs/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type Client interface {
// ParseRepositoryAddr parses the repository address from a string.
ParseRepositoryAddr(ref string) (RepositoryAddr, error)

// GetRepositoryInfo returns the information from the VCS API.
GetRepositoryInfo(ctx context.Context, repository RepositoryAddr) (RepositoryInfo, error)

// ListLatestTags returns the last few tags in the VCS system. This is a lightweight call and
Expand Down Expand Up @@ -98,4 +99,9 @@ type WorkingCopy interface {

type RepositoryInfo struct {
Description string `json:"description"`
// Popularity indicates how popular (stars, etc.) the repository is.
Popularity int `json:"popularity"`
// ForkOf indicates that this repository is a fork or copy of another repository. This is empty if the
// repository is not a known fork/copy.
ForkOf *RepositoryAddr `json:"fork_of,omitempty"`
}
22 changes: 19 additions & 3 deletions vcs/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,33 @@ func (g github) GetRepositoryInfo(ctx context.Context, repository vcs.Repository
return vcs.RepositoryInfo{}, err
}
type repoInfoResponse struct {
Description string `json:"description"`
Description string `json:"description"`
StargazersCount int `json:"stargazers_count"`
Parent *struct {
Name string `json:"name"`
Owner struct {
Login string `json:"login"`
} `json:"owner"`
} `json:"parent"`
}

var response repoInfoResponse

if err := g.request(ctx, "https://api.github.com/repos/"+url.PathEscape(string(repository.Org))+"/"+url.PathEscape(repository.Name), &response); err != nil {
return vcs.RepositoryInfo{}, err
}
return vcs.RepositoryInfo{

repoInfo := vcs.RepositoryInfo{
Description: response.Description,
}, nil
Popularity: response.StargazersCount,
}
if response.Parent != nil {
repoInfo.ForkOf = &vcs.RepositoryAddr{
Org: vcs.OrganizationAddr(response.Parent.Owner.Login),
Name: response.Parent.Name,
}
}
return repoInfo, nil
}

func (g github) Checkout(ctx context.Context, repository vcs.RepositoryAddr, version vcs.VersionNumber) (vcs.WorkingCopy, error) {
Expand Down

0 comments on commit 41915c7

Please sign in to comment.