Skip to content

Allow choosing a blank issue/pr template - #950

Merged
mislav merged 6 commits into
cli:trunkfrom
AliabbasMerchant:blank-issue
Jun 10, 2020
Merged

mislav merged 6 commits into
cli:trunkfrom
AliabbasMerchant:blank-issue

Conversation

@AliabbasMerchant

Copy link
Copy Markdown
Contributor

Fixes #504

@vilmibm vilmibm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Comment thread command/title_body_survey.go Resolved
@vilmibm

vilmibm commented May 18, 2020

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor Author

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 😅

@mislav mislav left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Comment thread command/title_body_survey.go Resolved
@AliabbasMerchant

AliabbasMerchant commented May 19, 2020 •

Copy link
Copy Markdown
Contributor Author

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

mislav commented May 19, 2020

Copy link
Copy Markdown
Contributor

Yes, please amend this PR! Thank you

@AliabbasMerchant
AliabbasMerchant force-pushed the blank-issue branch 2 times, most recently from 8fe22e9 to 01f272d Compare May 22, 2020 05:48

// 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")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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

Comment thread command/issue.go
url.QueryEscape(body),
)
} else if len(templateFiles) > 1 {
} else if len(nonLegacyTemplateFiles) > 1 {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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

mislav commented May 22, 2020

Copy link
Copy Markdown
Contributor

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

Comment thread command/title_body_survey.go Resolved
@AliabbasMerchant

Copy link
Copy Markdown
Contributor Author

@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
Copy Markdown
Contributor Author

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 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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!

Comment thread command/pr_create.go Resolved
}

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 {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

@AliabbasMerchant AliabbasMerchant May 22, 2020 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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

Comment thread command/title_body_survey.go Resolved
@mislav
mislav changed the base branch from master to trunk May 27, 2020 11:41
@AliabbasMerchant

Copy link
Copy Markdown
Contributor Author

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

@AliabbasMerchant

Copy link
Copy Markdown
Contributor Author

Any updates?

@mislav

mislav commented Jun 3, 2020

Copy link
Copy Markdown
Contributor

I have tried this out and it works great for me! Thank you

Comment thread command/issue.go
if baseOverride == "" {
if rootDir, err := git.ToplevelDir(); err == nil {
// TODO: figure out how to stub this in tests
legacyTemplateFile = githubtemplate.FindLegacy(rootDir, "ISSUE_TEMPLATE")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I noticed that "ISSUE_TEMPLATE" string is used in multiple parts of the code. Could it be added to a constant?

Comment thread command/pr_create.go Resolved
@AliabbasMerchant

Copy link
Copy Markdown
Contributor Author

@safv12 Thats a nice suggestion. I have noticed that there are a few more such constants also, lying around in the codebase, (some of which even had the TODO, to shift them to a constants file).
@mislav @vilmibm Should I do that change also, and shift all of them to appropriate files? (or does that need to be done in a separate PR?)
Then we can merge this PR hopefully

@mislav
mislav dismissed vilmibm’s stale review June 10, 2020 10:46

template chooser tests will be addressed in a separate changeset

@mislav
mislav merged commit 1c9c5e5 into cli:trunk Jun 10, 2020
@mislav

mislav commented Jun 10, 2020

Copy link
Copy Markdown
Contributor

@AliabbasMerchant @safv12 Each *_TEMPLATE value is only repeated twice, so for now I'm making a call that it's fine. Thank you!

@sebas-hdz2 sebas-hdz2 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow choosing a blank issue/pr template

5 participants