Skip to content

Commit d2ab9db

Browse files
committed
fix: for latest.json, get checksum from release asset
1 parent e20a089 commit d2ab9db

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

plugins.test.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@ Deno.test("tryResolveUserLatestJson", async () => {
2222
{
2323
const result = await getValidResultForUrl("https://plugins.dprint.dev/dprint/typescript/latest.json");
2424
const releaseInfo = await getLatestReleaseInfo("dprint", "dprint-plugin-typescript");
25+
assertEquals(releaseInfo?.checksum?.length, 64);
2526
assertEquals(result, {
2627
schemaVersion: 1,
2728
url: `https://plugins.dprint.dev/typescript-${releaseInfo!.tagName}.wasm`,
2829
version: releaseInfo!.tagName,
29-
checksum: undefined,
30+
checksum: releaseInfo!.checksum,
3031
});
3132
}
3233
// dprint repo full name
@@ -35,11 +36,12 @@ Deno.test("tryResolveUserLatestJson", async () => {
3536
"https://plugins.dprint.dev/dprint/dprint-plugin-typescript/latest.json",
3637
);
3738
const releaseInfo = await getLatestReleaseInfo("dprint", "dprint-plugin-typescript");
39+
assertEquals(releaseInfo?.checksum?.length, 64);
3840
assertEquals(result, {
3941
schemaVersion: 1,
4042
url: `https://plugins.dprint.dev/typescript-${releaseInfo!.tagName}.wasm`,
4143
version: releaseInfo!.tagName,
42-
checksum: undefined,
44+
checksum: releaseInfo!.checksum,
4345
});
4446
}
4547
// non-dprint repo
@@ -50,7 +52,7 @@ Deno.test("tryResolveUserLatestJson", async () => {
5052
schemaVersion: 1,
5153
url: `https://plugins.dprint.dev/malobre/vue-${releaseInfo!.tagName}.wasm`,
5254
version: releaseInfo!.tagName.replace(/^v/, ""),
53-
checksum: undefined,
55+
checksum: releaseInfo!.checksum,
5456
});
5557
}
5658
// non-dprint repo full name
@@ -61,7 +63,7 @@ Deno.test("tryResolveUserLatestJson", async () => {
6163
schemaVersion: 1,
6264
url: `https://plugins.dprint.dev/malobre/vue-${releaseInfo!.tagName}.wasm`,
6365
version: releaseInfo!.tagName.replace(/^v/, ""),
64-
checksum: undefined,
66+
checksum: releaseInfo!.checksum,
6567
});
6668
}
6769
// process plugin repo

utils/github.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,21 @@ function getReleaseInfo(data: GitHubRelease): ReleaseInfo {
6161
};
6262

6363
function getChecksum() {
64-
if (typeof data.body !== "string") {
65-
return undefined;
64+
if (typeof data.body === "string") {
65+
// search the body text for a dprint style checksum
66+
const checksum = /\@([a-z0-9]{64})\b/i.exec(data.body);
67+
if (checksum?.[1]) {
68+
return checksum[1];
69+
}
70+
}
71+
// fall back to the digest from the release asset
72+
const assetName = getPluginKind() === "wasm" ? "plugin.wasm" : "plugin.json";
73+
const asset = data.assets?.find((a) => a.name === assetName);
74+
if (asset?.digest) {
75+
const match = /^sha256:([a-f0-9]{64})$/i.exec(asset.digest);
76+
return match?.[1];
6677
}
67-
// search the body text for a dprint style checksum
68-
const checksum = /\@([a-z0-9]{64})\b/i.exec(data.body);
69-
return checksum?.[1];
78+
return undefined;
7079
}
7180

7281
function getPluginKind(): ReleaseInfo["kind"] {
@@ -93,6 +102,7 @@ function getDownloadCount(assets: ReleaseAsset[]) {
93102
interface ReleaseAsset {
94103
name: string;
95104
download_count: number;
105+
digest: string | null;
96106
}
97107

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

0 commit comments

Comments
 (0)