mirror of
https://github.com/EnixCoda/Gitako.git
synced 2026-03-11 08:54:44 +00:00
feat: update API endpoint for enterprise
This commit is contained in:
parent
6f83adf934
commit
749af84cbb
6 changed files with 20 additions and 5 deletions
|
|
@ -1,4 +1,5 @@
|
|||
import { errors } from 'platforms'
|
||||
import { isEnterprise } from '.'
|
||||
|
||||
function apiRateLimitExceeded(content: any /* safe any */) {
|
||||
return content?.['documentation_url'] === 'https://developer.github.com/v3/#rate-limiting'
|
||||
|
|
@ -55,12 +56,14 @@ async function request(
|
|||
}
|
||||
}
|
||||
|
||||
const API_ENDPOINT = isEnterprise() ? `${window.location.host}/api/v3` : 'api.github.com'
|
||||
|
||||
export async function getRepoMeta(
|
||||
userName: string,
|
||||
repoName: string,
|
||||
accessToken?: string,
|
||||
): Promise<GitHubAPI.MetaData> {
|
||||
const url = `https://api.github.com/repos/${userName}/${repoName}`
|
||||
const url = `https://${API_ENDPOINT}/repos/${userName}/${repoName}`
|
||||
return await request(url, { accessToken })
|
||||
}
|
||||
|
||||
|
|
@ -70,7 +73,7 @@ export async function getTreeData(
|
|||
branchName: string,
|
||||
accessToken?: string,
|
||||
): Promise<GitHubAPI.TreeData> {
|
||||
const url = `https://api.github.com/repos/${userName}/${repoName}/git/trees/${branchName}?recursive=1`
|
||||
const url = `https://${API_ENDPOINT}/repos/${userName}/${repoName}/git/trees/${branchName}?recursive=1`
|
||||
return await request(url, { accessToken })
|
||||
}
|
||||
|
||||
|
|
@ -80,7 +83,7 @@ export async function getBlobData(
|
|||
sha: string,
|
||||
accessToken?: string,
|
||||
): Promise<GitHubAPI.BlobData> {
|
||||
const url = `https://api.github.com/repos/${userName}/${repoName}/git/blobs/${sha}`
|
||||
const url = `https://${API_ENDPOINT}/repos/${userName}/${repoName}/git/blobs/${sha}`
|
||||
return await request(url, { accessToken })
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -76,10 +76,15 @@ function getUrlForRedirect(
|
|||
type = 'blob',
|
||||
path = '',
|
||||
) {
|
||||
return `https://github.com/${userName}/${repoName}/${type}/${branchName}/${path}`
|
||||
return `https://${window.location.host}/${userName}/${repoName}/${type}/${branchName}/${path}`
|
||||
}
|
||||
|
||||
export function isEnterprise() {
|
||||
return !window.location.host.endsWith('github.com')
|
||||
}
|
||||
|
||||
export const GitHub: Platform = {
|
||||
isEnterprise,
|
||||
resolveMeta() {
|
||||
if (!URLHelper.isInRepoPage()) {
|
||||
return null
|
||||
|
|
|
|||
|
|
@ -78,6 +78,9 @@ function getUrlForRedirect(
|
|||
}
|
||||
|
||||
export const Gitee: Platform = {
|
||||
isEnterprise() {
|
||||
return !window.location.host.endsWith('gitee.com')
|
||||
},
|
||||
resolveMeta() {
|
||||
if (!DOMHelper.isInRepoPage()) {
|
||||
return null
|
||||
|
|
|
|||
|
|
@ -1,4 +1,7 @@
|
|||
export const dummyPlatformForTypeSafety: Platform = {
|
||||
isEnterprise() {
|
||||
return false
|
||||
},
|
||||
resolveMeta() {
|
||||
return null
|
||||
},
|
||||
|
|
|
|||
1
src/platforms/platform.d.ts
vendored
1
src/platforms/platform.d.ts
vendored
|
|
@ -1,4 +1,5 @@
|
|||
type Platform = {
|
||||
isEnterprise(): boolean
|
||||
resolveMeta(): MetaData | null
|
||||
getMetaData(
|
||||
metaData: Pick<MetaData, 'userName' | 'repoName'>,
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ function transformModuleGitURL(node: TreeNode, URL: string) {
|
|||
const matched = URL.match(subModuleURLRegex.git)
|
||||
if (!matched) return
|
||||
const [_, userName, repoName] = matched
|
||||
return appendCommitPath(`https://github.com/${userName}/${repoName}`, node)
|
||||
return appendCommitPath(`https://${window.location.host}/${userName}/${repoName}`, node)
|
||||
}
|
||||
|
||||
function cutDotGit(URL: string) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue