diff --git a/README.md b/README.md index f5bd72b6..174599e9 100644 --- a/README.md +++ b/README.md @@ -198,6 +198,20 @@ With `--comment=create`, each commit would generate a comment for itself, useful And `--comment=off` would turn off comments for maintainers who prefer minimal pull requests. +> `--commentWithSha` specify whether to replace the pr number with sha commit in the generated comments. + +With `--commentWithSha`: + +```sh +npm i https://pkg.pr.new/tinybench@a832a55 +``` + +Without `--commentWithSha`: + +```sh +npm i https://pkg.pr.new/tinybench@123 +``` + To customize which package manager is reflected in the comments, use the `--packageManager=XYZ` flag. XYZ can be one of the following: npm (default), pnpm, yarn, or bun. Multiple valid values ​​can also be configured at the same time, such as `--packageManager=ABC,XYZ`. For repositories with many packages, comments might get too long. In that case, you can use `--only-templates` to only show templates. diff --git a/packages/app/server/routes/publish.post.ts b/packages/app/server/routes/publish.post.ts index e1d4cc67..3ca882e4 100644 --- a/packages/app/server/routes/publish.post.ts +++ b/packages/app/server/routes/publish.post.ts @@ -21,6 +21,7 @@ export default eventHandler(async (event) => { "sb-bin": binHeader, "sb-package-manager": packageManagerHeader, "sb-only-templates": onlyTemplatesHeader, + "sb-comment-with-sha": commentWithShaHeader, } = getHeaders(event); const compact = compactHeader === "true"; const onlyTemplates = onlyTemplatesHeader === "true"; @@ -28,6 +29,7 @@ export default eventHandler(async (event) => { const bin = binHeader === "true"; const packageManager: PackageManager = (packageManagerHeader as PackageManager) || "npm"; + const commentWithSha = commentWithShaHeader === "true"; if (!key || !runIdHeader || !shasumsHeader) { throw createError({ @@ -290,7 +292,7 @@ export default eventHandler(async (event) => { onlyTemplates, checkRunUrl, packageManager, - "ref", + commentWithSha ? "sha" : "ref", bin, ), }, diff --git a/packages/cli/index.ts b/packages/cli/index.ts index bd593160..9f963f31 100644 --- a/packages/cli/index.ts +++ b/packages/cli/index.ts @@ -1,5 +1,4 @@ /* eslint-disable unicorn/no-process-exit */ -import assert from "node:assert"; import path from "node:path"; import { createHash } from "node:crypto"; import fsSync from "node:fs"; @@ -89,6 +88,12 @@ const main = defineCommand({ description: `"off" for no comments (silent mode). "create" for comment on each publish. "update" for one comment across the pull request with edits on each publish (default)`, default: "update", }, + commentWithSha: { + type: "boolean", + description: + "use commit sha instead of the pr number in the comment links", + default: false, + }, "only-templates": { type: "boolean", description: `generate only stackblitz templates`, @@ -143,6 +148,7 @@ const main = defineCommand({ const isPeerDepsEnabled = !!args.peerDeps; const isOnlyTemplates = !!args["only-templates"]; const isBinaryApplication = !!args.bin; + const isCommentWithSha = !!args.commentWithSha; const comment: Comment = args.comment as Comment; const selectedPackageManager = (args.packageManager as string) .split(",") @@ -542,6 +548,7 @@ const main = defineCommand({ "sb-bin": `${isBinaryApplication}`, "sb-package-manager": selectedPackageManager.join(","), "sb-only-templates": `${isOnlyTemplates}`, + "sb-comment-with-sha": `${isCommentWithSha}`, }, body: formData, });