Kevin Web 894ba77d94 Fix OAuth token refresh in webhook handling for Bitbucket and GitHub (#6059)
## Summary

Fixes #5590
Fixes #5713

This PR fixes an issue where webhook handling fails with "failure to parse hook" error when the user's OAuth access token has expired. The root cause is that the Bitbucket and GitHub forge implementations make API calls during webhook processing without first refreshing the OAuth token.

## Problem

When a webhook arrives from Bitbucket or GitHub, the `Hook()` function (and its helper functions) make API calls to fetch additional data (changed files, repo info, etc.). These API calls use the stored OAuth access token, which may have expired.

**Before this fix:**
1. Webhook arrives
2. `Hook()` makes API calls with potentially expired token
3. API call fails with "OAuth2 access token expired"
4. Error bubbles up as HTTP 400 "failure to parse hook"
5. `forge.Refresh()` is called later in `PostHook()` - but it's too late

**Example error from logs:**

`failure to parse hook error="OAuth2 access token expired. Use your refresh token to obtain a new access token."`


## Solution

Add `forge.Refresh()` calls before making API calls in the webhook handling code paths. This follows the same pattern already used by:
- Bitbucket Data Center forge (`server/forge/bitbucketdatacenter/bitbucketdatacenter.go`)
- Other code paths like `pipeline.Create()`, `cron.go`, etc.

### Changes

**Bitbucket** (`server/forge/bitbucket/bitbucket.go`):
- Added `forge.Refresh()` in `Hook()` before API calls

**GitHub** (`server/forge/github/github.go`):
- Added `forge.Refresh()` in `loadChangedFilesFromPullRequest()`
- Added `forge.Refresh()` in `getTagCommitSHA()`
- Added `forge.Refresh()` in `loadChangedFilesFromCommits()`

## Testing

- All existing Bitbucket and GitHub forge tests pass
- Tested in production environment with Bitbucket (waited for token expiry, webhook succeeded after fix)
2026-02-03 13:34:01 +01:00
2025-09-28 22:05:56 +02:00
2026-02-02 17:47:01 +01:00
2025-06-27 08:36:07 +03:00
2024-11-23 09:17:19 +01:00
2025-10-21 12:19:39 +02:00
2022-06-17 12:03:34 +02:00
2024-01-11 18:43:54 +01:00
2024-12-28 15:36:23 +01:00
2023-12-30 15:10:31 +01:00
2026-01-14 13:23:05 +01:00

Woodpecker

Woodpecker


Pipeline Status Code coverage Translation status Matrix space Go Report Card go reference GitHub release Docker pulls License: Apache-2.0 OpenSSF best practices pre-commit.ci


Woodpecker is a simple, yet powerful CI/CD engine with great extensibility.

woodpecker

Installation & Resources

Woodpecker can be installed in various ways (see the Installation Instructions) and runs with SQLite as database by default. It requires around 100 MB of RAM (Server) and 30 MB (Agent) at runtime in idle mode.

Support

You can support the project by becoming a backer on Open Collective or via GitHub Sponsors.

Open Collective backers

Documentation

Our documentation can be found at https://woodpecker-ci.org/docs/intro.

Translation

We have a self-hosted Weblate instance at translate.woodpecker-ci.org.

An overview of the current translation state is available at https://translate.woodpecker-ci.org/projects/woodpecker-ci/#languages.

Public Woodpecker Instances

Woodpecker is used as the main CI/CD engine at Codeberg, an alternative Git hosting platform with a focus on privacy and free software development.

Plugins

Woodpecker can be extended via plugins. The plugin overview website helps browsing available plugins. It combines both plugins by the Woodpecker core team and community-maintained ones.

Star History

Star History Chart

License

Woodpecker is Apache 2.0 licensed. The source files have a header indicating which license they are under and what copyrights apply.

Everything in docs/ is licensed under the Creative Commons Attribution-ShareAlike 4.0 International Public License.

Description
Woodpecker is a community fork of the Drone CI system.
Readme 223 MiB
Languages
Go 84.3%
Vue 10.8%
TypeScript 3.6%
Makefile 0.8%
CSS 0.4%