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

spr up seems to always trigger duplicate synchronize webhooks #207

Open
jsravn opened this issue Mar 3, 2022 · 7 comments
Open

spr up seems to always trigger duplicate synchronize webhooks #207

jsravn opened this issue Mar 3, 2022 · 7 comments
Labels
documentation Improvements or additions to documentation

Comments

@jsravn
Copy link

jsravn commented Mar 3, 2022

Hi, I'm enjoying this project a lot. It really helps the dev workflow on github. Thanks!

I'm encountering one issue - whenever I do a git spr up on an existing PR, it causes github to emit two identical synchronize webhooks. As a result, my CI system runs two duplicate builds.

AFAIK synchronize should only be issued when the source branch is updated. But whatever spr is doing under the hood causes github to issue it twice. Oddly, the contents are identical - even the headers are the same, except for the X-GitHub-Delivery value. (actually, not always, sometimes there is a 1 second difference in the pushed_at fields).

Here is an example log output of when it happens

❯ git spr up --detail
> git rev-parse --show-toplevel
> git fetch
> git rebase origin/main --autostash
> github fetch pull requests
> git branch
> git log origin/main..HEAD
> git status --porcelain --untracked-files=no
> git push --force --atomic origin 12461fb8173a3372c5f2d92c049525137edcf40a:refs/heads/pr/jsravn/fix-cd-controller-deploy/7cb948cd
> github update 545 - cd: Fix cd-controller role to be namespaced
> github fetch pull requests
> git branch

Might be the git push followed by the github update that causes it?

@jsravn jsravn changed the title spr up seems to always trigger duplicate Synchronize webhooks spr up seems to always trigger duplicate synchronize webhooks Mar 3, 2022
@ejoffe
Copy link
Owner

ejoffe commented Mar 3, 2022

You should be able to remove the github update call to test out your theory.
This call is there to update the stack part of the pr message body but it is not functionally required, so I think everything should still work ok. If this is the case, we can add a feature flag to disable the stack display of the pr message body.

index fa72383..d2e634c 100644
--- a/spr/spr.go
+++ b/spr/spr.go
@@ -191,7 +191,8 @@ func (sd *stackediff) UpdatePullRequests(ctx context.Context, reviewers []string
        sd.profiletimer.Step("UpdatePullRequests::updatePullRequests")

        for _, pr := range updateQueue {
-               sd.github.UpdatePullRequest(ctx, githubInfo, pr.pr, pr.commit, pr.prevCommit)
+               //      sd.github.UpdatePullRequest(ctx, githubInfo, pr.pr, pr.commit, pr.prevCommit)
+               _ = pr
        }

        sd.profiletimer.Step("UpdatePullRequests::commitUpdateQueue")```

@jsravn
Copy link
Author

jsravn commented Mar 3, 2022

Thanks, I'll give it a try. It sort of feels like a github bug to be honest - maybe there is a race between the api and the git push.

@ejoffe
Copy link
Owner

ejoffe commented Mar 3, 2022

pro tip:
If you have goreleaser installed, you can build the project using make bin
I alias my dev built spr so I can easily test it:
alias spr='/Users/eitan/Code/spr/dist/spr_darwin_amd64/git-spr'

@ejoffe ejoffe added the bug Something isn't working label Mar 31, 2022
@dan-v
Copy link
Contributor

dan-v commented Feb 2, 2023

I also ran into this duplicate issue with a CI workflow that had both push and pull_request events configured:

on:
  push:
    branches: [master]
  pull_request:
    branches: [master]

As spr does a push followed by an update of the pull request, as mentioned above, it was triggering this workflow twice. What actually happens is the first event fires on push, then the second event fires on PR update, the first workflow ends up getting cancelled while the second runs and succeeds. This ends up breaking spr 'github checks', as it's looking at the first cancelled workflow rather than the secondary run that succeeded, so you end up with a big red X for spr status even though the PR is really green.

For now, I ended up switching to triggering on all push events instead, which seems to works ok for this workflow as it still triggers for PRs and merges to master.

on:
  push:

@ejoffe ejoffe added documentation Improvements or additions to documentation and removed bug Something isn't working labels Jan 11, 2024
@ejoffe
Copy link
Owner

ejoffe commented Jan 11, 2024

Looks like the right approach is to use push events rather than pull_request events.
Could be worth while to add this into the readme somewhere.

@annervisser
Copy link

@jsravn Did you ever figure out the issue?
I have a tool that does pretty much exactly the same (git push followed by gh pr edit),
and I'm observing the same behaviour where the pull_request synchronize event is triggered twice.

@steinemann
Copy link

Is there any update on this ?
I recently also run into this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

5 participants