Visitar URL original
Allow choosing a blank issue/pr template by AliabbasMerchant · Pull Request #950 · cli/cli · GitHub
The Wayback Machine - https://web.archive.org/web/20200529202919/https://github.com/cli/cli/pull/950
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow choosing a blank issue/pr template #950

Open
wants to merge 5 commits into
base: trunk
from

Conversation

@AliabbasMerchant
Copy link

AliabbasMerchant commented May 17, 2020

Fixes #504

@AliabbasMerchant AliabbasMerchant force-pushed the AliabbasMerchant:blank-issue branch from 2de508f to e8741b9 May 17, 2020
@AliabbasMerchant AliabbasMerchant force-pushed the AliabbasMerchant:blank-issue branch from e8741b9 to 6effcd4 May 17, 2020
@vilmibm vilmibm self-requested a review May 18, 2020
@vilmibm vilmibm added this to Backlog 🗒 in The GitHub CLI via automation May 18, 2020
@vilmibm vilmibm added the community label May 18, 2020
@vilmibm vilmibm moved this from Backlog 🗒 to Needs review 🤔 in The GitHub CLI May 18, 2020
Copy link
Member

vilmibm left a comment

tested locally and it's 👍 ; just one tiny nitpick.

I was going to request tests but remembered that we still haven't made template selection testable. I'm ok with punting on that some more and cut #956.

command/title_body_survey.go Outdated Show resolved Hide resolved
@vilmibm
Copy link
Member

vilmibm commented May 18, 2020

