mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-03-02 16:08:23 +00:00
* Remove enableGallery feature flag * Fix bugs * Add tests to increase coverage * Move favorites functionality behind feature.enableGalleryPublish flag * Show code cells in NotebookViewer * Use cosmos db logo as persona image for sample notebook gallery cards * Update gallery card snapshot to fix test
65 lines
2.0 KiB
TypeScript
65 lines
2.0 KiB
TypeScript
// https://github.com/<owner>/<repo>/tree/<branch>
|
|
// The url when users visit a repo/branch on github.com
|
|
export const RepoUriPattern = /https:\/\/github.com\/([^/]*)\/([^/]*)\/tree\/([^?]*)/;
|
|
|
|
// github://<owner>/<repo>/<path>?ref=<branch>
|
|
// Custom scheme for github content
|
|
export const ContentUriPattern = /github:\/\/([^/]*)\/([^/]*)\/([^?]*)\?ref=(.*)/;
|
|
|
|
// https://github.com/<owner>/<repo>/blob/<branch>/<path>
|
|
// We need to support this until we move to newer scheme for quickstarts
|
|
export const LegacyContentUriPattern = /https:\/\/github.com\/([^/]*)\/([^/]*)\/blob\/([^/]*)\/([^?]*)/;
|
|
|
|
export function toRepoFullName(owner: string, repo: string): string {
|
|
return `${owner}/${repo}`;
|
|
}
|
|
|
|
export function fromRepoUri(repoUri: string): undefined | { owner: string; repo: string; branch: string } {
|
|
const matches = repoUri.match(RepoUriPattern);
|
|
if (matches && matches.length > 3) {
|
|
return {
|
|
owner: matches[1],
|
|
repo: matches[2],
|
|
branch: matches[3]
|
|
};
|
|
}
|
|
|
|
return undefined;
|
|
}
|
|
|
|
export function fromContentUri(
|
|
contentUri: string
|
|
): undefined | { owner: string; repo: string; branch: string; path: string } {
|
|
let matches = contentUri.match(ContentUriPattern);
|
|
if (matches && matches.length > 4) {
|
|
return {
|
|
owner: matches[1],
|
|
repo: matches[2],
|
|
branch: matches[4],
|
|
path: matches[3]
|
|
};
|
|
}
|
|
|
|
matches = contentUri.match(LegacyContentUriPattern);
|
|
if (matches && matches.length > 4) {
|
|
console.log(`Using legacy github content uri scheme ${contentUri}`);
|
|
|
|
return {
|
|
owner: matches[1],
|
|
repo: matches[2],
|
|
branch: matches[3],
|
|
path: matches[4]
|
|
};
|
|
}
|
|
|
|
return undefined;
|
|
}
|
|
|
|
export function toContentUri(owner: string, repo: string, branch: string, path: string): string {
|
|
return `github://${owner}/${repo}/${path}?ref=${branch}`;
|
|
}
|
|
|
|
export function toRawContentUri(owner: string, repo: string, branch: string, path: string): string {
|
|
return `https://raw.githubusercontent.com/${owner}/${repo}/${branch}/${path}`;
|
|
}
|