Skip to content
Draft
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
27 changes: 26 additions & 1 deletion src/extension/extension-host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,25 @@ const githubBranchUrlProvider = {
},
};

const githubCommitUrlProvider = {
extensionUrl: (host: ExtensionHost) => {
if (host.modifier && isCommitSha(host.modifier)) {
return `https://github.com/${host.organization}/${host.repo}/archive/${host.modifier}${archiveExt}`;
}
},
archiveSubdir: (host: ExtensionHost) => {
const baseDir = `${host.repo}-${host.modifier}`;
if (host.subdirectory) {
return baseDir + "/" + host.subdirectory;
} else {
return baseDir;
}
},
learnMoreUrl: (host: ExtensionHost) => {
return `https://github.com/${host.organization}/${host.repo}/tree/${host.modifier}#readme`;
},
};

// The github extension source
const kGithubExtensionSource: ExtensionHostSource = {
parse: (name: string) => {
Expand All @@ -184,6 +203,7 @@ const kGithubExtensionSource: ExtensionHostSource = {
urlProviders: [
githubLatestUrlProvider,
githubTagUrlProvider,
githubCommitUrlProvider,
githubBranchUrlProvider,
],
};
Expand Down Expand Up @@ -218,7 +238,7 @@ const kGithubArchiveUrlSource: ExtensionHostSource = {
};

const kGithubArchiveUrlRegex =
/https?\:\/\/github.com\/([a-zA-Z0-9-_\.]+?)\/([a-zA-Z0-9-_\.]+?)\/archive\/refs\/(?:tags|heads)\/(.+)(?:\.tar\.gz|\.zip)$/;
/https?\:\/\/github.com\/([a-zA-Z0-9-_\.]+?)\/([a-zA-Z0-9-_\.]+?)\/archive\/(?:refs\/(?:tags|heads)\/)?(.+)(?:\.tar\.gz|\.zip)$/;

function tagSubDirectory(tag?: string) {
// Strip the leading 'v' from tag names
Expand All @@ -229,6 +249,11 @@ function tagSubDirectory(tag?: string) {
}
}

function isCommitSha(modifier?: string): boolean {
if (!modifier) return false;
return /^[a-f0-9]{7,40}$/i.test(modifier);
}

function makeResolvers(
source: ExtensionHostSource,
): ExtensionNameResolver[] {
Expand Down
4 changes: 4 additions & 0 deletions tests/smoke/extensions/install.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,12 @@ const extUrls = [
"quarto-ext/lightbox@cool",
"quarto-ext/[email protected]",
"quarto-ext/lightbox@test/use-in-quarto-cli",
"quarto-ext/lightbox@a738ff253fd46dd0cdd6aa992178cb7561b70251",
"quarto-ext/lightbox@a738ff2",
"https://github.com/quarto-ext/lightbox/archive/refs/tags/v0.1.4.tar.gz",
"https://github.com/quarto-ext/lightbox/archive/refs/heads/main.tar.gz",
"https://github.com/quarto-ext/lightbox/archive/refs/heads/cool.tar.gz",
"https://github.com/quarto-ext/lightbox/archive/a738ff253fd46dd0cdd6aa992178cb7561b70251.tar.gz",
];

if (!isLinux) {
Expand All @@ -77,6 +80,7 @@ if (!isLinux) {
"https://github.com/quarto-ext/lightbox/archive/refs/tags/v0.1.4.zip",
"https://github.com/quarto-ext/lightbox/archive/refs/heads/main.zip",
"https://github.com/quarto-ext/lightbox/archive/refs/heads/cool.zip",
"https://github.com/quarto-ext/lightbox/archive/a738ff253fd46dd0cdd6aa992178cb7561b70251.zip",
],
);
}
Expand Down
Loading