Skip to content

Commit

Permalink
Fix GKDotDevUrl in injected scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
jdgarcia committed Apr 26, 2024
1 parent 5257487 commit 155d2a9
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 15 deletions.
9 changes: 6 additions & 3 deletions src/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { injectionScope as inject_bitbucket } from './hosts/bitbucket';
import { injectionScope as inject_github } from './hosts/github';
import { injectionScope as inject_gitlab } from './hosts/gitlab';
import { refreshPermissions } from './permissions-helper';
import { getEnterpriseConnections, PermissionsGrantedMessage, PopupInitMessage } from './shared';
import { getEnterpriseConnections, GKDotDevUrl, PermissionsGrantedMessage, PopupInitMessage } from './shared';
import type { CacheContext } from './types';

interface InjectionDomains {
Expand Down Expand Up @@ -73,7 +73,7 @@ async function addInjectionListener(context: CacheContext) {
target: { tabId: details.tabId },
// injectImmediately: true,
func: getInjectionFn(details.url, injectionDomains),
args: [details.url],
args: [details.url, GKDotDevUrl],
});
};

Expand All @@ -86,7 +86,10 @@ function urlHostHasDomain(url: URL, domains: string[]): boolean {
return domains.some(domain => url.hostname.endsWith(domain));
}

function getInjectionFn(rawUrl: string, injectionDomains: InjectionDomains): (url: string) => void {
function getInjectionFn(
rawUrl: string,
injectionDomains: InjectionDomains,
): (url: string, gkDotDevUrl: string) => void {
const url = new URL(rawUrl);
if (urlHostHasDomain(url, injectionDomains.github)) {
return inject_github;
Expand Down
7 changes: 4 additions & 3 deletions src/hosts/azureDevops.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
// IMPORTANT: Non-type imports cannot be used, only anything contained within the injectionScope function will actually be injected into the page.

import type { InjectionProvider, LinkTarget } from '../provider';
import { GKDotDevUrl } from '../shared';

interface ReplaceSelector {
selector: string;
href: string;
}

export function injectionScope(url: string) {
export function injectionScope(url: string, gkDotDevUrl: string) {
class AzureDevopsInjectionProvider implements InjectionProvider {
private _timer: ReturnType<typeof setTimeout> | undefined;
private _observer: MutationObserver | undefined;
Expand Down Expand Up @@ -180,7 +181,7 @@ export function injectionScope(url: string) {

private transformUrl(action: 'open' | 'compare', pathname: string, search: URLSearchParams): string {
const redirectUrl = new URL(this.getRedirectUrl('vscode', action, pathname, search));
const deepLinkUrl = `${GKDotDevUrl}/link`;
const deepLinkUrl = `${gkDotDevUrl}/link`;
const deepLink = new URL(`${deepLinkUrl}/${encodeURIComponent(btoa(redirectUrl.toString()))}`);
deepLink.searchParams.set('referrer', 'extension');
if (redirectUrl.searchParams.get('pr')) {
Expand Down
7 changes: 4 additions & 3 deletions src/hosts/bitbucket.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
// IMPORTANT: Non-type imports cannot be used, only anything contained within the injectionScope function will actually be injected into the page.

import type { InjectionProvider, LinkTarget } from '../provider';
import { GKDotDevUrl } from '../shared';

interface ReplaceSelector {
selector: string;
href: string;
}

export function injectionScope(url: string) {
export function injectionScope(url: string, gkDotDevUrl: string) {
class BitBucketInjectionProvider implements InjectionProvider {
private _timer: ReturnType<typeof setTimeout> | undefined;
private _observer: MutationObserver | undefined;
Expand Down Expand Up @@ -184,7 +185,7 @@ export function injectionScope(url: string) {

private transformUrl(action: 'open' | 'compare', pathname: string): string {
const redirectUrl = new URL(this.getRedirectUrl('vscode', action, pathname));
const deepLinkUrl = `${GKDotDevUrl}/link`;
const deepLinkUrl = `${gkDotDevUrl}/link`;
const deepLink = new URL(`${deepLinkUrl}/${encodeURIComponent(btoa(redirectUrl.toString()))}`);
deepLink.searchParams.set('referrer', 'extension');
if (redirectUrl.searchParams.get('pr')) {
Expand Down
8 changes: 5 additions & 3 deletions src/hosts/github.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// IMPORTANT: Non-type imports cannot be used, only anything contained within the injectionScope function will actually be injected into the page.

import type { InjectionProvider, LinkTarget } from '../provider';
import { GKDotDevUrl } from '../shared';

export function injectionScope(url: string) {
export function injectionScope(url: string, gkDotDevUrl: string) {
class GitHubInjectionProvider implements InjectionProvider {
private _timer: ReturnType<typeof setTimeout> | undefined;
private _observer: MutationObserver | undefined;
Expand Down Expand Up @@ -252,7 +253,8 @@ export function injectionScope(url: string) {
private transformUrl(action: 'open' | 'compare'): string {
const redirectUrl = new URL(this.getRedirectUrl('vscode', action));
console.debug('redirectUrl', redirectUrl);
const deepLinkUrl = `${GKDotDevUrl}/link`;
console.log('GKDotDevUrl', gkDotDevUrl);
const deepLinkUrl = `${gkDotDevUrl}/link`;
const deepLink = new URL(`${deepLinkUrl}/${encodeURIComponent(btoa(redirectUrl.toString()))}`);
deepLink.searchParams.set('referrer', 'extension');
if (redirectUrl.searchParams.get('pr')) {
Expand Down
7 changes: 4 additions & 3 deletions src/hosts/gitlab.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// IMPORTANT: Non-type imports cannot be used, only anything contained within the injectionScope function will actually be injected into the page.

import type { InjectionProvider, LinkTarget } from '../provider';
import { GKDotDevUrl } from '../shared';

export function injectionScope(url: string) {
export function injectionScope(url: string, gkDotDevUrl: string) {
class GitLabInjectionProvider implements InjectionProvider {
private _timer: ReturnType<typeof setTimeout> | undefined;
private _observer: MutationObserver | undefined;
Expand Down Expand Up @@ -252,7 +253,7 @@ export function injectionScope(url: string) {
private transformUrl(action: 'open' | 'compare'): string {
const redirectUrl = new URL(this.getRedirectUrl('vscode', action));
console.debug('redirectUrl', redirectUrl);
const deepLinkUrl = `${GKDotDevUrl}/link`;
const deepLinkUrl = `${gkDotDevUrl}/link`;
const deepLink = new URL(`${deepLinkUrl}/${encodeURIComponent(btoa(redirectUrl.toString()))}`);
deepLink.searchParams.set('referrer', 'extension');
if (redirectUrl.searchParams.get('pr')) {
Expand Down

0 comments on commit 155d2a9

Please sign in to comment.