lab132 / buildbot-gitea

Buildbot plugin for integration with gitea.
MIT License
62 stars 21 forks source link

`branch` attribute of change incorrectly set to base branch and not head branch #43

Open MagicRB opened 3 months ago

MagicRB commented 3 months ago

While working on https://github.com/nix-community/buildbot-nix I've noticed that al PR changes are considered as changes to master branch, which differs from what the upstream GitHub upstream webhook handler does, see the attached screenshots:

image

image

I think the problem is here, because the branch attribute of the change is set to base["branch"] when I think it should be head["branch"].

https://github.com/lab132/buildbot-gitea/blob/master/buildbot_gitea/webhook.py#L102

pampersrocker commented 3 months ago

I think we are experiencing a similar problem in our own case at the moment, as a PR request also triggers a build on the main branch on our own setup.

MagicRB commented 3 months ago

I'll open a PR with the changes that fixed it for me, can you test if it helps you too? but also we have

            # build all pull requests
            schedulers.SingleBranchScheduler(
                name=f"{project.project_id}-prs",
                change_filter=util.ChangeFilter(
                    repository=project.url,
                    category="pull",
                ),
                builderNames=[f"{project.name}/nix-eval"],
            ),
                        schedulers.SingleBranchScheduler(
                name=f"{project.project_id}-default-branch",
                change_filter=util.ChangeFilter(
                    repository=project.url,
                    filter_fn=lambda c: c.branch == project.default_branch,
                ),
                builderNames=[f"{project.name}/nix-eval"],
                treeStableTimer=5,
            ),

we did not experience duplicate build, Gitea sends two webhooks for each PR push, so I think that's discarding one of them. We were only seeing the one incorrectly attributed to master

pampersrocker commented 3 months ago

There has been some discussion on this on this PR: https://github.com/lab132/buildbot-gitea/pull/21 it's been some time, but the in-between fork stuff etc is a bit and gitea is also a bit different than github in that regard (at least it was, not sure if that has changed in the meantime)

MagicRB commented 3 months ago

For us it works mostly, except for the branch property being incorrect, which is why I didn't notice. But our code is a bit :sparkle: special :sparkle: