mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-12-19 17:01:13 +00:00
Update to ADO 5ed9b2130da7f822153531489d802c28986f5d30
This commit is contained in:
@@ -1,56 +1,46 @@
|
||||
import UrlUtility from "../Common/UrlUtility";
|
||||
import { RepoListItem } from "../Explorer/Controls/GitHub/GitHubReposComponent";
|
||||
import { IGitHubFile, IGitHubRepo } from "../GitHub/GitHubClient";
|
||||
import { IPinnedRepo } from "../Juno/JunoClient";
|
||||
|
||||
export class GitHubUtils {
|
||||
// The pattern is https://github.com/<owner>/<repo>/(blob|tree)/<branch>/<path>
|
||||
private static readonly UriPattern = "https://github.com/([^/]*)/([^/]*)/(blob|tree)/([^/]*)/?(.*)";
|
||||
// https://github.com/<owner>/<repo>/tree/<branch>
|
||||
// The url when users visit a repo/branch on github.com
|
||||
private static readonly RepoUriPattern = /https:\/\/github.com\/([^/]*)\/([^/]*)\/tree\/([^?]*)/;
|
||||
|
||||
// github://<owner>/<repo>/<path>?ref=<branch>
|
||||
// Custom scheme for github content
|
||||
private static readonly ContentUriPattern = /github:\/\/([^/]*)\/([^/]*)\/([^?]*)\?ref=(.*)/;
|
||||
|
||||
public static toRepoFullName(owner: string, repo: string): string {
|
||||
return `${owner}/${repo}`;
|
||||
}
|
||||
|
||||
public static toGitHubUriForRepoAndBranch(owner: string, repo: string, branch: string, path?: string): string {
|
||||
return UrlUtility.createUri(`https://github.com/${owner}/${repo}/tree/${branch}`, path);
|
||||
public static fromRepoUri(repoUri: string): undefined | { owner: string; repo: string; branch: string } {
|
||||
const matches = repoUri.match(GitHubUtils.RepoUriPattern);
|
||||
if (matches && matches.length > 3) {
|
||||
return {
|
||||
owner: matches[1],
|
||||
repo: matches[2],
|
||||
branch: matches[3]
|
||||
};
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
public static toGitHubUriForFile(gitHubFile: IGitHubFile): string {
|
||||
return decodeURIComponent(gitHubFile.html_url);
|
||||
}
|
||||
|
||||
public static fromGitHubUri(
|
||||
gitHubUri: string
|
||||
public static fromContentUri(
|
||||
contentUri: string
|
||||
): undefined | { owner: string; repo: string; branch: string; path: string } {
|
||||
try {
|
||||
const matches = gitHubUri.match(GitHubUtils.UriPattern);
|
||||
const matches = contentUri.match(GitHubUtils.ContentUriPattern);
|
||||
if (matches && matches.length > 4) {
|
||||
return {
|
||||
owner: matches[1],
|
||||
repo: matches[2],
|
||||
branch: matches[4],
|
||||
path: matches[5]
|
||||
path: matches[3]
|
||||
};
|
||||
} catch (error) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
public static toPinnedRepo(item: RepoListItem): IPinnedRepo {
|
||||
return {
|
||||
owner: item.repo.owner.login,
|
||||
name: item.repo.name,
|
||||
private: item.repo.private,
|
||||
branches: item.branches.map(element => ({ name: element.name }))
|
||||
};
|
||||
}
|
||||
|
||||
public static toGitHubRepo(pinnedRepo: IPinnedRepo): IGitHubRepo {
|
||||
return {
|
||||
owner: {
|
||||
login: pinnedRepo.owner
|
||||
},
|
||||
name: pinnedRepo.name,
|
||||
private: pinnedRepo.private
|
||||
};
|
||||
public static toContentUri(owner: string, repo: string, branch: string, path: string): string {
|
||||
return `github://${owner}/${repo}/${path}?ref=${branch}`;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user