feat(repos): add repository languages endpoint
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
6dff39c82d
commit
3940f8f23e
2 changed files with 37 additions and 0 deletions
10
repos.go
10
repos.go
|
|
@ -221,6 +221,16 @@ func (s *RepoService) GetRawFile(ctx context.Context, owner, repo, filepath stri
|
|||
return s.client.GetRaw(ctx, path)
|
||||
}
|
||||
|
||||
// GetLanguages returns the byte counts per language for a repository.
|
||||
func (s *RepoService) GetLanguages(ctx context.Context, owner, repo string) (map[string]int64, error) {
|
||||
path := ResolvePath("/api/v1/repos/{owner}/{repo}/languages", pathParams("owner", owner, "repo", repo))
|
||||
var out map[string]int64
|
||||
if err := s.client.Get(ctx, path, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// ListFlags returns all flags for a repository.
|
||||
func (s *RepoService) ListFlags(ctx context.Context, owner, repo string) ([]string, error) {
|
||||
path := ResolvePath("/api/v1/repos/{owner}/{repo}/flags", pathParams("owner", owner, "repo", repo))
|
||||
|
|
|
|||
|
|
@ -390,6 +390,33 @@ func TestRepoService_DeleteTag_Good(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestRepoService_GetLanguages_Good(t *testing.T) {
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodGet {
|
||||
t.Errorf("expected GET, got %s", r.Method)
|
||||
}
|
||||
if r.URL.Path != "/api/v1/repos/core/go-forge/languages" {
|
||||
t.Errorf("wrong path: %s", r.URL.Path)
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
json.NewEncoder(w).Encode(map[string]int64{
|
||||
"go": 1200,
|
||||
"shell": 300,
|
||||
})
|
||||
}))
|
||||
defer srv.Close()
|
||||
|
||||
f := NewForge(srv.URL, "tok")
|
||||
languages, err := f.Repos.GetLanguages(context.Background(), "core", "go-forge")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !reflect.DeepEqual(languages, map[string]int64{"go": 1200, "shell": 300}) {
|
||||
t.Fatalf("got %#v", languages)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRepoService_ListForks_Good(t *testing.T) {
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodGet {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue