Add repository tag listing
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
b9e8b22d41
commit
5326ecefb6
2 changed files with 37 additions and 0 deletions
|
|
@ -184,3 +184,28 @@ func TestRepoService_GetArchive_Good(t *testing.T) {
|
|||
t.Fatalf("got %q, want %q", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRepoService_ListTags_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/tags" {
|
||||
t.Errorf("wrong path: %s", r.URL.Path)
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
w.Header().Set("X-Total-Count", "1")
|
||||
json.NewEncoder(w).Encode([]types.Tag{{Name: "v1.0.0"}})
|
||||
}))
|
||||
defer srv.Close()
|
||||
|
||||
f := NewForge(srv.URL, "tok")
|
||||
tags, err := f.Repos.ListTags(context.Background(), "core", "go-forge")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(tags) != 1 || tags[0].Name != "v1.0.0" {
|
||||
t.Fatalf("unexpected result: %+v", tags)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
12
repos.go
12
repos.go
|
|
@ -45,6 +45,18 @@ func (s *RepoService) IterUserRepos(ctx context.Context) iter.Seq2[types.Reposit
|
|||
return ListIter[types.Repository](ctx, s.client, "/api/v1/user/repos", nil)
|
||||
}
|
||||
|
||||
// ListTags returns all tags for a repository.
|
||||
func (s *RepoService) ListTags(ctx context.Context, owner, repo string) ([]types.Tag, error) {
|
||||
path := ResolvePath("/api/v1/repos/{owner}/{repo}/tags", pathParams("owner", owner, "repo", repo))
|
||||
return ListAll[types.Tag](ctx, s.client, path, nil)
|
||||
}
|
||||
|
||||
// IterTags returns an iterator over all tags for a repository.
|
||||
func (s *RepoService) IterTags(ctx context.Context, owner, repo string) iter.Seq2[types.Tag, error] {
|
||||
path := ResolvePath("/api/v1/repos/{owner}/{repo}/tags", pathParams("owner", owner, "repo", repo))
|
||||
return ListIter[types.Tag](ctx, s.client, path, nil)
|
||||
}
|
||||
|
||||
// GetArchive returns a repository archive as raw bytes.
|
||||
func (s *RepoService) GetArchive(ctx context.Context, owner, repo, archive string) ([]byte, error) {
|
||||
path := ResolvePath("/api/v1/repos/{owner}/{repo}/archive/{archive}", pathParams("owner", owner, "repo", repo, "archive", archive))
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue