Skip to content

Commit 9a70366

Browse files
authored
fix(gitlab): Fix auth error when trying to sync public gitlab.com project with no token (#748)
* fix gitlab init * changelog
1 parent 47ec6e8 commit 9a70366

File tree

4 files changed

+10
-9
lines changed

4 files changed

+10
-9
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1919

2020
### Fixed
2121
- Fixed issue with filtering on generic git repo indexed from http/https [#742](https://github.com/sourcebot-dev/sourcebot/pull/742)
22+
- Fixed auth error when trying to sync public gitlab.com project with no token [#748](https://github.com/sourcebot-dev/sourcebot/pull/748)
2223
- Fixed "Ranges must be added sorted by `from` position and `startSide`" error when browsing certain files. [#743](https://github.com/sourcebot-dev/sourcebot/pull/743)
2324

2425
## [4.10.10] - 2026-01-16

packages/backend/src/ee/repoPermissionSyncer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ export class RepoPermissionSyncer {
177177

178178
const accountIds = await (async () => {
179179
if (repo.external_codeHostType === 'github') {
180-
const isGitHubCloud = credentials.hostUrl ? new URL(credentials.hostUrl).hostname === GITHUB_CLOUD_HOSTNAME : false;
180+
const isGitHubCloud = credentials.hostUrl ? new URL(credentials.hostUrl).hostname === GITHUB_CLOUD_HOSTNAME : true;
181181
const { octokit } = await createOctokitFromToken({
182182
token: credentials.token,
183183
url: isGitHubCloud ? undefined : credentials.hostUrl,

packages/backend/src/github.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const isHttpError = (error: unknown, status: number): boolean => {
4747
}
4848

4949
export const createOctokitFromToken = async ({ token, url }: { token?: string, url?: string }): Promise<{ octokit: Octokit, isAuthenticated: boolean }> => {
50-
const isGitHubCloud = url ? new URL(url).hostname === GITHUB_CLOUD_HOSTNAME : false;
50+
const isGitHubCloud = url ? new URL(url).hostname === GITHUB_CLOUD_HOSTNAME : true;
5151
const octokit = new Octokit({
5252
auth: token,
5353
...(url && !isGitHubCloud ? {

packages/backend/src/gitlab.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ const logger = createLogger('gitlab');
1212
export const GITLAB_CLOUD_HOSTNAME = "gitlab.com";
1313

1414
export const createGitLabFromPersonalAccessToken = async ({ token, url }: { token?: string, url?: string }) => {
15-
const isGitLabCloud = url ? new URL(url).hostname === GITLAB_CLOUD_HOSTNAME : false;
15+
const isGitLabCloud = url ? new URL(url).hostname === GITLAB_CLOUD_HOSTNAME : true;
1616
return new Gitlab({
17-
token,
17+
...(token ? { token } : {}),
1818
...(isGitLabCloud ? {} : {
1919
host: url,
2020
}),
@@ -23,9 +23,9 @@ export const createGitLabFromPersonalAccessToken = async ({ token, url }: { toke
2323
}
2424

2525
export const createGitLabFromOAuthToken = async ({ oauthToken, url }: { oauthToken?: string, url?: string }) => {
26-
const isGitLabCloud = url ? new URL(url).hostname === GITLAB_CLOUD_HOSTNAME : false;
26+
const isGitLabCloud = url ? new URL(url).hostname === GITLAB_CLOUD_HOSTNAME : true;
2727
return new Gitlab({
28-
oauthToken,
28+
...(oauthToken ? { oauthToken } : {}),
2929
...(isGitLabCloud ? {} : {
3030
host: url,
3131
}),
@@ -99,7 +99,7 @@ export const getGitLabReposFromConfig = async (config: GitlabConnectionConfig) =
9999
const status = e?.cause?.response?.status;
100100
if (status !== undefined) {
101101
const warning = `GitLab API returned ${status}`
102-
logger.warning(warning);
102+
logger.warn(warning);
103103
return {
104104
type: 'warning' as const,
105105
warning
@@ -139,7 +139,7 @@ export const getGitLabReposFromConfig = async (config: GitlabConnectionConfig) =
139139
const status = e?.cause?.response?.status;
140140
if (status !== undefined) {
141141
const warning = `GitLab API returned ${status}`
142-
logger.warning(warning);
142+
logger.warn(warning);
143143
return {
144144
type: 'warning' as const,
145145
warning
@@ -177,7 +177,7 @@ export const getGitLabReposFromConfig = async (config: GitlabConnectionConfig) =
177177
const status = e?.cause?.response?.status;
178178
if (status !== undefined) {
179179
const warning = `GitLab API returned ${status}`
180-
logger.warning(warning);
180+
logger.warn(warning);
181181
return {
182182
type: 'warning' as const,
183183
warning

0 commit comments

Comments
 (0)