Skip to content

Commit a8ee664

Browse files
authored
fix(forgejo): support fallback for all forgejo-* host types (#39968)
* fix: support fallback for forgejo-* host types * Sort imports * Reorganize code to lexicographical order
1 parent a39c529 commit a8ee664

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

lib/util/http/auth.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { isNonEmptyString, isString } from '@sindresorhus/is';
22
import type { Options } from 'got';
33
import {
4+
FORGEJO_API_USING_HOST_TYPES,
45
GITEA_API_USING_HOST_TYPES,
56
GITHUB_API_USING_HOST_TYPES,
67
GITLAB_API_USING_HOST_TYPES,
@@ -36,6 +37,11 @@ export function applyAuthorization<GotOptions extends AuthGotOptions>(
3637
} else {
3738
options.headers.authorization = `${authType} ${options.token}`;
3839
}
40+
} else if (
41+
options.hostType &&
42+
FORGEJO_API_USING_HOST_TYPES.includes(options.hostType)
43+
) {
44+
options.headers.authorization = `Bearer ${options.token}`;
3945
} else if (
4046
options.hostType &&
4147
GITEA_API_USING_HOST_TYPES.includes(options.hostType)

lib/util/http/host-rules.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { GlobalConfig } from '../../config/global';
33
import {
44
BITBUCKET_API_USING_HOST_TYPES,
55
BITBUCKET_SERVER_API_USING_HOST_TYPES,
6+
FORGEJO_API_USING_HOST_TYPES,
67
GITEA_API_USING_HOST_TYPES,
78
GITHUB_API_USING_HOST_TYPES,
89
GITLAB_API_USING_HOST_TYPES,
@@ -125,6 +126,21 @@ export function findMatchingRule<GotOptions extends HostRulesGotOptions>(
125126
};
126127
}
127128

129+
// Fallback to `forgejo` hostType
130+
if (
131+
hostType &&
132+
FORGEJO_API_USING_HOST_TYPES.includes(hostType) &&
133+
hostType !== 'forgejo'
134+
) {
135+
res = {
136+
...hostRules.find({
137+
hostType: 'forgejo',
138+
url,
139+
}),
140+
...res,
141+
};
142+
}
143+
128144
// Fallback to `gitea` hostType
129145
if (
130146
hostType &&

0 commit comments

Comments
 (0)