feat(repos): add repository lookup by ID
Some checks failed
Security Scan / security (push) Successful in 12s
Test / test (push) Has been cancelled

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-04-02 02:34:41 +00:00
parent 0a4b8a849a
commit 39742d75c2
2 changed files with 38 additions and 0 deletions

View file

@ -85,6 +85,16 @@ func (s *RepoService) IterUserRepos(ctx context.Context) iter.Seq2[types.Reposit
return ListIter[types.Repository](ctx, s.client, "/api/v1/user/repos", nil)
}
// GetByID returns a repository by its numeric ID.
func (s *RepoService) GetByID(ctx context.Context, id int64) (*types.Repository, error) {
path := ResolvePath("/api/v1/repositories/{id}", pathParams("id", int64String(id)))
var out types.Repository
if err := s.client.Get(ctx, path, &out); err != nil {
return nil, err
}
return &out, 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))

View file

@ -46,6 +46,34 @@ func TestRepoService_ListActivityFeeds_Good(t *testing.T) {
}
}
func TestRepoService_GetByID_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/repositories/42" {
t.Errorf("wrong path: %s", r.URL.Path)
http.NotFound(w, r)
return
}
json.NewEncoder(w).Encode(types.Repository{
ID: 42,
Name: "go-forge",
FullName: "core/go-forge",
})
}))
defer srv.Close()
f := NewForge(srv.URL, "tok")
repo, err := f.Repos.GetByID(context.Background(), 42)
if err != nil {
t.Fatal(err)
}
if repo.ID != 42 || repo.Name != "go-forge" || repo.FullName != "core/go-forge" {
t.Fatalf("got %#v", repo)
}
}
func TestRepoService_ListTopics_Good(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet {