Skip to content

Commit d0c4f36

Browse files
committed
Fix ghe.com compatibility
1 parent 0842e0d commit d0c4f36

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

src/configuration/configuration.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,16 @@ export function useEnterprise(): boolean {
6868
return getConfiguration().get<boolean>(getSettingsKey("use-enterprise"), false);
6969
}
7070

71+
export function getGithubUri(): string {
72+
const apiUri = getGitHubApiUri();
73+
74+
if (apiUri === DEFAULT_GITHUB_API || apiUri.endsWith(".ghe.com")) {
75+
return apiUri.replace(/^(https?):\/\/api\./, "$1://");
76+
}
77+
78+
return apiUri.replace(/\/api\/v3$/, "");
79+
}
80+
7181
export function getGitHubApiUri(): string {
7282
if (!useEnterprise()) return DEFAULT_GITHUB_API;
7383
const base = getConfiguration().get<string>("github-enterprise.uri", DEFAULT_GITHUB_API).replace(/\/$/, "");
@@ -76,7 +86,7 @@ export function getGitHubApiUri(): string {
7686
}
7787

7888
if (base.endsWith(".ghe.com")) {
79-
return `api.${base}`;
89+
return base.replace(/^(https?):\/\//, "$1://api.");
8090
} else {
8191
return `${base}/api/v3`;
8292
}

src/git/repository.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@ import {Octokit} from "@octokit/rest";
44
import {canReachGitHubAPI} from "../api/canReachGitHubAPI";
55
import {handleSamlError} from "../api/handleSamlError";
66
import {getSession} from "../auth/auth";
7-
import {getRemoteName, useEnterprise} from "../configuration/configuration";
7+
import {getGithubUri, getRemoteName, useEnterprise} from "../configuration/configuration";
88
import {Protocol} from "../external/protocol";
99
import {logDebug, logError} from "../log";
1010
import {API, GitExtension, RefType, RepositoryState} from "../typings/git";
1111
import {RepositoryPermission, getRepositoryPermission} from "./repository-permissions";
12-
import {getGitHubApiUri} from "../configuration/configuration";
1312

1413
interface GitHubUrls {
1514
workspaceUri: vscode.Uri;
@@ -78,7 +77,7 @@ export async function getGitHubUrls(): Promise<GitHubUrls[] | null> {
7877
if (
7978
remote.length > 0 &&
8079
(remote[0].pushUrl?.indexOf("github.com") !== -1 ||
81-
(useEnterprise() && remote[0].pushUrl?.indexOf(new URL(getGitHubApiUri()).host) !== -1))
80+
(useEnterprise() && remote[0].pushUrl?.indexOf(new URL(getGithubUri()).host) !== -1))
8281
) {
8382
const url = remote[0].pushUrl;
8483

0 commit comments

Comments
 (0)