Skip to content

fix(bitbucketdatacenter): ignore branch deletion events in ParsePayload #2126

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

infernus01
Copy link

@infernus01 infernus01 commented Jun 12, 2025

Changes

When a branch is deleted in Bitbucket Data Center, the repo:refs_changed webhook event contains a toHash with a zero SHA (0000000000000000000000000000000000000000). Previously, Pipelines as Code would attempt to process this event as a push, resulting in commit validation failures and noisy logs.
This patch updates the ParsePayload function to detect and ignore such events early, returning (nil, nil) when a branch deletion is detected. This ensures branch deletions are not processed like standard push events.
Fixes #2035
/kind bug

Submitter Checklist

  • 📝 Ensure your commit message is clear and informative. Refer to the How to write a git commit message guide. Include the commit message in the PR body rather than linking to an external site (e.g., Jira ticket).

  • ♽ Run make test lint before submitting a PR to avoid unnecessary CI processing. Consider installing pre-commit and running pre-commit install in the repository root for an efficient workflow.

  • ✨ We use linters to maintain clean and consistent code. Run make lint before submitting a PR. Some linters offer a --fix mode, executable with make fix-linters (ensure markdownlint and golangci-lint are installed).

  • 📖 Document any user-facing features or changes in behavior.

  • 🧪 While 100% coverage isn't required, we encourage unit tests for code changes where possible.

  • 🎁 If feasible, add an end-to-end test. See README for details.

  • 🔎 Address any CI test flakiness before merging, or provide a valid reason to bypass it (e.g., token rate limitations).

  • If adding a provider feature, fill in the following details:

    • GitHub App
    • GitHub Webhook
    • Gitea/Forgejo
    • GitLab
    • Bitbucket Cloud
    • Bitbucket Data Center

    (update the provider documentation accordingly)

@infernus01
Copy link
Author

/cc @zakisk @chmouel

@chmouel
Copy link
Member

chmouel commented Jun 12, 2025

/ok-to-test

@chmouel
Copy link
Member

chmouel commented Jun 12, 2025

this will fail because your commit message is not gitlint compatible

Gitlint..................................................................Failed
- hook id: gitlint
- exit code: 2

3: B6 Body message is missing
make: *** [Makefile:119: gitlint] Error 1
3: B6 Body message is missing
make: *** [Makefile:119: gitlint] Error 1

please consider installing pre-commit job

@zakisk
Copy link
Contributor

zakisk commented Jun 13, 2025

/ok-to-test

1 similar comment
@chmouel
Copy link
Member

chmouel commented Jun 13, 2025

/ok-to-test

@chmouel
Copy link
Member

chmouel commented Jun 13, 2025

A mirrored PR has been created for E2E testing: #2130

@zakisk
Copy link
Contributor

zakisk commented Jun 13, 2025

@chmouel E2E tests are running here?

@infernus01
Copy link
Author

One of the e2e tests (TestGiteaACLCommentsAllowing/Retest) failed, but from reviewing the logs, it looks unrelated to this patch.
All other checks including pre-commit, unit tests and gitlint have passed.

@chmouel
Copy link
Member

chmouel commented Jun 13, 2025

@zakisk ah that's actually a nice github behaviour side effect, because we have the same SHA from the mirrored PR, github automatically sees it on this PR as well

@zakisk
Copy link
Contributor

zakisk commented Jun 13, 2025

so check-runs are posted in both PRs? that's nice though

Comment on lines 158 to 162
for _, change := range e.Changes {
if change.ToHash == "0000000000000000000000000000000000000000" {
return nil, nil
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
for _, change := range e.Changes {
if change.ToHash == "0000000000000000000000000000000000000000" {
return nil, nil
}
}
for _, change := range e.Changes {
if change.ToHash == "0000000000000000000000000000000000000000" && change.Type == "DELETE {
return nil, nil
}
}

@infernus01 if you see in payload changes have type: DELETE so it would be good if you add this condition with &&

"changes": [{
        "ref": {
            "id": "refs/heads/test-26196",
            "displayId": "test-26196",
            "type": "BRANCH"
        },
        "fromHash": "abda6907a37c451017acea247ee22d2dc457e1aa",
        "toHash": "0000000000000000000000000000000000000000",
        "refId": "refs/heads/test-26196",
        "type": "DELETE"
    }]

Copy link
Member

Choose a reason for hiding this comment

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

I think that change to make is for you @infernus01 :)

Copy link
Author

Choose a reason for hiding this comment

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

PTAL

When a branch is deleted in Bitbucket Data Center, the repo:refs_changed
webhook sends a change with toHash set to all-zeros. Previously, Pipelines
as Code treated this like a push event, which caused errors when trying
to validate a missing commit.

This patch detects and ignores such events early in ParsePayload.

Fixes openshift-pipelines#2035
@chmouel
Copy link
Member

chmouel commented Jun 19, 2025

/ok-to-test

@chmouel
Copy link
Member

chmouel commented Jun 19, 2025

/ok-to-test

@chmouel
Copy link
Member

chmouel commented Jun 19, 2025

you had a fumpt error which i have pushed to your branch to fix

@infernus01
Copy link
Author

Oh I see, but the failing of test persists, with the error:
The Service "gitea" is invalid: spec.ports[0].nodePort: Invalid value: 32567: provided port is already allocated

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

Successfully merging this pull request may close these issues.

Invalidate branch delete event on Bitbucket Data Center
3 participants