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

Update GitHub commit injection #29

Merged
merged 4 commits into from
Apr 16, 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
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@
],
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-redundant-type-constituents": "off",
"@typescript-eslint/no-shadow": "warn",
"@typescript-eslint/no-shadow": "error",
"@typescript-eslint/no-unnecessary-condition": "off",
"@typescript-eslint/no-unnecessary-boolean-literal-compare": "off",
"@typescript-eslint/no-unsafe-argument": "off",
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ on:
branches: [main, master]
jobs:
test:
timeout-minutes: 60
timeout-minutes: 5
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
node-version: 18
- name: Install dependencies
run: yarn
- name: Install Playwright Browsers
Expand Down
48 changes: 24 additions & 24 deletions src/hosts/azureDevops.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export function injectionScope(url: string) {
>();
try {
const label = 'Open with GitKraken';
const url = this.transformUrl('open', pathname, search);
const openUrl = this.transformUrl('open', pathname, search);

const [, , , , , type] = pathname.split('/');
switch (type) {
Expand All @@ -62,7 +62,7 @@ export function injectionScope(url: string) {
case 'pullrequest': {
const compareUrl = this.transformUrl('compare', pathname, search);
insertions.set('.repos-pr-title-row', {
html: /*html*/ `<a data-gk class="gk-insert-pr bolt-header-command-item-button bolt-button" href="${url}" style="text-decoration:none !important" target="_blank" title="${label}" role="menuitem" aria-label="${label}">${this.getGitKrakenSvg(
html: /*html*/ `<a data-gk class="gk-insert-pr bolt-header-command-item-button bolt-button" href="${openUrl}" style="text-decoration:none !important" target="_blank" title="${label}" role="menuitem" aria-label="${label}">${this.getGitKrakenSvg(
20,
undefined,
'position:relative; margin-right:4px;',
Expand All @@ -75,33 +75,33 @@ export function injectionScope(url: string) {
position: 'afterend',
replaceSelectorList: [
{ selector: '.gk-insert-compare', href: compareUrl },
{ selector: '.gk-insert-pr', href: url },
{ selector: '.gk-insert-pr', href: openUrl },
],
});
break;
}
case 'commit': {
insertions.set('.bolt-header-commandbar ', {
html: /*html*/ `<a data-gk class="gk-insert-commit bolt-header-command-item-button bolt-button" href="${url}" style="text-decoration:none !important" target="_blank" title="${label}" role="menuitem" aria-label="${label}">${this.getGitKrakenSvg(
html: /*html*/ `<a data-gk class="gk-insert-commit bolt-header-command-item-button bolt-button" href="${openUrl}" style="text-decoration:none !important" target="_blank" title="${label}" role="menuitem" aria-label="${label}">${this.getGitKrakenSvg(
20,
undefined,
'position:relative; margin-right:4px;',
)}Open with GitKraken</a>`,
position: 'afterbegin',
replaceSelectorList: [{ selector: '.gk-insert-commit', href: url }],
replaceSelectorList: [{ selector: '.gk-insert-commit', href: openUrl }],
});

break;
}
case undefined: {
insertions.set('.repos-files-header-commandbar ', {
html: /*html*/ `<a data-gk class="gk-insert bolt-header-command-item-button bolt-button" href="${url}" style="text-decoration:none !important" target="_blank" title="${label}" role="menuitem" aria-label="${label}">${this.getGitKrakenSvg(
html: /*html*/ `<a data-gk class="gk-insert bolt-header-command-item-button bolt-button" href="${openUrl}" style="text-decoration:none !important" target="_blank" title="${label}" role="menuitem" aria-label="${label}">${this.getGitKrakenSvg(
20,
undefined,
'position:relative; margin-right:4px;',
)}Open with GitKraken</a>`,
position: 'afterbegin',
replaceSelectorList: [{ selector: '.gk-insert', href: url }],
replaceSelectorList: [{ selector: '.gk-insert', href: openUrl }],
});

break;
Expand Down Expand Up @@ -200,21 +200,21 @@ export function injectionScope(url: string) {

const repoId = '-';

let url;
let redirectUrl: URL | null = null;
switch (type) {
case 'commit': {
url = new URL(`${target}://eamodio.gitlens/link/r/${repoId}/c/${urlTarget}`);
redirectUrl = new URL(`${target}://eamodio.gitlens/link/r/${repoId}/c/${urlTarget}`);
break;
}
case 'branchCompare': {
// no comparisons across forks
const comparisonTargetBranch = search.get('targetVersion')?.slice(2);
const comparisonBaseBranch = search.get('baseVersion')?.slice(2);
if (!comparisonTargetBranch || !comparisonBaseBranch) {
url = new URL(`${target}://eamodio.gitlens/link/r/${repoId}`);
redirectUrl = new URL(`${target}://eamodio.gitlens/link/r/${repoId}`);
break;
}
url = new URL(
redirectUrl = new URL(
`${target}://eamodio.gitlens/link/r/${repoId}/compare/${org}/${project}/${repo}:${comparisonBaseBranch}...${org}/${project}/${repo}:${comparisonTargetBranch}`,
);
break;
Expand All @@ -241,38 +241,38 @@ export function injectionScope(url: string) {
const baseBranchString = `${baseOrg}/${baseProject}/${baseRepo}:${baseBranch}`;
const prBranchString = `${prOrg}/${prProject}/${prRepo}:${prBranch}`;

url = new URL(
redirectUrl = new URL(
`${target}://eamodio.gitlens/link/r/${repoId}/compare/${baseBranchString}...${prBranchString}`,
);
}

if (url == null) {
url = new URL(`${target}://eamodio.gitlens/link/r/${repoId}/b/${prBranch}`);
if (redirectUrl === null) {
redirectUrl = new URL(`${target}://eamodio.gitlens/link/r/${repoId}/b/${prBranch}`);
}

url.searchParams.set('pr', prNumber);
url.searchParams.set('prUrl', this.uri.toString());
redirectUrl.searchParams.set('pr', prNumber);
redirectUrl.searchParams.set('prUrl', this.uri.toString());

if (prOrg !== org || prRepo !== repo) {
const prRepoUrl = `https://${prOrg}@dev.azure.com/${prOrg}/${prProject}/_git/${prRepo}`;
url.searchParams.set('prRepoUrl', prRepoUrl.toString());
redirectUrl.searchParams.set('prRepoUrl', prRepoUrl.toString());

org = prOrg;
repo = prRepo;
}
} else {
url = new URL(`${target}://eamodio.gitlens/link/r/${repoId}`);
url.searchParams.set('pr', prNumber);
url.searchParams.set('prUrl', this.uri.toString());
redirectUrl = new URL(`${target}://eamodio.gitlens/link/r/${repoId}`);
redirectUrl.searchParams.set('pr', prNumber);
redirectUrl.searchParams.set('prUrl', this.uri.toString());
}
break;
}
default: {
const branch = search.get('version')?.slice(2);
if (branch) {
url = new URL(`${target}://eamodio.gitlens/link/r/${repoId}/b/${branch}`);
redirectUrl = new URL(`${target}://eamodio.gitlens/link/r/${repoId}/b/${branch}`);
} else {
url = new URL(`${target}://eamodio.gitlens/link/r/${repoId}`);
redirectUrl = new URL(`${target}://eamodio.gitlens/link/r/${repoId}`);
}
break;
}
Expand All @@ -281,8 +281,8 @@ export function injectionScope(url: string) {
const remoteUrl = `https://${org}@dev.azure.com/${org}/${project}/_git/${repo}`;
console.log('remoteUrl', remoteUrl);

url.searchParams.set('url', remoteUrl.toString());
return url.toString();
redirectUrl.searchParams.set('url', remoteUrl.toString());
return redirectUrl.toString();
}

private parsePathname(pathname: string): {
Expand Down
60 changes: 30 additions & 30 deletions src/hosts/bitbucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export function injectionScope(url: string) {
>();
try {
const label = 'Open with GitKraken';
const url = this.transformUrl('open', pathname);
const openUrl = this.transformUrl('open', pathname);

const [, , , type] = pathname.split('/');
switch (type) {
Expand All @@ -65,7 +65,7 @@ export function injectionScope(url: string) {
case 'pull-requests': {
const compareUrl = this.transformUrl('compare', pathname);
insertions.set('.css-1oy5iav', {
html: /*html*/ `<a data-gk class="gk-insert-pr css-w97uih" href="${url}" target="_blank" title="${label}" role="menuitem" aria-label="${label}">${this.getGitKrakenSvg(
html: /*html*/ `<a data-gk class="gk-insert-pr css-w97uih" href="${openUrl}" target="_blank" title="${label}" role="menuitem" aria-label="${label}">${this.getGitKrakenSvg(
20,
undefined,
'position:relative; top:4px; left:-5px;',
Expand All @@ -77,15 +77,15 @@ export function injectionScope(url: string) {
)}Open Comparison with GitKraken</a>`,
position: 'afterbegin',
replaceSelectorList: [
{ selector: '.gk-insert-pr', href: url },
{ selector: '.gk-insert-pr', href: openUrl },
{ selector: '.gk-insert-comparison', href: compareUrl },
],
});
break;
}
case 'branches': {
insertions.set('.css-1bvc4cc', {
html: /*html*/ `<a data-gk class="css-w97uih" style="margin-right:4px !important;" href="${url}" target="_blank" title="${label}" role="menuitem" aria-label="${label}">${this.getGitKrakenSvg(
html: /*html*/ `<a data-gk class="css-w97uih" style="margin-right:4px !important;" href="${openUrl}" target="_blank" title="${label}" role="menuitem" aria-label="${label}">${this.getGitKrakenSvg(
20,
undefined,
'position:relative; top:4px; left:-5px;',
Expand All @@ -99,13 +99,13 @@ export function injectionScope(url: string) {
case 'src':
case undefined: {
insertions.set('.css-1oy5iav', {
html: /*html*/ `<a data-gk class="gk-insert css-w97uih" href="${url}" target="_blank" title="${label}" role="menuitem" aria-label="${label}">${this.getGitKrakenSvg(
html: /*html*/ `<a data-gk class="gk-insert css-w97uih" href="${openUrl}" target="_blank" title="${label}" role="menuitem" aria-label="${label}">${this.getGitKrakenSvg(
20,
undefined,
'position:relative; top:4px; left:-5px;',
)}Open with GitKraken</a>`,
position: 'afterbegin',
replaceSelectorList: [{ selector: '.gk-insert', href: url }],
replaceSelectorList: [{ selector: '.gk-insert', href: openUrl }],
});

break;
Expand Down Expand Up @@ -202,21 +202,21 @@ export function injectionScope(url: string) {

const repoId = '-';

let url;
let redirectUrl: URL | null = null;
switch (type) {
case 'commits': {
const urlTarget = rest.join('/');
if (!urlTarget) {
url = new URL(`${target}://eamodio.gitlens/link/r/${repoId}`);
redirectUrl = new URL(`${target}://eamodio.gitlens/link/r/${repoId}`);
break;
}
url = new URL(`${target}://eamodio.gitlens/link/r/${repoId}/c/${urlTarget}`);
redirectUrl = new URL(`${target}://eamodio.gitlens/link/r/${repoId}/c/${urlTarget}`);
break;
}
case 'compare': {
let comparisonTarget = rest.join('/');
if (!comparisonTarget) {
url = new URL(`${target}://eamodio.gitlens/link/r/${repoId}`);
redirectUrl = new URL(`${target}://eamodio.gitlens/link/r/${repoId}`);
break;
}
const sameOrigin = !comparisonTarget.includes(':');
Expand All @@ -225,7 +225,7 @@ export function injectionScope(url: string) {

comparisonTarget = branches.join('...');
}
url = new URL(
redirectUrl = new URL(
`${target}://eamodio.gitlens/link/r/${repoId}/compare/${comparisonTarget.replace(
/%0D/g,
'...',
Expand Down Expand Up @@ -273,68 +273,68 @@ export function injectionScope(url: string) {

if (prOwner === baseOwner && prRepo === baseRepo) {
const baseBranch = base;
const prBranch = pr;
prBranch = pr;
baseBranchString = `${baseOwner}/${baseRepo}:${baseBranch}`;
prBranchString = `${prOwner}/${prRepo}:${prBranch}`;
} else {
baseBranchString = base;
prBranchString = pr;
}
url = new URL(
redirectUrl = new URL(
`${target}://eamodio.gitlens/link/r/${repoId}/compare/${baseBranchString}...${prBranchString}`,
);
}

if (url == null) {
url = new URL(`${target}://eamodio.gitlens/link/r/${repoId}/b/${prBranch}`);
if (redirectUrl === null) {
redirectUrl = new URL(`${target}://eamodio.gitlens/link/r/${repoId}/b/${prBranch}`);
}

url.searchParams.set('pr', prNumber);
url.searchParams.set('prUrl', this.uri.toString());
redirectUrl.searchParams.set('pr', prNumber);
redirectUrl.searchParams.set('prUrl', this.uri.toString());

if (prOwner !== owner || prRepo !== repo) {
const prRepoUrl = new URL(this.uri.toString());
prRepoUrl.hash = '';
prRepoUrl.search = '';
prRepoUrl.pathname = `/${owner}/${repo}.git`;
url.searchParams.set('prRepoUrl', prRepoUrl.toString());
redirectUrl.searchParams.set('prRepoUrl', prRepoUrl.toString());

owner = prOwner;
repo = prRepo;
}
} else {
url = new URL(`${target}://eamodio.gitlens/link/r/${repoId}`);
url.searchParams.set('pr', prNumber);
url.searchParams.set('prUrl', this.uri.toString());
redirectUrl = new URL(`${target}://eamodio.gitlens/link/r/${repoId}`);
redirectUrl.searchParams.set('pr', prNumber);
redirectUrl.searchParams.set('prUrl', this.uri.toString());
}
console.log('transform', url.toString(), action);
console.log('transform', redirectUrl.toString(), action);
break;
}
case 'branches':
case 'branch': {
const urlTarget = rest.join('/');
if (!urlTarget) {
url = new URL(`${target}://eamodio.gitlens/link/r/${repoId}`);
redirectUrl = new URL(`${target}://eamodio.gitlens/link/r/${repoId}`);
break;
}
url = new URL(`${target}://eamodio.gitlens/link/r/${repoId}/b/${urlTarget}`);
redirectUrl = new URL(`${target}://eamodio.gitlens/link/r/${repoId}/b/${urlTarget}`);
break;
}
case 'src': {
// TODO@miggy-e this is a pretty naive check, please update if you find a better way
// this is currently broken when branches have 40 characters or if you use the short sha of a commit
if (rest.length === 1 && rest[0].length === 40) {
// commit sha's are 40 characters long
url = new URL(`${target}://eamodio.gitlens/link/r/${repoId}/c/${rest.join('/')}`);
redirectUrl = new URL(`${target}://eamodio.gitlens/link/r/${repoId}/c/${rest.join('/')}`);
} else if (!rest.length) {
url = new URL(`${target}://eamodio.gitlens/link/r/${repoId}`);
redirectUrl = new URL(`${target}://eamodio.gitlens/link/r/${repoId}`);
} else {
url = new URL(`${target}://eamodio.gitlens/link/r/${repoId}/b/${rest.join('/')}`);
redirectUrl = new URL(`${target}://eamodio.gitlens/link/r/${repoId}/b/${rest.join('/')}`);
}
break;
}
default:
url = new URL(`${target}://eamodio.gitlens/link/r/${repoId}`);
redirectUrl = new URL(`${target}://eamodio.gitlens/link/r/${repoId}`);
break;
}

Expand All @@ -343,8 +343,8 @@ export function injectionScope(url: string) {
remoteUrl.search = '';
remoteUrl.pathname = `/${owner}/${repo}.git`;

url.searchParams.set('url', remoteUrl.toString());
return url.toString();
redirectUrl.searchParams.set('url', remoteUrl.toString());
return redirectUrl.toString();
}

private getGitKrakenSvg(size: number, classes?: string, style?: string) {
Expand Down
Loading
Loading