From c7eb7382f01c13e3549ed36fd771e9e07d2a185b Mon Sep 17 00:00:00 2001 From: Divya Ramanathan Date: Wed, 2 Dec 2020 21:53:24 -0500 Subject: [PATCH] implementing issue template GraphQL API call Co-authored-by: Zach Boyle --- api/queries_issue.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/api/queries_issue.go b/api/queries_issue.go index 22f08287b..3f05c261f 100644 --- a/api/queries_issue.go +++ b/api/queries_issue.go @@ -23,6 +23,13 @@ type IssuesAndTotalCount struct { TotalCount int } +type IssueTemplate struct { + About string + Body string + Name string + Title string +} + type Issue struct { ID string Number int @@ -488,6 +495,31 @@ func IssueDelete(client *Client, repo ghrepo.Interface, issue Issue) error { return err } +func IssueTemplates(client *Client, repo *Repository) ([]IssueTemplate, error) { + var query struct { + Repository struct { + IssueTemplates []IssueTemplate + } `graphql:"repository(owner: $owner, name: $name)"` + } + + variables := map[string]interface{}{ + "owner": githubv4.String(repo.RepoOwner()), + "name": githubv4.String(repo.RepoName()), + } + + gql := graphQLClient(client.http, repo.RepoHost()) + + err := gql.QueryNamed(context.Background(), "RepositoryIssueTemplates", &query, variables) + if err != nil { + return nil, err + } + if query.Repository.IssueTemplates == nil { + return nil, fmt.Errorf("no issue templates found ") + } + + return query.Repository.IssueTemplates, nil +} + // milestoneNodeIdToDatabaseId extracts the REST Database ID from the GraphQL Node ID // This conversion is necessary since the GraphQL API requires the use of the milestone's database ID // for querying the related issues.