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

refactor github1s for supporting other scm #398

Merged
merged 77 commits into from
May 13, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
5bc1959
chore: add type definations
conwnet Aug 3, 2021
a567c1c
chore: add type definations
conwnet Aug 5, 2021
c86ed9f
chore: add type definations
conwnet Aug 12, 2021
1c9ba01
chore: add type definations
conwnet Aug 18, 2021
222b47e
chore: add type definations
conwnet Aug 19, 2021
5b1e816
chore: add github1s adapter
conwnet Aug 19, 2021
ebade2a
chore: implements adapter
conwnet Aug 19, 2021
eb3b1f3
chore: add github1s adapter
conwnet Aug 20, 2021
e64285e
refactor: refact file system provider
conwnet Sep 15, 2021
b78273b
refactor: refact fileSystemProvider
conwnet Sep 15, 2021
27f9e88
refactor: fill github datasource
conwnet Sep 16, 2021
154b610
refactor: fill github datasource
conwnet Sep 16, 2021
9f13c69
refactor: fill github datasource
conwnet Sep 16, 2021
0dd7b70
refactor: fill github datasource
conwnet Sep 17, 2021
02becb4
refactor: text search provider
conwnet Sep 20, 2021
b125c14
refactor: definitions and references
conwnet Sep 21, 2021
68394b5
refactor: move settings code to adapters
conwnet Jan 9, 2022
fd8bc33
feat: add github1s adapter
conwnet Apr 3, 2022
766a2a9
refactor: refactor pull list view
conwnet Apr 5, 2022
8259d05
refactor: refactor commit list view
conwnet Apr 10, 2022
6ad833d
refactor: changed file provider
conwnet Apr 10, 2022
284ea34
refactor: definination provider and reference provider
conwnet Apr 10, 2022
1313cde
refactor: hover provider
conwnet Apr 10, 2022
bdd2c97
refactor: text search provider and file search provider
conwnet Apr 10, 2022
490e2b7
refactor: update provider files
conwnet Apr 10, 2022
bdc6abf
refactor: extension listeners
conwnet Apr 10, 2022
7bb0f23
refactor: editor and ref commands
conwnet Apr 12, 2022
2c13555
refactor: rename constants
conwnet Apr 12, 2022
8521c1a
refactor: use singleton repository
conwnet Apr 12, 2022
03d3906
refactor: blame commands
conwnet Apr 12, 2022
c7e8c1f
refactor: global commands
conwnet Apr 12, 2022
4772f8e
refactor: optimize file system provider
conwnet Apr 12, 2022
6d1e456
reafactor: clean entry files
conwnet Apr 12, 2022
9deb44f
reafactor: fix ts errors
conwnet Apr 12, 2022
c19ab38
reafactor: fix read submodule file
conwnet Apr 12, 2022
f93b740
rafactor: optimize director structure & fix chnaged files decoration
conwnet Apr 15, 2022
23b4ff1
feat: upgrade vscode to 1.66.2
conwnet Apr 15, 2022
04c85eb
feat: update initialize rule
conwnet Apr 15, 2022
9277beb
feat: update vscode deps and add workspace identifier
conwnet Apr 16, 2022
095147a
feat: update proload css
conwnet Apr 16, 2022
5326b90
feat: add auth command
conwnet Apr 16, 2022
581a625
feat: github oauth token
conwnet Apr 16, 2022
a0c8b52
feat: remove unused files
conwnet Apr 16, 2022
7ce0ad4
feat: update adapter context
conwnet Apr 16, 2022
7badb9f
feat: preload file structures
conwnet Apr 16, 2022
134964f
fix: css preload typo
conwnet Apr 16, 2022
553be7c
fix: connect to github and set token
conwnet Apr 16, 2022
dcae51a
refactor: remove vscode loader.js modification
conwnet Apr 17, 2022
24e7875
fix: invalid token status & localize webview libraries
conwnet Apr 17, 2022
11d3a19
feat: update dependencies & fix commit diff
conwnet Apr 17, 2022
6ab1b34
fix: token changed create wrong octokit
conwnet Apr 17, 2022
ffb4494
fix: data source types
conwnet Apr 17, 2022
de2d170
feat: add notifications & platform logos
conwnet Apr 18, 2022
2121878
feat: use sourcegraph api
conwnet Apr 18, 2022
e55257a
feat: update github1s fetcher retry rule
conwnet Apr 18, 2022
a4b2b5b
feat: remove prebuilt vscode-anycode
conwnet Apr 19, 2022
f2eced8
feat: remove prebuilt vscode-anycode
conwnet Apr 19, 2022
98c7689
feat: add sourcegraph api
conwnet May 5, 2022
44ea77d
feat: change settings page
conwnet May 5, 2022
90387d6
feat: auto switch github api
conwnet May 7, 2022
929197d
chore: update datasource & fix user avatar url
conwnet May 7, 2022
6c984fa
feat: fix vercel build script
conwnet May 7, 2022
3f1019f
fix: commit list refresh lost data
conwnet May 8, 2022
a1b1f0d
feat: commit list paginations
conwnet May 8, 2022
bf6d490
fix: commit manager load data
conwnet May 8, 2022
29a21c3
feat: increase text search count
conwnet May 8, 2022
3a4a958
feat: add list file recursively limit
conwnet May 8, 2022
e339a26
feat: add gitlab support
conwnet May 8, 2022
28cc68a
feat: add bitbucket support
conwnet May 8, 2022
cb3825b
fix: parse router path
conwnet May 9, 2022
990b1d6
default: use default branch for router parser in gitlab1s
conwnet May 9, 2022
1ab9b4a
feat: update default page title
conwnet May 9, 2022
9c0695f
feat: update logo link path
conwnet May 9, 2022
eb7952e
test: update test cases
conwnet May 9, 2022
b99380c
chore: update logo icon
conwnet May 9, 2022
9ad5d6f
ci: fix ci error
conwnet May 9, 2022
b9c7d5c
feat: update use sourcegraph api strategy
conwnet May 10, 2022
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
Prev Previous commit
Next Next commit
feat: add gitlab support
  • Loading branch information
