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

Edit issue command #2915

Merged
merged 4 commits into from Feb 12, 2021
Merged

Edit issue command #2915

merged 4 commits into from Feb 12, 2021

Conversation

samcoe
Copy link
Contributor

@samcoe samcoe commented Feb 4, 2021

This PR implements the issue edit command allowing the ability to update an already created issue. I extracted code that will be used for the pr edit command into the editable file. Overall the command behavior is very similar to issue create and pr create.

Screen Shot 2021-02-04 at 11 15 14 AM

Screen Shot 2021-02-04 at 11 14 52 AM

closes #904
follow ups #2940 #2949

@samcoe samcoe self-assigned this Feb 4, 2021
@samcoe samcoe marked this pull request as ready for review February 4, 2021 19:16
Copy link
Contributor

@mislav mislav left a comment

Choose a reason for hiding this comment

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

The code looks pretty solid; great work!

Before I approve, something that I feel needs clarifying: then supplying values via flags, e.g. gh issue edit --label foo --label bar, will this add the foo + bar labels to the set of existing labels, or replace all old labels? From the flags documentation, it sounds like new labels will be added, but from my reading of the code, it sounds like the whole set will get replaced.

Would there be a way to non-interactively explicitly add a label (preserving old ones), remove a specific label, or clear all existing labels?

pkg/cmd/issue/edit/edit.go Outdated Show resolved Hide resolved
Comment on lines 25 to 29
OpenInBrowser func(string) error
DetermineEditor func() (string, error)
FieldsToEditSurvey func(*prShared.EditableOptions) error
EditableSurvey func(string, *prShared.EditableOptions) error
FetchOptions func(*api.Client, ghrepo.Interface, *prShared.EditableOptions) error
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of passing around funcs for the purpose of stubbing in tests—even though that is the pattern that we practiced before—how about we consider gradually moving to interfaces? It would allow the same kind of dependency injection, with the added benefit of better readability/being more idiomatic Go.

You don't have to rewrite all of these; I'm just wondering whether you think that accepting interfaces and then substituting the concrete implementation object in tests would be an approach that could make the above cleaner.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I like the interface approach and generally think it is better. I mostly just forgot that we had discussed it when I wrote this and ended up falling back on what we had been doing.

My only real complaint with the interface approach is that it doesn't seem to bring much improvement when the interface defines only one function and results in slightly more code. I do think bundling up the survey functions into a surveyAsker interface, as seen in the gist, is great though.

I will keep the idea top of mind when I do the pr edit command and see how that goes, and if it works well I will come back and update this command.

@samcoe
Copy link
Contributor Author

samcoe commented Feb 5, 2021

@mislav That is a great question about the non-interactive flow. The code does replace the assignee/label/project value completely rather than adding to the existing field and so if we decided to keep this behavior I will update the documentation to reflect that.

If we want to also support adding/removing/clearing values of fields that accept arrays of values we would probably want to introduce new flags such as --add-label, --remove-label, --clear-label. I can't think of a nice way to do this with one flag that does not lead to confusion. I do see value in supporting these sorts of operations, but I am wondering if that can be implemented as a separate feature?

Copy link
Contributor

@vilmibm vilmibm left a comment

Choose a reason for hiding this comment

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

Looks awesome, thank you!

For the --label question, I'd love the ability to add labels incrementally or replace wholesale, but I'm fine with it being beyond the scope of this PR. I think for this PR having --label replace wholesale is fine. As a follow up I'd like to explore an --add flag that changes the meaning of the various fields -- ie they all become additive (not just labels).

@mislav
Copy link
Contributor

mislav commented Feb 8, 2021

I do see value in supporting these sorts of operations, but I am wondering if that can be implemented as a separate feature?

Of course, since that adds the complexity of extra flags, it can absolutely be done as follow-up. However, I do see features of adding/removing a label (or assignee, project, etc) as being vastly more useful than replacing the whole set of labels. In fact, I can't really think of a use case where I would want to replace the whole set. On the web, that operation is not even possible. That's why I feel that adding/removing functionality should be a priority over replacing.

I can't think of a nice way to do this with one flag that does not lead to confusion.

Some CLI tools support syntaxes like --flag +foo,+bar,-baz to denote add/remove operations from a set, but I'm not sure if we should go in that direction, especially because operators + and - are themselves valid characters in a label.

@billygriffin
Copy link
Contributor

I do see features of adding/removing a label (or assignee, project, etc) as being vastly more useful than replacing the whole set of labels. In fact, I can't really think of a use case where I would want to replace the whole set. On the web, that operation is not even possible. That's why I feel that adding/removing functionality should be a priority over replacing.

I'm in strong agreement with this. I'd be concerned about us shipping something where adding a label via gh just overwrites all existing labels. I'm curious if @ampinsk has thoughts on how to address this.

@ampinsk
Copy link
Contributor

ampinsk commented Feb 10, 2021

I'm in strong agreement with this. I'd be concerned about us shipping something where adding a label via gh just overwrites all existing labels. I'm curious if @ampinsk has thoughts on how to address this.

I'm also in agreement here. A default behavior of adding labels is much less destructive and more expected than replacing.

This behavior and syntax is a good question. Separating these behaviors out into --add-label --remove-label at minimum feels simple and intuitive at least as a start? Also agree this could be a follow up.

@samcoe samcoe requested a review from a team February 11, 2021 19:16
Copy link
Contributor

@mislav mislav left a comment

Choose a reason for hiding this comment

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

Looks great! Thank you for the hard work 🏆

}

if contains(results, "Title") {
options.TitleEdited = true
Copy link
Contributor

Choose a reason for hiding this comment

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

Tiny naming oddity: it's a bit weird that simply declaring your intent that you want to edit the title would set the opts.TitleEdited field to true, and that the same field is used when --title was passed on the command-line. But, I guess it works!

@samcoe samcoe merged commit 4109af9 into trunk Feb 12, 2021
@samcoe samcoe deleted the issue-edit branch February 12, 2021 17:50
@vilmibm vilmibm added this to Backlog 🗒 in The GitHub CLI via automation Feb 17, 2021
@vilmibm vilmibm moved this from Backlog 🗒 to Pending Release 🥚 in The GitHub CLI Feb 17, 2021
@github-actions github-actions bot moved this from Pending Release 🥚 to Done 💤 in The GitHub CLI Feb 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
The GitHub CLI
  
Done 💤
Development

Successfully merging this pull request may close these issues.

Ability to edit title/body/metadata of already open issue
5 participants