Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add --only-templates flag #172

Merged
merged 2 commits into from
Aug 19, 2024
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ 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.

For repositories with many packages, comments might get too long. In that case, you can use `--only-templates` to only show templates.

pkg.pr.new uses `npm pack --json` under the hood, in case you face issues, you can also use the `--pnpm` flag so it starts using `pnpm pack`. This is not necessary in most cases.

<img width="100%" src="https://github.com/stackblitz-labs/pkg.pr.new/assets/37929992/2fc03b94-ebae-4c47-a271-03a4ad5d2449" />
Expand Down
4 changes: 4 additions & 0 deletions packages/backend/server/routes/publish.post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ export default eventHandler(async (event) => {
"sb-comment": commentHeader,
"sb-compact": compactHeader,
"sb-package-manager": packageManagerHeader,
"sb-only-templates": onlyTemplatesHeader,
} = getHeaders(event);
const compact = compactHeader === "true";
const onlyTemplates = onlyTemplatesHeader === "true";
const comment: Comment = (commentHeader ?? "update") as Comment;
const packageManager: PackageManager =
(packageManagerHeader as PackageManager) || "npm";
Expand Down Expand Up @@ -230,6 +232,7 @@ export default eventHandler(async (event) => {
packagesWithoutPrefix,
workflowData,
compact,
onlyTemplates,
checkRunUrl,
packageManager,
"ref",
Expand All @@ -249,6 +252,7 @@ export default eventHandler(async (event) => {
packagesWithoutPrefix,
workflowData,
compact,
onlyTemplates,
checkRunUrl,
packageManager,
comment === "update" ? "ref" : "sha",
Expand Down
5 changes: 5 additions & 0 deletions packages/backend/server/utils/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export function generatePullRequestPublishMessage(
packages: string[],
workflowData: WorkflowData,
compact: boolean,
onlyTemplates: boolean,
checkRunUrl: string,
packageManager: PackageManager,
base: "sha" | "ref",
Expand Down Expand Up @@ -80,6 +81,10 @@ ${packageManager} ${packageCommands[packageManager]} ${refUrl}

const templatesStr = generateTemplatesStr(templates);

if(onlyTemplates) {
return templatesStr
}

return `
_commit: <a href="${checkRunUrl}"><code>${abbreviateCommitHash(workflowData.sha)}</code></a>_

Expand Down
7 changes: 7 additions & 0 deletions packages/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ 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",
},
onlyTemplates: {
type: "boolean",
description: `generate only stackblitz templates`,
default: false,
},
},
run: async ({ args }) => {
const paths = (args._.length ? args._ : ["."])
Expand All @@ -83,6 +88,7 @@ const main = defineCommand({
const isCompact = !!args.compact;
const isPnpm = !!args.pnpm;
const isPeerDepsEnabled = !!args.peerDeps
const isOnlyTemplates = !!args.onlyTemplates

const comment: Comment = args.comment as Comment;

Expand Down Expand Up @@ -299,6 +305,7 @@ const main = defineCommand({
"sb-shasums": JSON.stringify(shasums),
"sb-run-id": GITHUB_RUN_ID,
"sb-package-manager": packageManager,
"sb-only-templates": `${isOnlyTemplates}`
},
body: formData,
});
Expand Down
Loading