@ucdjs/release-scripts 0.1.0-beta.1 → 0.1.0-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -99,6 +99,10 @@ interface ReleaseOptions {
99
99
  * GitHub token for authentication
100
100
  */
101
101
  githubToken: string;
102
+ pullRequest?: {
103
+ title: string;
104
+ body: string;
105
+ };
102
106
  }
103
107
  interface ReleaseResult {
104
108
  /**
package/dist/index.mjs CHANGED
@@ -342,6 +342,27 @@ async function rebaseBranch(ontoBranch, workspaceRoot) {
342
342
  await run("git", ["rebase", ontoBranch], { nodeOptions: { cwd: workspaceRoot } });
343
343
  }
344
344
  /**
345
+ * Check if local branch is ahead of remote (has commits to push)
346
+ * @param branch - The branch name to check
347
+ * @param workspaceRoot - The root directory of the workspace
348
+ * @returns Promise resolving to true if local is ahead, false otherwise
349
+ */
350
+ async function isBranchAheadOfRemote(branch, workspaceRoot) {
351
+ try {
352
+ const result = await run("git", [
353
+ "rev-list",
354
+ `origin/${branch}..${branch}`,
355
+ "--count"
356
+ ], { nodeOptions: {
357
+ cwd: workspaceRoot,
358
+ stdio: "pipe"
359
+ } });
360
+ return Number.parseInt(result.stdout.trim(), 10) > 0;
361
+ } catch {
362
+ return true;
363
+ }
364
+ }
365
+ /**
345
366
  * Check if there are any changes to commit (staged or unstaged)
346
367
  * @param workspaceRoot - The root directory of the workspace
347
368
  * @returns Promise resolving to true if there are changes, false otherwise
@@ -386,34 +407,6 @@ async function pushBranch(branch, workspaceRoot, options) {
386
407
  else if (options?.force) args.push("--force");
387
408
  await run("git", args, { nodeOptions: { cwd: workspaceRoot } });
388
409
  }
389
- /**
390
- * Generate PR body from version updates
391
- * @param updates - Array of version updates to include in the PR body
392
- * @returns Formatted PR body as a string
393
- */
394
- function generatePRBody(updates) {
395
- const lines = [];
396
- lines.push("## Packages");
397
- lines.push("");
398
- const directChanges = updates.filter((u) => u.hasDirectChanges);
399
- const dependencyUpdates = updates.filter((u) => !u.hasDirectChanges);
400
- if (directChanges.length > 0) {
401
- lines.push("### Direct Changes");
402
- lines.push("");
403
- for (const update of directChanges) lines.push(`- **${update.package.name}**: ${update.currentVersion} → ${update.newVersion} (${update.bumpType})`);
404
- lines.push("");
405
- }
406
- if (dependencyUpdates.length > 0) {
407
- lines.push("### Dependency Updates");
408
- lines.push("");
409
- for (const update of dependencyUpdates) lines.push(`- **${update.package.name}**: ${update.currentVersion} → ${update.newVersion} (dependencies changed)`);
410
- lines.push("");
411
- }
412
- lines.push("---");
413
- lines.push("");
414
- lines.push("This release PR was automatically generated.");
415
- return lines.join("\n");
416
- }
417
410
 
418
411
  //#endregion
419
412
  //#region src/github.ts
@@ -481,6 +474,29 @@ async function upsertPullRequest({ owner, repo, title, body, head, base, pullNum
481
474
  throw err;
482
475
  }
483
476
  }
477
+ function generatePullRequestBody(updates, _body) {
478
+ const lines = [];
479
+ lines.push("## Packages");
480
+ lines.push("");
481
+ const directChanges = updates.filter((u) => u.hasDirectChanges);
482
+ const dependencyUpdates = updates.filter((u) => !u.hasDirectChanges);
483
+ if (directChanges.length > 0) {
484
+ lines.push("### Direct Changes");
485
+ lines.push("");
486
+ for (const update of directChanges) lines.push(`- **${update.package.name}**: ${update.currentVersion} → ${update.newVersion} (${update.bumpType})`);
487
+ lines.push("");
488
+ }
489
+ if (dependencyUpdates.length > 0) {
490
+ lines.push("### Dependency Updates");
491
+ lines.push("");
492
+ for (const update of dependencyUpdates) lines.push(`- **${update.package.name}**: ${update.currentVersion} → ${update.newVersion} (dependencies changed)`);
493
+ lines.push("");
494
+ }
495
+ lines.push("---");
496
+ lines.push("");
497
+ lines.push("This release PR was automatically generated.");
498
+ return lines.join("\n");
499
+ }
484
500
 
485
501
  //#endregion
486
502
  //#region src/prompts.ts
@@ -717,8 +733,10 @@ async function release(options) {
717
733
  console.log("Rebasing release branch onto", currentBranch);
718
734
  await rebaseBranch(currentBranch, workspaceRoot);
719
735
  await updatePackageJsonFiles(allUpdates);
720
- if (!await commitChanges("chore: update release versions", workspaceRoot)) {
721
- console.log("No changes to commit");
736
+ const hasCommitted = await commitChanges("chore: update release versions", workspaceRoot);
737
+ const isBranchAhead = await isBranchAheadOfRemote(releaseBranch, workspaceRoot);
738
+ if (!hasCommitted && !isBranchAhead) {
739
+ console.log("No changes to commit and branch is in sync with remote");
722
740
  await checkoutBranch(currentBranch, workspaceRoot);
723
741
  if (prExists) {
724
742
  console.log("No updates needed, PR is already up to date");
@@ -734,8 +752,8 @@ async function release(options) {
734
752
  }
735
753
  console.log("Pushing changes to remote");
736
754
  await pushBranch(releaseBranch, workspaceRoot, { forceWithLease: true });
737
- const prTitle = existingPullRequest?.title || "Release: Update package versions";
738
- const prBody = generatePRBody(allUpdates);
755
+ const prTitle = existingPullRequest?.title || options.pullRequest?.title || "chore: update package versions";
756
+ const prBody = generatePullRequestBody(allUpdates, options.pullRequest?.body);
739
757
  const pullRequest = await upsertPullRequest({
740
758
  owner,
741
759
  repo,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ucdjs/release-scripts",
3
- "version": "0.1.0-beta.1",
3
+ "version": "0.1.0-beta.3",
4
4
  "description": "@ucdjs release scripts",
5
5
  "type": "module",
6
6
  "license": "MIT",