Skip to content
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
10 changes: 6 additions & 4 deletions plugins.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ Deno.test("tryResolveUserLatestJson", async () => {
{
const result = await getValidResultForUrl("https://plugins.dprint.dev/dprint/typescript/latest.json");
const releaseInfo = await getLatestReleaseInfo("dprint", "dprint-plugin-typescript");
assertEquals(releaseInfo?.checksum?.length, 64);
assertEquals(result, {
schemaVersion: 1,
url: `https://plugins.dprint.dev/typescript-${releaseInfo!.tagName}.wasm`,
version: releaseInfo!.tagName,
checksum: undefined,
checksum: releaseInfo!.checksum,
});
}
// dprint repo full name
Expand All @@ -35,11 +36,12 @@ Deno.test("tryResolveUserLatestJson", async () => {
"https://plugins.dprint.dev/dprint/dprint-plugin-typescript/latest.json",
);
const releaseInfo = await getLatestReleaseInfo("dprint", "dprint-plugin-typescript");
assertEquals(releaseInfo?.checksum?.length, 64);
assertEquals(result, {
schemaVersion: 1,
url: `https://plugins.dprint.dev/typescript-${releaseInfo!.tagName}.wasm`,
version: releaseInfo!.tagName,
checksum: undefined,
checksum: releaseInfo!.checksum,
});
}
// non-dprint repo
Expand All @@ -50,7 +52,7 @@ Deno.test("tryResolveUserLatestJson", async () => {
schemaVersion: 1,
url: `https://plugins.dprint.dev/malobre/vue-${releaseInfo!.tagName}.wasm`,
version: releaseInfo!.tagName.replace(/^v/, ""),
checksum: undefined,
checksum: releaseInfo!.checksum,
});
}
// non-dprint repo full name
Expand All @@ -61,7 +63,7 @@ Deno.test("tryResolveUserLatestJson", async () => {
schemaVersion: 1,
url: `https://plugins.dprint.dev/malobre/vue-${releaseInfo!.tagName}.wasm`,
version: releaseInfo!.tagName.replace(/^v/, ""),
checksum: undefined,
checksum: releaseInfo!.checksum,
});
}
// process plugin repo
Expand Down
20 changes: 15 additions & 5 deletions utils/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,21 @@ function getReleaseInfo(data: GitHubRelease): ReleaseInfo {
};

function getChecksum() {
if (typeof data.body !== "string") {
return undefined;
if (typeof data.body === "string") {
// search the body text for a dprint style checksum
const checksum = /\@([a-z0-9]{64})\b/i.exec(data.body);
if (checksum?.[1]) {
return checksum[1];
}
}
// fall back to the digest from the release asset
const assetName = getPluginKind() === "wasm" ? "plugin.wasm" : "plugin.json";
const asset = data.assets?.find((a) => a.name === assetName);
if (asset?.digest) {
const match = /^sha256:([a-f0-9]{64})$/i.exec(asset.digest);
return match?.[1];
}
// search the body text for a dprint style checksum
const checksum = /\@([a-z0-9]{64})\b/i.exec(data.body);
return checksum?.[1];
return undefined;
}

function getPluginKind(): ReleaseInfo["kind"] {
Expand All @@ -93,6 +102,7 @@ function getDownloadCount(assets: ReleaseAsset[]) {
interface ReleaseAsset {
name: string;
download_count: number;
digest: string | null;
}

export async function getAllDownloadCount(username: string, repoName: string) {
Expand Down