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

Fix PR subscription error "You cannot update an existing Post" #755

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

mickmister
Copy link
Member

Summary

This PR fixes an issue in the pull request event webhook logic where we reuse the same post struct for multiple calls to CreatePost, resulting in this error:

CreatePost: You cannot update an existing Post.

This PR applies a fix to make it so we instantiate a Post struct in the subscriptions loop, and only when we are going to create a post for that given subscription for the most part.

Ticket Link

Fixes #754

@mickmister mickmister added 2: Dev Review Requires review by a core committer 3: QA Review Requires review by a QA tester labels Mar 21, 2024
@mickmister mickmister requested a review from hanzei as a code owner March 21, 2024 13:54
@codecov-commenter
Copy link

codecov-commenter commented Mar 21, 2024

Codecov Report

Attention: Patch coverage is 0% with 68 lines in your changes are missing coverage. Please review.

Project coverage is 16.16%. Comparing base (da4c4df) to head (e6c087f).
Report is 3 commits behind head on master.

Current head e6c087f differs from pull request most recent head 35851e2

Please upload reports for the commit 35851e2 to get more accurate results.

Files Patch % Lines
server/plugin/webhook.go 0.00% 68 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master     #755   +/-   ##
=======================================
  Coverage   16.16%   16.16%           
=======================================
  Files          17       17           
  Lines        6021     6021           
=======================================
  Hits          973      973           
  Misses       5003     5003           
  Partials       45       45           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment on lines +825 to +826
repoName := strings.ToLower(repo.GetFullName())
commentID := event.GetComment().GetID()
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can move this out of the loop

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure 👍 I was mainly keeping it close to the post for readability, but you're right it doesn't need to be in the loop

Copy link
Contributor

Choose a reason for hiding this comment

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

1/5 that getting the commentID and assigning it as a prop should stay together as they semantically belong together.

Copy link
Member Author

Choose a reason for hiding this comment

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

@ayusht2810 Note that these methods being called are not performing network requests. They are essentially helper methods that are accessing fields on the struct for us. @hanzei Sure we can keep it as is. strings.ToLower is happening each time but that's the only concern I could potentially have. The repo name is always going to be short.

Copy link
Member Author

Choose a reason for hiding this comment

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

@ayusht2810 I chose to keep this code as is. Let me know what you think

Copy link
Contributor

Choose a reason for hiding this comment

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

@mickmister Sure, that's fine with me.

server/plugin/webhook.go Show resolved Hide resolved
Copy link
Contributor

@hanzei hanzei left a comment

Choose a reason for hiding this comment

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

Should the code in postDeleteEvent also get updated? It seems to suffer from the same issue.

Comment on lines 414 to 417
post := &model.Post{
UserId: p.BotUserID,
Type: "custom_git_pr",
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we move the post creation into a separate method and reuse it?

Comment on lines +825 to +826
repoName := strings.ToLower(repo.GetFullName())
commentID := event.GetComment().GetID()
Copy link
Contributor

Choose a reason for hiding this comment

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

1/5 that getting the commentID and assigning it as a prop should stay together as they semantically belong together.

Copy link
Contributor

Choose a reason for hiding this comment

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

I would love to see tests for these changes. One can only dream...

Copy link
Member Author

Choose a reason for hiding this comment

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

@hanzei Sure I think I can do that. May take a bit to get to this. This is currently affecting community, and maybe other servers without them realizing it. @ayusht2810 Are you able to look into this (writing unit tests)?

@hanzei Is this a requirement to merge? Also are you thinking this could replace the manual QA for this? We also need to itemize the changes so QA knows what to look into

Copy link
Contributor

Choose a reason for hiding this comment

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

No, the tests are not a requirement.

The lack of tests is one of the reasons that heavy manual QA testing is required.

Copy link
Contributor

@hanzei hanzei left a comment

Choose a reason for hiding this comment

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

Should the code in postDeleteEvent also get updated? It seems to suffer from the same issue.

@Kshitij-Katiyar
Copy link
Contributor

@mickmister Can we please fix the lint errors here ?

@mickmister
Copy link
Member Author

@AayushChaudhary0001 Can you take a look at this PR when you have the chance? Essentially all webhook events need to be tested

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2: Dev Review Requires review by a core committer 3: QA Review Requires review by a QA tester
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix PR subscription error "You cannot update an existing Post"
5 participants