Skip to content
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

fix(backend): allow a custom API root for backend #7214

Merged
merged 2 commits into from
Aug 2, 2024
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 packages/decap-cms-backend-gitlab/src/implementation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ export default class GitLab implements Implementation {
backend: 'gitlab',
repo: this.repo,
token: this.token,
apiRoot: this.apiRoot,
});
if (defaultBranchName) {
this.branch = defaultBranchName;
Expand Down
8 changes: 5 additions & 3 deletions packages/decap-cms-lib-util/src/API.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ type Backend = 'github' | 'gitlab' | 'bitbucket';
type RequestConfig = Omit<RequestInit, 'headers'> &
HeaderConfig & {
backend: Backend;
apiRoot?: string;
params?: ParamObject;
};

Expand Down Expand Up @@ -199,7 +200,7 @@ export async function apiRequest(
const { token, backend, ...props } = config;
const options = { cache: 'no-cache', ...props };
const headers = await constructRequestHeaders({ headers: options.headers || {}, token });
const baseUrl = apiRoots[backend];
const baseUrl = config.apiRoot ?? apiRoots[backend];
const url = constructUrlWithParams(`${baseUrl}${path}`, options.params);
let responseStatus = 500;
try {
Expand All @@ -220,9 +221,10 @@ export async function getDefaultBranchName(configs: {
backend: Backend;
repo: string;
token?: string;
apiRoot?: string;
}) {
let apiPath;
const { token, backend, repo } = configs;
const { token, backend, repo, apiRoot } = configs;
switch (backend) {
case 'gitlab': {
apiPath = `/projects/${encodeURIComponent(repo)}`;
Expand All @@ -236,7 +238,7 @@ export async function getDefaultBranchName(configs: {
apiPath = `/repos/${repo}`;
}
}
const repoInfo = await apiRequest(apiPath, { token, backend });
const repoInfo = await apiRequest(apiPath, { token, backend, apiRoot });
let defaultBranchName;
if (backend === 'bitbucket') {
const {
Expand Down
Loading