Skip to content

Allow explicitly empty body in issue/pr create#3787

Merged
mislav merged 5 commits intotrunkfrom
editor-tests
Jun 15, 2021
Merged

Allow explicitly empty body in issue/pr create#3787
mislav merged 5 commits intotrunkfrom
editor-tests

Conversation

@mislav
Copy link
Contributor

@mislav mislav commented Jun 4, 2021

In issue/pr create, choosing a template but then opening your editor and deleting all contents there should be submitting a blank body, in my opinion, since you've explicitly deleted all contents. But this wasn't happening for two reasons:

  1. We used to treat Body == "" as a special case that meant "user has skipped editing". (We quit doing that in Handle default body text when creating issues and pull requests #3658, but the code that appended the template to a blank body still remained.) Fixes PR body(description) is not reflecting as empty even after removing the content completely #1294
  2. Even if the user tried to submit a blank body via browser, the &body= query parameter wasn't present, and thus the web interface would apply the template body again.

Bonus:

Manual testing note: to test saving a completely empty file in vim, I would have to do :set noendofline nofixendofline, since otherwise vim always includes a trailing newline (and thus the resulting string wouldn't be empty).

/cc @chemotaxis

mislav added 3 commits June 4, 2021 20:06
There was a race condition wherein the test didn't wait enough time for
the prompt to get rendered before testing the terminal output.
@mislav mislav changed the title Editor tests Allow explicitly empty body in issue/pr create Jun 4, 2021
if state.Body != "" {
q.Set("body", state.Body)
}
// We always want to set body, even if it's empty, to prevent the web interface to apply the default
Copy link
Contributor

Choose a reason for hiding this comment

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

A nitpick, but "...to prevent the web interface from applying the default..." sounds better than "...to prevent the web interface to apply the default...".

@chemotaxis
Copy link
Contributor

chemotaxis commented Jun 5, 2021

I still have concerns about the if statement that I mentioned in the other issue. This potentially still overwrites a blank body if you didn't set e.AppendDefault for some reason, but still set e.Default. It'd be nice to know why this if statement is still needed.

Also, do you think adding an if statement at the end of surveyext.GhEditor.prompt() to overwrite a body that only contained whitespace would be appropriate? By default, a lot of editors will add a newline on save, even if you deleted everything.

@mislav
Copy link
Contributor Author

mislav commented Jun 8, 2021

I still have concerns about the if statement that I mentioned in the other issue. This potentially still overwrites a blank body if you didn't set e.AppendDefault for some reason, but still set e.Default. It'd be nice to know why this if statement is still needed.

That statement is copied from upstream where it's a feature of the Survey library that we are using. I don't see our need for it, but I didn't want to delete it because I didn't want to introduce unnecessary changes that diverge from upstream. You are right that if e.AppendDefault wasn't set, we would still be back on square one. Fortunately, we are consistently using e.AppendDefault in issue/pr create and issue/pr edit.

Also, do you think adding an if statement at the end of surveyext.GhEditor.prompt() to overwrite a body that only contained whitespace would be appropriate? By default, a lot of editors will add a newline on save, even if you deleted everything.

That would be smart, but again, we inherited this code from upstream, so best not change it without a strong reason. Also, this PR eliminates what I think is the last active special-casing of an empty body post-editing, so in doesn't matter whether we normalize whitespace or not.

Copy link
Contributor

@samcoe samcoe left a comment

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. I like that we now have better test coverage for surveyext. The new tests did take a couple read throughs to fully understand what was happening but I couldn't think of a cleaner way to write them.

}

func TestHelperProcess(t *testing.T) {
if os.Getenv("GH_WANT_HELPER_PROCESS") != "1" {
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the purpose of having the GH_WANT_HELPER_PROCESS check? Seems like it is a precautionary measure, but I can't think of the case it is guarding against.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The TestHelperProcess function needs to be skipped during normal test run. It should only be active when invoked as a subprocess

@mislav
Copy link
Contributor Author

mislav commented Jun 15, 2021

The new tests did take a couple read throughs to fully understand what was happening but I couldn't think of a cleaner way to write them.

Yeah, tests for event-handling functionality are tricky because we have to have at minimum of 2 goroutines to test it. I went with a few different approaches and this was the cleanest I could come up with.

@mislav mislav merged commit 543a17d into trunk Jun 15, 2021
@mislav mislav deleted the editor-tests branch June 15, 2021 14:17
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.

PR body(description) is not reflecting as empty even after removing the content completely

3 participants