-
Notifications
You must be signed in to change notification settings - Fork 145
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
base: master
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
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. |
repoName := strings.ToLower(repo.GetFullName()) | ||
commentID := event.GetComment().GetID() |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
server/plugin/webhook.go
Outdated
post := &model.Post{ | ||
UserId: p.BotUserID, | ||
Type: "custom_git_pr", | ||
} |
There was a problem hiding this comment.
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?
repoName := strings.ToLower(repo.GetFullName()) | ||
commentID := event.GetComment().GetID() |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
@mickmister Can we please fix the lint errors here ? |
@AayushChaudhary0001 Can you take a look at this PR when you have the chance? Essentially all webhook events need to be tested |
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