conwnet committed May 9, 2022
commit e339a26e179c10305bc3528dc9b8b053a3f2bd53
14 changes: 8 additions & 6 deletions extensions/github1s/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
"lib": "lib"
},
"activationEvents": [
"onFileSystem:github1s"
"onFileSystem:github1s",
"onFileSystem:gitlab1s",
"onFileSystem:bitbucket1s"
],
"browser": "./dist/extension",
"engines": {
Expand Down Expand Up @@ -214,7 +216,7 @@
"command": "github1s.commands.toggleEditorGutterBlame",
"title": "Toggle File Blame",
"category": "GitHub1s",
"enablement": "!isInDiffEditor && resourceScheme =~ /^github1s$/"
"enablement": "!isInDiffEditor"
},
{
"command": "github1s.commands.openEditorGutterBlame",
Expand All @@ -224,7 +226,7 @@
"dark": "assets/icons/dark/open-blame.svg",
"light": "assets/icons/light/open-blame.svg"
},
"enablement": "!isInDiffEditor && resourceScheme =~ /^github1s$/"
"enablement": "!isInDiffEditor"
},
{
"command": "github1s.commands.closeEditorGutterBlame",
Expand All @@ -234,7 +236,7 @@
"dark": "assets/icons/dark/close-blame.svg",
"light": "assets/icons/light/close-blame.svg"
},
"enablement": "!isInDiffEditor && resourceScheme =~ /^github1s$/"
"enablement": "!isInDiffEditor"
},
{
"command": "github1s.commands.openOnGitHub",
Expand Down Expand Up @@ -526,12 +528,12 @@
},
{
"command": "github1s.commands.openEditorGutterBlame",
"when": "!isInDiffEditor && resourceScheme =~ /^github1s$/ && !github1s:blames:gutterBlameOpen",
"when": "!isInDiffEditor && !github1s:blames:gutterBlameOpen",
"group": "navigation@4"
},
{
"command": "github1s.commands.closeEditorGutterBlame",
"when": "!isInDiffEditor && resourceScheme =~ /^github1s$/ && github1s:blames:gutterBlameOpen",
"when": "!isInDiffEditor && github1s:blames:gutterBlameOpen",
"group": "navigation@4"
}
]
Expand Down
2 changes: 1 addition & 1 deletion extensions/github1s/src/adapters/github1s/data-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export class GitHub1sDataSource extends DataSource {
);

