Skip to content

Commit c7eb738

Browse files
divyaramanathanzaboyle
authored andcommitted
implementing issue template GraphQL API call
Co-authored-by: Zach Boyle <zboyle@umich.edu>
1 parent f43fb26 commit c7eb738

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

api/queries_issue.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ type IssuesAndTotalCount struct {
2323
TotalCount int
2424
}
2525

26+
type IssueTemplate struct {
27+
About string
28+
Body string
29+
Name string
30+
Title string
31+
}
32+
2633
type Issue struct {
2734
ID string
2835
Number int
@@ -488,6 +495,31 @@ func IssueDelete(client *Client, repo ghrepo.Interface, issue Issue) error {
488495
return err
489496
}
490497

498+
func IssueTemplates(client *Client, repo *Repository) ([]IssueTemplate, error) {
499+
var query struct {
500+
Repository struct {
501+
IssueTemplates []IssueTemplate
502+
} `graphql:"repository(owner: $owner, name: $name)"`
503+
}
504+
505+
variables := map[string]interface{}{
506+
"owner": githubv4.String(repo.RepoOwner()),
507+
"name": githubv4.String(repo.RepoName()),
508+
}
509+
510+
gql := graphQLClient(client.http, repo.RepoHost())
511+
512+
err := gql.QueryNamed(context.Background(), "RepositoryIssueTemplates", &query, variables)
513+
if err != nil {
514+
return nil, err
515+
}
516+
if query.Repository.IssueTemplates == nil {
517+
return nil, fmt.Errorf("no issue templates found ")
518+
}
519+
520+
return query.Repository.IssueTemplates, nil
521+
}
522+
491523
// milestoneNodeIdToDatabaseId extracts the REST Database ID from the GraphQL Node ID
492524
// This conversion is necessary since the GraphQL API requires the use of the milestone's database ID
493525
// for querying the related issues.

0 commit comments

Comments
 (0)