implementing issue template GraphQL API call

Co-authored-by: Zach Boyle <zboyle@umich.edu>
This commit is contained in:
Divya Ramanathan 2020-12-02 21:53:24 -05:00 committed by Mislav Marohnić
parent f43fb26acf
commit c7eb7382f0

View file

@ -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.