@trySourcegraphApiFirst
async extractGitHubRef(repoFullName: string, refAndPath: string): Promise<{ ref: string; path: string }> {
async extractRefPath(repoFullName: string, refAndPath: string): Promise<{ ref: string; path: string }> {
const fetcher = GitHubFetcher.getInstance();
const { owner, repo } = parseRepoFullName(repoFullName);
const requestParams = { owner, repo, refAndPath };
Expand Down
3 changes: 2 additions & 1 deletion extensions/github1s/src/adapters/github1s/parser/commit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import { RouterState, PageType } from '../../types';

export const parseCommitUrl = async (path: string): Promise<RouterState> => {
const pathParts = parsePath(path).pathname!.split('/').filter(Boolean);
const [owner, repo, _pageType, commitSha] = pathParts;
const [owner, repo, _pageType, ...refParts] = pathParts;
const commitSha = refParts.join('/');

return { repo: `${owner}/${repo}`, pageType: PageType.Commit, ref: commitSha, commitSha };
};
21 changes: 9 additions & 12 deletions extensions/github1s/src/adapters/github1s/parser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,19 @@ import { parsePullUrl } from './pull';
import { parseCommitsUrl } from './commits';
import { parseCommitUrl } from './commit';

// detect concrete PageType the *third part* in url.path
const detectPageTypeFromPathParts = (pathParts: string[]): PageType => {
const PAGE_TYPE_MAP = {
tree: PageType.Tree,
blob: PageType.Blob,
pulls: PageType.CodeReviewList,
pull: PageType.CodeReview,
commit: PageType.Commit,
commits: PageType.CommitList,
};
return pathParts[2] ? PAGE_TYPE_MAP[pathParts[2]] : PageType.Unknown;
const PAGE_TYPE_MAP = {
tree: PageType.Tree,
blob: PageType.Blob,
pulls: PageType.CodeReviewList,
pull: PageType.CodeReview,
commit: PageType.Commit,
commits: PageType.CommitList,
};

export const parseGitHubPath = async (path: string): Promise<RouterState> => {
const pathParts = parsePath(path).pathname?.split('/').filter(Boolean) || [];
const pageType = detectPageTypeFromPathParts(pathParts);
// detect concrete PageType the *third part* in url.path
const pageType = pathParts[2] ? PAGE_TYPE_MAP[pathParts[2]] || PageType.Unknown : PageType.Tree;

if (pathParts.length >= 2) {
switch (pageType) {
Expand Down
6 changes: 3 additions & 3 deletions extensions/github1s/src/adapters/github1s/parser/tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { parsePath } from 'history';
import { GitHub1sDataSource } from '../data-source';
import { PageType, RouterState } from '../../types';

export const extractGitHubRef = async (
export const extractRefPath = async (
repoFullName: string,
refAndFilePath: string
): Promise<{ ref: string; path: string }> => {
Expand All @@ -18,14 +18,14 @@ export const extractGitHubRef = async (
return { ref: 'HEAD', path: refAndFilePath.slice(5) };
}

return GitHub1sDataSource.getInstance().extractGitHubRef(repoFullName, refAndFilePath);
return GitHub1sDataSource.getInstance().extractRefPath(repoFullName, refAndFilePath);
};

export const parseTreeUrl = async (path: string): Promise<RouterState> => {
const pathParts = parsePath(path).pathname!.split('/').filter(Boolean);
const [owner, repo, _pageType, ...restParts] = pathParts;
const repoFullName = `${owner}/${repo}`;
const { ref, path: filePath } = await extractGitHubRef(repoFullName, restParts.join('/'));
const { ref, path: filePath } = await extractRefPath(repoFullName, restParts.join('/'));

return { pageType: PageType.Tree, repo: repoFullName, ref, filePath };
};
8 changes: 4 additions & 4 deletions extensions/github1s/src/adapters/github1s/router-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
* @author netcon
*/

import * as github1s from '../types';
import * as adapterTypes from '../types';
import { parseGitHubPath } from './parser';

export class GitHub1sRouterParser extends github1s.RouterParser {
export class GitHub1sRouterParser extends adapterTypes.RouterParser {
private static instance: GitHub1sRouterParser | null = null;

public static getInstance(): GitHub1sRouterParser {
Expand All @@ -16,7 +16,7 @@ export class GitHub1sRouterParser extends github1s.RouterParser {
return (GitHub1sRouterParser.instance = new GitHub1sRouterParser());
}

parsePath(path: string): Promise<github1s.RouterState> {
parsePath(path: string): Promise<adapterTypes.RouterState> {
return parseGitHubPath(path);
}

Expand All @@ -41,7 +41,7 @@ export class GitHub1sRouterParser extends github1s.RouterParser {
return `/${repo}/pulls`;
}

buildCodeReviewPath(repo: string, codeReviewId: string): github1s.Promisable<string> {
buildCodeReviewPath(repo: string, codeReviewId: string): adapterTypes.Promisable<string> {
return `/${repo}/pull/${codeReviewId}`;
}

Expand Down
31 changes: 31 additions & 0 deletions extensions/github1s/src/adapters/gitlab1s/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* @file GitLab1s adapter
* @author netcon
*/

import { GitLab1sRouterParser } from './router-parser';
import { SourcegraphDataSource } from '../sourcegraph/data-source';
import { Adapter, CodeReviewType, PlatformName } from '../types';
import { setVSCodeContext } from '@/helpers/vscode';

export class GitLab1sAdapter implements Adapter {
public scheme: string = 'gitlab1s';
public platformName = PlatformName.GitLab;
public codeReviewType = CodeReviewType.MergeRequest;

resolveDataSource() {
return Promise.resolve(SourcegraphDataSource.getInstance('gitlab'));
}

resolveRouterParser() {
return Promise.resolve(GitLab1sRouterParser.getInstance());
}

activateAsDefault() {
setVSCodeContext('github1s:views:commitList:visible', true);
}

deactivateAsDefault() {
setVSCodeContext('github1s:views:commitList:visible', false);
}
}
29 changes: 29 additions & 0 deletions extensions/github1s/src/adapters/gitlab1s/parser/blob.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* @file GitLab Blob Url Parser
* @author netcon
*/

import { parsePath } from 'history';
import { PageType, RouterState } from '../../types';
import { parseTreeUrl } from './tree';

export const parseBlobUrl = async (path: string): Promise<RouterState> => {
const routerState = (await parseTreeUrl(path)) as any;
const { hash: routerHash } = parsePath(path);

if (!routerHash) {
return { ...routerState, pageType: PageType.Blob };
}

// get selected line number range from path which looks like:
// `/gitlab-org/gitlab/-/blob/HEAD/package.json#L10-L20`
const matches = routerHash.match(/^#L(\d+)(?:-L(\d+))?/);
const [_, startLineNumber = '0', endLineNumber] = matches ? matches : [];

return {
...routerState,
pageType: PageType.Blob,
startLine: parseInt(startLineNumber, 10),
endLine: parseInt(endLineNumber || startLineNumber, 10),
};
};
16 changes: 16 additions & 0 deletions extensions/github1s/src/adapters/gitlab1s/parser/commit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* @file GitLab Commit Url Parser
* @author netcon
*/

import { parsePath } from 'history';
import { RouterState, PageType } from '../../types';

export const parseCommitUrl = async (path: string): Promise<RouterState> => {
const pathParts = parsePath(path).pathname!.split('/').filter(Boolean);
const dashIndex = pathParts.indexOf('-');
const repo = pathParts.slice(0, dashIndex).join('/');
const commitSha = pathParts.slice(dashIndex + 2).join('/');

return { repo, pageType: PageType.Commit, ref: commitSha, commitSha };
};
16 changes: 16 additions & 0 deletions extensions/github1s/src/adapters/gitlab1s/parser/commits.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* @file GitLab Commit List Url Parser
* @author netcon
*/

import { parsePath } from 'history';
import { RouterState, PageType } from '../../types';

export const parseCommitsUrl = async (path: string): Promise<RouterState> => {
const pathParts = parsePath(path).pathname!.split('/').filter(Boolean);
const dashIndex = pathParts.indexOf('-');
const repo = pathParts.slice(0, dashIndex).join('/');
const ref = pathParts.slice(dashIndex + 2).join('/') || 'HEAD';

return { repo, pageType: PageType.CommitList, ref };
};
47 changes: 47 additions & 0 deletions extensions/github1s/src/adapters/gitlab1s/parser/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* @file GitLab Url Parser
* @author netcon
*/

import { PageType, RouterState } from '@/adapters/types';
import { parsePath } from 'history';
import { parseTreeUrl } from './tree';
import { parseBlobUrl } from './blob';
import { parseCommitsUrl } from './commits';
import { parseCommitUrl } from './commit';

const PAGE_TYPE_MAP = {
tree: PageType.Tree,
blob: PageType.Blob,
commit: PageType.Commit,
commits: PageType.CommitList,
};

export const parseGitLabPath = async (path: string): Promise<RouterState> => {
const pathParts = parsePath(path).pathname?.split('/').filter(Boolean) || [];
const dashIndex = pathParts.indexOf('-');
const typeSegment = dashIndex > 0 && pathParts[dashIndex + 1];
const pageType = typeSegment ? PAGE_TYPE_MAP[typeSegment] || PageType.Unknown : PageType.Tree;

if (dashIndex > 0) {
switch (pageType) {
case PageType.Tree:
case PageType.Unknown:
return parseTreeUrl(path);
case PageType.Blob:
return parseBlobUrl(path);
case PageType.Commit:
return parseCommitUrl(path);
case PageType.CommitList:
return parseCommitsUrl(path);
}
}

// fallback to default
return {
repo: 'gitlab-org/gitlab-docs',
ref: 'HEAD',
pageType: PageType.Tree,
filePath: '',
};
};
32 changes: 32 additions & 0 deletions extensions/github1s/src/adapters/gitlab1s/parser/tree.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* @file GitLab Tree Url Parser
* @author netcon
*/

import { parsePath } from 'history';
import { PageType, RouterState } from '../../types';
import { SourcegraphDataSource } from '@/adapters/sourcegraph/data-source';

export const extractRefPath = async (
repoFullName: string,
refAndFilePath: string
): Promise<{ ref: string; path: string }> => {
if (!refAndFilePath) {
return { ref: 'HEAD', path: '' };
}
if (refAndFilePath.match(/^HEAD(\/.*)?$/i)) {
return { ref: 'HEAD', path: refAndFilePath.slice(5) };
}

return SourcegraphDataSource.getInstance('gitlab').extractRefPath(repoFullName, refAndFilePath);
};

export const parseTreeUrl = async (path: string): Promise<RouterState> => {
const pathParts = parsePath(path).pathname!.split('/').filter(Boolean);
const dashIndex = pathParts.indexOf('-');
const repo = pathParts.slice(0, dashIndex).join('/');
const restParts = pathParts.slice(dashIndex + 2);
const { ref, path: filePath } = await extractRefPath(repo, restParts.join('/'));

return { pageType: PageType.Tree, repo, ref, filePath };
};
51 changes: 51 additions & 0 deletions extensions/github1s/src/adapters/gitlab1s/router-parser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* @file router parser
* @author netcon
*/

import * as adapterTypes from '../types';
import { parseGitLabPath } from './parser/index';

export class GitLab1sRouterParser extends adapterTypes.RouterParser {
private static instance: GitLab1sRouterParser | null = null;

public static getInstance(): GitLab1sRouterParser {
if (GitLab1sRouterParser.instance) {
return GitLab1sRouterParser.instance;
}
return (GitLab1sRouterParser.instance = new GitLab1sRouterParser());
}

parsePath(path: string): Promise<adapterTypes.RouterState> {
return parseGitLabPath(path);
}

buildTreePath(repo: string, ref?: string, filePath?: string): string {
return ref ? (filePath ? `/${repo}/-/tree/${ref}/${filePath}` : `/${repo}/-/tree/${ref}`) : `/${repo}`;
}

buildBlobPath(repo: string, ref: string, filePath: string, startLine?: number, endLine?: number): string {
const hash = startLine ? (endLine ? `#L${startLine}-L${endLine}` : `#L${startLine}`) : '';
return `/${repo}/-/blob/${ref}/${filePath}${hash}`;
}

buildCommitListPath(repo: string): string {
return `/${repo}/-/commits`;
}

buildCommitPath(repo: string, commitSha: string): string {
return `/${repo}/-/commit/${commitSha}`;
}

buildCodeReviewListPath(repo: string): string {
return `/${repo}/-/merge_requests`;
}

buildCodeReviewPath(repo: string, codeReviewId: string): adapterTypes.Promisable<string> {
return `/${repo}/-/merge_requests/${codeReviewId}`;
}

buildExternalLink(path: string): string {
return 'https://gitlab.com' + (path.startsWith('/') ? path : `/${path}`);
}
}
Loading