Port issue create to using templates API

This commit is contained in:
Mislav Marohnić 2021-02-10 17:32:00 +01:00
parent c7eb7382f0
commit 3ddd93793c
7 changed files with 289 additions and 54 deletions

View file

@ -23,13 +23,6 @@ type IssuesAndTotalCount struct {
TotalCount int
}
type IssueTemplate struct {
About string
Body string
Name string
Title string
}
type Issue struct {
ID string
Number int
@ -495,31 +488,6 @@ 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.