In testing this I noticed our bug fix template has no name (not an issue when we weren't previously displaying it in a select menu); I pushed a commit to give it a name.

@AliabbasMerchant
Copy link
Author

AliabbasMerchant commented May 18, 2020

In testing this I noticed our bug fix template has no name (not an issue when we weren't previously displaying it in a select menu); I pushed a commit to give it a name.

I had also noticed that, and was going to point it out, but then I think it slipped my mind 😅

@AliabbasMerchant AliabbasMerchant force-pushed the AliabbasMerchant:blank-issue branch from dd4924c to bd7790f May 18, 2020
Copy link
Member

mislav left a comment •

This looks good to me, but I wonder whether we're still keeping parity with dotcom here.

When opening issues in web UI, users only get presented with a template picker + "open a blank issue" option when there are .github/ISSUE_TEMPLATE/*.md files only. When "blank issue" is chosen, a template from .github/ISSUE_TEMPLATE.md is used if it exists, or actually blank if not.

When opening pull requests in web UI, users never get presented with a template picker (as far as I know?), but users can pick a template by passing a ?template=<filename> query parameter. We deviate from web by showing a picker for .github/PULL_REQUEST_TEMPLATE/*.md files, and I think that's ok to keep.

But if we wanted to match what dotcom is doing, then .github/{ISSUE,PULL_REQUEST}_TEMPLATE.md files (i.e. templates that aren't grouped under a directory) should never show up in a picker, but should get used either A) by default (if there was no picker), or B) when the user has chosen "blank" from the picker.

command/title_body_survey.go Outdated Show resolved Hide resolved
@AliabbasMerchant
Copy link
Author

AliabbasMerchant commented May 19, 2020 •

But if we wanted to match what dotcom is doing, then .github/{ISSUE,PULL_REQUEST}_TEMPLATE.md files (i.e. templates that aren't grouped under a directory) should never show up in a picker, but should get used either A) by default (if there was no picker), or B) when the user has chosen "blank" from the picker.

Right. Seems the right way to go.
We can do this. Shall I do it in this PR itself?

@mislav
Copy link
Member

mislav commented May 19, 2020

Yes, please amend this PR! Thank you

@AliabbasMerchant AliabbasMerchant force-pushed the AliabbasMerchant:blank-issue branch 2 times, most recently from 8fe22e9 to 01f272d May 22, 2020
@@ -10,8 +10,8 @@ import (
"gopkg.in/yaml.v3"
)

// Find returns the list of template file paths
func Find(rootDir string, name string) []string {
// FindNonLegacy returns the list of template file paths from the template folder (according to the "upgraded multiple template builder")

This comment has been minimized.

Copy link
@AliabbasMerchant

AliabbasMerchant May 22, 2020

Author

GitHub refers to the original way of PULL_REQUEST_TEMPLATE.md and ISSUE_TEMPLATE.md files as 'legacy' and the new method of PULL_REQUEST_TEMPLATE and ISSUE_TEMPLATE folders containing the template files as "upgraded multiple template builder".
I have hence called them as legacy and nonlegacy

@@ -397,7 +397,7 @@ func issueCreate(cmd *cobra.Command, args []string) error {
url.QueryEscape(title),
url.QueryEscape(body),
)
} else if len(templateFiles) > 1 {
} else if len(nonLegacyTemplateFiles) > 1 {

This comment has been minimized.

Copy link
@AliabbasMerchant

AliabbasMerchant May 22, 2020

Author

The /choose route is to be opened only if we have non-legacy templates. If there is a legacy template only, it is selected by default by GitHub

@mislav
Copy link
Member

mislav commented May 22, 2020

@AliabbasMerchant Thanks for the updates! Note for the future: it's easier for us to go through review cycles if you refrain from force-pushing the branch. In general, we avoid force-pushing while multiple people are either working on or reviewing a branch. After a force-push, it's hard for us to tell exactly which code is new since last review.

When the PR is approved to merge, we can always clean up the history by doing a rebase before the big merge.

@AliabbasMerchant AliabbasMerchant force-pushed the AliabbasMerchant:blank-issue branch from 9c6103c to 4fd051b May 22, 2020
const (
issueMetadata metadataStateType = iota
prMetadata
)

type issueMetadataState struct {

This comment has been minimized.

Copy link
@AliabbasMerchant

AliabbasMerchant May 22, 2020

Author

I feel that the name of this struct should be changed, since it is not only used for issues, but for PRs also.
Possibly to metadataState? 🤔

This comment has been minimized.

Copy link
@mislav

mislav May 22, 2020

Member

In github-y terms, PRs are issues since they are a subset of Issues. If we renamed this to metadataState in the command package then it might not be clear what the "metadata" applies to. I think the only more precise name would be "issueOrPullRequestMetadataState`

This comment has been minimized.

Copy link
@AliabbasMerchant

AliabbasMerchant May 22, 2020

Author

In github-y terms, PRs are issues since they are a subset of Issues

Oh. I didn't know that.

I think the only more precise name would be "issueOrPullRequestMetadataState`

Agreed. Can we do that, just for extra clarity?

@AliabbasMerchant
Copy link
Author

AliabbasMerchant commented May 22, 2020

@mislav Right, sorry. I won't force push from now on. Will clean up the history only after the PR is approved.
For now, only the last 2 commits have changed contents.

@AliabbasMerchant
Copy link
Author

AliabbasMerchant commented May 22, 2020

In accordance with @mislav 's suggestion, the new workflow is as follows:
Templates are now categorised into 2:

  1. LegacyTemplates: The PULL_REQUEST_TEMPLATE.md' and ISSUE_TEMPLATE.md` files. Only 1 such template is respected, in order of occurrence in the '.github', root and 'docs' folder.
  2. NonLegacyTemplates: The custom/special/non-generic templates in the PULL_REQUEST_TEMPLATE and ISSUE_TEMPLATE folders

When the NonLegacyTemplates are present, the user is given a prompt to choose from them and a blank template(which defaults to the LegacyTemplate, if it is there, or an empty body)
If there are no NonLegacy templates, the legacy template is selected by default, if present, otherwise an empty body is selected.

There are currently no tests for template selection, but @vilmibm and I working on them in #986

@mislav
mislav approved these changes May 22, 2020
Copy link
Member

mislav left a comment

Code looks good to me! I will need until next week to manually test to verify behavior, and perhaps I would shuffle some code around, but for now I don't have specific suggestions. Thank you for your hard work!

command/pr_create.go Outdated Show resolved Hide resolved
@@ -116,7 +224,7 @@ func TestFind(t *testing.T) {
file.Close()
}

if got := Find(tt.args.rootDir, tt.args.name); !reflect.DeepEqual(got, tt.want) {
if got := FindLegacy(tt.args.rootDir, tt.args.name); *got != tt.want {

This comment has been minimized.

Copy link
@mislav

mislav May 22, 2020

Member

How come you were able to remove DeepEqual comparison from here?

This comment has been minimized.

Copy link
@AliabbasMerchant

AliabbasMerchant May 22, 2020 •

Author

Coz tt.want is just a string now, since we only have at most a since legacy template file

const (
issueMetadata metadataStateType = iota
prMetadata
)

type issueMetadataState struct {

This comment has been minimized.

Copy link
@mislav

mislav May 22, 2020

Member

In github-y terms, PRs are issues since they are a subset of Issues. If we renamed this to metadataState in the command package then it might not be clear what the "metadata" applies to. I think the only more precise name would be "issueOrPullRequestMetadataState`

@mislav mislav changed the base branch from master to trunk May 27, 2020
@AliabbasMerchant
Copy link
Author

AliabbasMerchant commented May 28, 2020

@mislav Did you get the chance to test this out?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
The GitHub CLI
  
Needs review 🤔
Linked issues

Successfully merging this pull request may close these issues.

3 participants
You can’t perform that action at this time.