mirror of
https://github.com/EnixCoda/Gitako.git
synced 2026-03-11 08:54:44 +00:00
Merge branch 'feature/enterprise' into develop
This commit is contained in:
commit
2a79861408
12 changed files with 107 additions and 7 deletions
1
.github/workflows/release-assets.yml
vendored
1
.github/workflows/release-assets.yml
vendored
|
|
@ -4,6 +4,7 @@ on:
|
|||
push:
|
||||
tags:
|
||||
- v[0-9]+.* # roughly matching version numbers
|
||||
- release-*
|
||||
|
||||
jobs:
|
||||
release:
|
||||
|
|
|
|||
|
|
@ -39,6 +39,8 @@
|
|||
"react-use": "^13.8.0",
|
||||
"react-window": "^1.8.5",
|
||||
"styled-components": "^5.0.1",
|
||||
"webext-domain-permission-toggle": "^1.0.0",
|
||||
"webext-dynamic-content-scripts": "^6.0.3",
|
||||
"webextension-polyfill": "^0.5.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
|
|
|||
7
src/background.ts
Normal file
7
src/background.ts
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
import addDomainPermissionToggle from 'webext-domain-permission-toggle'
|
||||
import 'webext-dynamic-content-scripts'
|
||||
|
||||
addDomainPermissionToggle({
|
||||
title: 'Enable Gitako on this domain',
|
||||
reloadOnSuccess: 'Refresh to activate Gitako?',
|
||||
})
|
||||
|
|
@ -6,8 +6,22 @@
|
|||
"128": "icons/Gitako-128.png",
|
||||
"256": "icons/Gitako-256.png"
|
||||
},
|
||||
"permissions": ["storage", "*://*.github.com/*", "*://*.sentry.io/*"],
|
||||
"permissions": [
|
||||
"storage",
|
||||
"contextMenus",
|
||||
"activeTab",
|
||||
"*://*.github.com/*",
|
||||
"*://gitako.now.sh/*",
|
||||
"*://*.sentry.io/*"
|
||||
],
|
||||
"optional_permissions": ["http://*/*", "https://*/*"],
|
||||
"web_accessible_resources": ["icons/vscode/*", "content.css"],
|
||||
"background": {
|
||||
"scripts": ["background.js"]
|
||||
},
|
||||
"browser_action": {
|
||||
"default_icon": "icons/Gitako.png"
|
||||
},
|
||||
"content_scripts": [
|
||||
{
|
||||
"matches": ["https://github.com/*"],
|
||||
|
|
|
|||
|
|
@ -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'
|
||||
|
|
@ -58,12 +59,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 })
|
||||
}
|
||||
|
||||
|
|
@ -73,7 +76,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 })
|
||||
}
|
||||
|
||||
|
|
@ -83,7 +86,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) {
|
||||
|
|
|
|||
|
|
@ -61,8 +61,9 @@ plugins.push(
|
|||
module.exports = {
|
||||
entry: {
|
||||
content: './src/content.tsx',
|
||||
background: './src/background.ts',
|
||||
},
|
||||
devtool: IN_PRODUCTION_MODE ? 'source-map' : 'eval-source-map',
|
||||
devtool: IN_PRODUCTION_MODE ? 'source-map' : 'inline-source-map',
|
||||
mode: IN_PRODUCTION_MODE ? 'production' : 'development',
|
||||
output: {
|
||||
path: path.resolve(__dirname, 'dist'),
|
||||
|
|
|
|||
60
yarn.lock
60
yarn.lock
|
|
@ -1265,11 +1265,35 @@
|
|||
"@testing-library/dom" "^6.11.0"
|
||||
"@types/testing-library__react" "^9.1.2"
|
||||
|
||||
"@types/chrome@0.0.86":
|
||||
version "0.0.86"
|
||||
resolved "https://registry.yarnpkg.com/@types/chrome/-/chrome-0.0.86.tgz#1026ef8e76db4fde1859cae858d73236fe670d69"
|
||||
integrity sha512-7ehebPf/5IR64SYdD2Vig0q0oUCNbWMQ29kASlNJaHVVtA5/J/DnrxnYVPCID70o7LgHdYsav6I4/XdqAxjTLQ==
|
||||
dependencies:
|
||||
"@types/filesystem" "*"
|
||||
|
||||
"@types/color-name@^1.1.1":
|
||||
version "1.1.1"
|
||||
resolved "https://registry.yarnpkg.com/@types/color-name/-/color-name-1.1.1.tgz#1c1261bbeaa10a8055bbc5d8ab84b7b2afc846a0"
|
||||
integrity sha512-rr+OQyAjxze7GgWrSaJwydHStIhHq2lvY3BOC2Mj7KnzI7XK0Uw1TOOdI9lDoajEbSWLiYgoo4f1R51erQfhPQ==
|
||||
|
||||
"@types/filesystem@*":
|
||||
version "0.0.29"
|
||||
resolved "https://registry.yarnpkg.com/@types/filesystem/-/filesystem-0.0.29.tgz#ee3748eb5be140dcf980c3bd35f11aec5f7a3748"
|
||||
integrity sha512-85/1KfRedmfPGsbK8YzeaQUyV1FQAvMPMTuWFQ5EkLd2w7szhNO96bk3Rh/SKmOfd9co2rCLf0Voy4o7ECBOvw==
|
||||
dependencies:
|
||||
"@types/filewriter" "*"
|
||||
|
||||
"@types/filewriter@*":
|
||||
version "0.0.28"
|
||||
resolved "https://registry.yarnpkg.com/@types/filewriter/-/filewriter-0.0.28.tgz#c054e8af4d9dd75db4e63abc76f885168714d4b3"
|
||||
integrity sha1-wFTor02d11205jq8dviFFocU1LM=
|
||||
|
||||
"@types/firefox-webext-browser@^67.0.2":
|
||||
version "67.0.2"
|
||||
resolved "https://registry.yarnpkg.com/@types/firefox-webext-browser/-/firefox-webext-browser-67.0.2.tgz#04625d3294fbca54bccf42dae43f636c5b6452a2"
|
||||
integrity sha512-tXR5THtH5Fqwfmi4y/2dTxCTebqHsKCH2bif/VdE5CPcB/S5x5fu+N+wBuMENzN41agovHMU/LQbtWNV+Aux+w==
|
||||
|
||||
"@types/firefox-webext-browser@^70.0.1":
|
||||
version "70.0.1"
|
||||
resolved "https://registry.yarnpkg.com/@types/firefox-webext-browser/-/firefox-webext-browser-70.0.1.tgz#53a3915bfbe25e2c5ec439dbdbe6e303610012bb"
|
||||
|
|
@ -2939,6 +2963,13 @@ content-disposition@0.5.3:
|
|||
dependencies:
|
||||
safe-buffer "5.1.2"
|
||||
|
||||
content-scripts-register-polyfill@^1.0.0:
|
||||
version "1.0.0"
|
||||
resolved "https://registry.yarnpkg.com/content-scripts-register-polyfill/-/content-scripts-register-polyfill-1.0.0.tgz#21bc2df475ea48aa83737d24675a6a44e4a006a7"
|
||||
integrity sha512-DiHscMTyL5evEg6C8GSkkd5Kfkma726zxqIt+zv6L2W/gVqYOUZUw2F27BpAUp9nQZnIrky5Gx1eYA9Fw4+aeA==
|
||||
dependencies:
|
||||
"@types/firefox-webext-browser" "^67.0.2"
|
||||
|
||||
content-type@~1.0.4:
|
||||
version "1.0.4"
|
||||
resolved "https://registry.yarnpkg.com/content-type/-/content-type-1.0.4.tgz#e138cc75e040c727b1966fe5e5f8c9aee256fe3b"
|
||||
|
|
@ -9159,6 +9190,35 @@ web-ext@^3.2.0:
|
|||
yargs "13.3.0"
|
||||
zip-dir "1.0.2"
|
||||
|
||||
webext-additional-permissions@^0.1.0:
|
||||
version "0.1.0"
|
||||
resolved "https://registry.yarnpkg.com/webext-additional-permissions/-/webext-additional-permissions-0.1.0.tgz#bc5a2a6cb8e60098c81a6004c446bfae2aefd85a"
|
||||
integrity sha512-eA1o6BdRbpU5ClL6GcmwhGtVVzNTbQSqX9esakpurWYVt9ykpGQ1ZNe5l30Yt19GW0eRC8VdroOeJSumP5cMpQ==
|
||||
dependencies:
|
||||
"@types/chrome" "0.0.86"
|
||||
|
||||
webext-domain-permission-toggle@^1.0.0:
|
||||
version "1.0.0"
|
||||
resolved "https://registry.yarnpkg.com/webext-domain-permission-toggle/-/webext-domain-permission-toggle-1.0.0.tgz#6f9a6d3234ffe596921d1be5ae8823ef5b02ebd2"
|
||||
integrity sha512-K6RAOYtVCMAmqjQPopMbGOIoxpFU05ERGgaLkUNvFCdpPsXLB5y4m1+Cq1dezyfx6FU0lLEqxoL/5/49+EY5zA==
|
||||
dependencies:
|
||||
webext-additional-permissions "^0.1.0"
|
||||
|
||||
webext-dynamic-content-scripts@^6.0.3:
|
||||
version "6.0.3"
|
||||
resolved "https://registry.yarnpkg.com/webext-dynamic-content-scripts/-/webext-dynamic-content-scripts-6.0.3.tgz#729a5cf4408dca589af889cb403943ab414c2ecd"
|
||||
integrity sha512-MIH4UOnkUl4hapl83uMQT5t2bbYXTPO/mxhFFBcesm2mGvnG3OrNKNiaPRFL6AdcPvqDVae8UcWcWHSflptLTQ==
|
||||
dependencies:
|
||||
"@types/chrome" "0.0.86"
|
||||
content-scripts-register-polyfill "^1.0.0"
|
||||
webext-additional-permissions "^0.1.0"
|
||||
webext-permissions-events-polyfill "^1.0.1"
|
||||
|
||||
webext-permissions-events-polyfill@^1.0.1:
|
||||
version "1.0.1"
|
||||
resolved "https://registry.yarnpkg.com/webext-permissions-events-polyfill/-/webext-permissions-events-polyfill-1.0.1.tgz#c5108d140b03efbd06b34c7211694b8cde928177"
|
||||
integrity sha512-dPsU7KtDn+OG+mPy0LLc9UhMXdVeQ8ywD5kK1GFtvceur4IWOnpI5D4uTjMPrKm8+re/8cbHKwVjnviIA9wZ3Q==
|
||||
|
||||
webextension-polyfill@^0.5.0:
|
||||
version "0.5.0"
|
||||
resolved "https://registry.yarnpkg.com/webextension-polyfill/-/webextension-polyfill-0.5.0.tgz#795e0bf6a2b8eadcdb6edaecd169e9228c747519"
|
||||
|
|
|
|||
Loading…
Reference in a new issue