Add non-local PR template support by samcoe · Pull Request #5097 · cli/cli

@samcoe

This PR adds the ability to use non-local templates when opening a PR. It is mostly a copy of the work done for issue create templates.

Closes #838

@samcoe samcoe marked this pull request as ready for review

January 25, 2022 07:10

samcoe

Comment on lines -208 to -211

m.templates = make([]Template, len(issueTemplates))
for i := range issueTemplates {
m.templates[i] = &issueTemplates[i]
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved this work into the list functions so that they would both have the same function signatures.

@samcoe

mislav

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking this on!

return hasQuerySupport && hasMutationSupport, nil
}

func hasPullRequestTemplateSupport(httpClient *http.Client, hostname string) (bool, error) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function does the exact same query as hasIssueTemplateSupport, except that it scans for a different field on a Repository object. Could this lookup instead piggyback on hasIssueTemplateSupport so that fewer API calls are done?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup good call. I consolidated hasIssueTemplateSupport and hasPullRequestTemplateSupport into a single hasTemplateSupport function which uses one query and supports both issues and pull requests.

@samcoe

mislav

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! One minor note about keeping the GraphQL query unchanged (for cache key purposes)

@samcoe

@localheinz