feat(repos): add issue template listing
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
4af621e580
commit
d97b9ba480
2 changed files with 40 additions and 0 deletions
6
repos.go
6
repos.go
|
|
@ -148,6 +148,12 @@ func (s *RepoService) GetArchive(ctx context.Context, owner, repo, archive strin
|
|||
return s.client.GetRaw(ctx, path)
|
||||
}
|
||||
|
||||
// ListIssueTemplates returns all issue templates available for a repository.
|
||||
func (s *RepoService) ListIssueTemplates(ctx context.Context, owner, repo string) ([]types.IssueTemplate, error) {
|
||||
path := ResolvePath("/api/v1/repos/{owner}/{repo}/issue_templates", pathParams("owner", owner, "repo", repo))
|
||||
return ListAll[types.IssueTemplate](ctx, s.client, path, nil)
|
||||
}
|
||||
|
||||
// ListTopics returns the topics assigned to a repository.
|
||||
func (s *RepoService) ListTopics(ctx context.Context, owner, repo string) ([]string, error) {
|
||||
path := ResolvePath("/api/v1/repos/{owner}/{repo}/topics", pathParams("owner", owner, "repo", repo))
|
||||
|
|
|
|||
|
|
@ -104,6 +104,40 @@ func TestRepoService_DeleteTopic_Good(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestRepoService_ListIssueTemplates_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/issue_templates" {
|
||||
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.IssueTemplate{
|
||||
{
|
||||
Name: "bug report",
|
||||
Title: "Bug report",
|
||||
Content: "Describe the problem",
|
||||
},
|
||||
})
|
||||
}))
|
||||
defer srv.Close()
|
||||
|
||||
f := NewForge(srv.URL, "tok")
|
||||
templates, err := f.Repos.ListIssueTemplates(context.Background(), "core", "go-forge")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(templates) != 1 {
|
||||
t.Fatalf("got %d templates, want 1", len(templates))
|
||||
}
|
||||
if templates[0].Name != "bug report" || templates[0].Title != "Bug report" {
|
||||
t.Fatalf("got %#v", templates[0])
|
||||
}
|
||||
}
|
||||
|
||||
func TestRepoService_GetNewPinAllowed_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