Add support for last comment edit by seachicken · Pull Request #6384 · cli/cli · GitHub
Skip to content

Add support for last comment edit#6384

Merged
samcoe merged 11 commits into
cli:trunkfrom
seachicken:issue3613
Oct 18, 2022
Merged

Add support for last comment edit#6384
samcoe merged 11 commits into
cli:trunkfrom
seachicken:issue3613

Conversation

@seachicken

Copy link
Copy Markdown
Contributor

Fixes #3613

Add --edit-last option to issue/pr comment.
This option edits the last comment that you are the author of. If the comment does not exist, a new one is added.
This is mainly useful when editing comments by the bot.

@seachicken seachicken requested a review from a team as a code owner October 1, 2022 23:44
@seachicken seachicken requested review from vilmibm and removed request for a team October 1, 2022 23:44
@cliAutomation cliAutomation added the external pull request originating outside of the CLI core team label Oct 1, 2022
@seachicken seachicken marked this pull request as draft October 2, 2022 02:24
Comment thread pkg/cmd/pr/shared/commentable.go Outdated

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.

api.CurrentLoginName is retrieved as "github-actions[bot]" when executed with GitHub Actions GITHUB_TOKEN: ${{ github.token }}, but Comment.Author.Login will be retrieved under a different name, "github-actions", so there is no match.
Should I trim "[bot]" if it is "github-actions[bot]"?

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.

When creating a PAT, --edit-last works fine, but when using github.token in CI, there is a problem with the username not matching and not getting the last comment.
I don't know why the names don't match, should I create an issue?

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.

@seachicken What is the error you are receiving? Is it showing the incorrect user or not retrieving any user at all?

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.

I get an incorrect username.
api.CurrentLoginName returns "github-actions[bot]"
Comment.Author.Login returns "github-actions"

@seachicken seachicken marked this pull request as ready for review October 2, 2022 04:52
vilmibm
vilmibm previously requested changes Oct 4, 2022

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

Nice start! I'd like to see the comment's body populated in the editor, however, otherwise it's not really an edit operation. I'd also like to see more robust tests -- in other words, test cases that actually cover this new behavior.

@seachicken

Copy link
Copy Markdown
Contributor Author

Now works in combination with other commands.
--editor --edit-last: The last comment can be edited in the editor
--web --edit-last: The last comment can be displayed on the web

@seachicken seachicken requested a review from vilmibm October 6, 2022 22:56

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

@seachicken Thanks for working on this. There are some changes I would like to see in Commentable that are mostly about keeping the code clear and maintaining the original intent of Commentable. I added the comments inline so please let me know if you have any questions regarding them.

Comment thread pkg/cmd/pr/shared/commentable.go Outdated
Comment thread pkg/cmd/pr/shared/commentable.go Outdated
Comment thread pkg/cmd/pr/shared/commentable.go Outdated
@seachicken seachicken requested review from samcoe and removed request for vilmibm October 12, 2022 23:25
@samcoe samcoe self-assigned this Oct 13, 2022

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

@seachicken Thanks for making the requested changes! I pushed a small commit adding a bit of polish 💅. This looks ready to ship.

Only question I have is about the name of the flag. --edit-last was agreed upon in the issue but with the upsert functionality do we think we should reevaluate the flag name? @vilmibm @mislav what are your thoughts?

@samcoe samcoe requested a review from vilmibm October 13, 2022 08:27
@mislav

mislav commented Oct 17, 2022

Copy link
Copy Markdown
Contributor

As a person who first floated the idea of "upsert" functionality in the original issue, I don't think that this functionality needs or should be part of --edit-last, since that would be a misnomer. I think --edit-last should only edit the last comment and error out if there isn't an existing one.

@samcoe

samcoe commented Oct 18, 2022

Copy link
Copy Markdown
Contributor

I went ahead and made the change to remove the upsert functionality and also I fixed the issue with comparing username strings for bots by switching to use the ViewerDidAuthor field on comments. By not relying on there username string I was also able to remove the API call to retrieve the current user.

@samcoe samcoe dismissed vilmibm’s stale review October 18, 2022 08:02

Changes requested have been addressed.

@samcoe samcoe enabled auto-merge (squash) October 18, 2022 08:02
@samcoe samcoe merged commit e523d50 into cli:trunk Oct 18, 2022
Comment thread pkg/cmd/pr/shared/commentable.go Outdated

comments := commentable.CommentsForUser(username)
if len(comments) == 0 {
return fmt.Errorf("no comments created by %s found", username)

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 error when there is no comment makes it hard to use it from the bot. I and the original issue would like an option to use it from the bot.
If --edit-last is not a good name, it would be more convenient to use an option name such as --upsert to avoid the error.

@seachicken seachicken Oct 18, 2022

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.

@samcoe @mislav Can you confirm this problem?

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.

@seachiken The team decided that the upsert functionality added complexity and confusion due to the naming of the flag. We also decided that it doesn't need to be built in since it is easy enough to recreate it by first doing issue comment --edit-last and if that fails then doing issue comment.

Comment thread api/queries_comments.go

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.

I didn't know that. Great!

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

Labels

external pull request originating outside of the CLI core team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support updating comments/reviews

5 participants