Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Upgraded `nodemailer` to `^9.0.1`. [#1356](https://github.com/sourcebot-dev/sourcebot/pull/1356)
- Upgraded `@opentelemetry/core` to `^2.8.0`. [#1413](https://github.com/sourcebot-dev/sourcebot/pull/1413)
- [EE] Fixed connector setup dialogs to add scrolling when connector setup content goes out of view.
- Fixed Gitea sync failing with `ERR_STREAM_PREMATURE_CLOSE` by forcing identity encoding on the Gitea API fetch and guarding against null repository responses. [#1405](https://github.com/sourcebot-dev/sourcebot/pull/1405)

## [5.0.4] - 2026-06-18

Expand Down
27 changes: 25 additions & 2 deletions packages/backend/src/gitea.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,22 @@ import { measure } from './utils.js';
const logger = createLogger('gitea');
const GITEA_CLOUD_HOSTNAME = "gitea.com";

// Some Gitea instances (particularly when behind certain reverse proxies or with
// response compression enabled) cause `cross-fetch` to fail while reading the
// response body with ERR_STREAM_PREMATURE_CLOSE. Forcing identity encoding and
// closing the connection avoids the premature close.
// @see https://github.com/sourcebot-dev/sourcebot/issues/1404
const customFetch: typeof fetch = (url, options = {}) => {
return fetch(url, {
...options,
headers: {
...(options.headers ?? {}),
'Accept-Encoding': 'identity',
'Connection': 'close',
},
});
};
Comment thread
brendan-kellam marked this conversation as resolved.

export const getGiteaReposFromConfig = async (config: GiteaConnectionConfig) => {
const hostname = config.url ?
new URL(config.url).hostname :
Expand All @@ -25,7 +41,7 @@ export const getGiteaReposFromConfig = async (config: GiteaConnectionConfig) =>

const api = giteaApi(config.url ?? 'https://gitea.com', {
token: token,
customFetch: fetch,
customFetch,
});

let allRepos: GiteaRepository[] = [];
Expand All @@ -49,8 +65,11 @@ export const getGiteaReposFromConfig = async (config: GiteaConnectionConfig) =>
allWarnings = allWarnings.concat(warnings);
}

allRepos = allRepos.filter(repo => repo.full_name !== undefined);
allRepos = allRepos.filter(repo => {
if (repo === null || repo === undefined) {
logger.warn(`Skipping null/undefined repository returned by the Gitea API`);
return false;
}
if (repo.full_name === undefined) {
logger.warn(`Repository with undefined full_name found: repoId=${repo.id}`);
return false;
Expand Down Expand Up @@ -208,6 +227,10 @@ const getRepos = async <T>(repoList: string[], api: Api<T>) => {
api.repos.repoGet(owner, repoName),
);

if (response.error || !response.data) {
throw response.error ?? new Error(`Received empty response body while fetching repository ${repo}`);
}

Comment thread
brendan-kellam marked this conversation as resolved.
logger.debug(`Found repo ${repo} in ${durationMs}ms.`);
return {
type: 'valid' as const,
Expand Down
Loading