Implementing issue template GraphQL API call#2539
Conversation
api/queries_issue.go
Outdated
| } | ||
|
|
||
| func IssueTemplates(client *Client, repo *Repository) ([]IssueTemplate, error) { | ||
| type response struct { |
There was a problem hiding this comment.
We could simplify/shorten this GQL request using the functionality provided by github.com/shurcooL/githubv4 so that the response struct also acts as the query. Many of the queries in api/queries_repo.go use this style. MilestoneByNumber is a short simple one that might be good to copy from.
api/queries_issue.go
Outdated
| return nil, err | ||
| } | ||
|
|
||
| if !resp.Repository.HasIssuesEnabled { |
There was a problem hiding this comment.
I would say that this check is outside the scope of responsibilities for this function. If this api call is being made then the caller should be responsible for making sure the repository has issue enabled.
pkg/cmd/issue/create/create.go
Outdated
| // overwrites previous templateContent | ||
| var templates []api.IssueTemplate | ||
| templates, err = api.IssueTemplates(apiClient, repo) | ||
| templateContent = templates[0].Body | ||
| if err != nil { | ||
| return | ||
| } |
There was a problem hiding this comment.
From the discussion in the issue I think this API call should replace the call to prShared.FindTemplates on line 108.
I am going to cc @mislav since it was his his comment about using the API both when -R is provided and when it is not which makes me think that is the desired approach.
There was a problem hiding this comment.
Thanks @samcoe for the initial review! You are right that this call needs to happen earlier.
@divyaramanathan You will want to invoke the new API logic just before TemplateSurvey(), since that is where the user will be presented with a list of templates to choose between. Also, since the new API approach replaces looking up templates from the filesystem, you can remove the old filesystem lookups from this file.
|
This is great progress so far. The API code looks good, just need to hook up the API response to the survey code properly. |
mislav
left a comment
There was a problem hiding this comment.
@divyaramanathan Thanks so much for taking this on! I'm really looking forward to improving templates this way.
pkg/cmd/issue/create/create.go
Outdated
| // overwrites previous templateContent | ||
| var templates []api.IssueTemplate | ||
| templates, err = api.IssueTemplates(apiClient, repo) | ||
| templateContent = templates[0].Body | ||
| if err != nil { | ||
| return | ||
| } |
There was a problem hiding this comment.
Thanks @samcoe for the initial review! You are right that this call needs to happen earlier.
@divyaramanathan You will want to invoke the new API logic just before TemplateSurvey(), since that is where the user will be presented with a list of templates to choose between. Also, since the new API approach replaces looking up templates from the filesystem, you can remove the old filesystem lookups from this file.
|
@mislav @samcoe thanks so much for your awesome feedback!! @divyaramanathan and I made some changes to reflect this behavior:
We're still having some issues, mainly:
We did, however, manage to grab this template and edit its contents: We think we're very very close, and would love some help on how to debug this API call and terminal rendering (we tried Postman but need an auth key). Thanks so much!! |
|
@mislav to get tests working and add conditional for older enterprise versions |
Co-authored-by: Zach Boyle <zboyle@umich.edu>
1a5801a to
83bb1bf
Compare
|
I have updated this branch to have both
@divyaramanathan @zaboyle Thank you so much for getting started on this implementation! 🙏 |
pkg/cmd/issue/create/create.go
Outdated
|
|
||
| if template != nil { | ||
| templateContent = string(template.Body()) | ||
| if ok, _ := tpl.HasAPI(); ok { |
There was a problem hiding this comment.
Exposing HasAPI() seems a bit odd and feels like details only the template manager should be aware of. What if, when doing the fetch of the templates, we don't set the template name if !HasAPI() that way we can just call template.Name() here.
| @@ -0,0 +1,252 @@ | |||
| package shared | |||
There was a problem hiding this comment.
I really like this direction. I think it would be good to add some unit tests to test these new functions directly since the top level command tests don't necessarily cover all the cases that are handled here.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.


closes #2361, fixes #875
In this PR, the following changes were made: