bstack 1.2.1 → 1.4.0

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.
Files changed (2) hide show
  1. package/dist/bstack.mjs +51 -12
  2. package/package.json +1 -1
package/dist/bstack.mjs CHANGED
@@ -6,7 +6,7 @@ import * as v from "valibot";
6
6
  import { mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
7
7
  import { dirname } from "node:path";
8
8
  //#region package.json
9
- var version = "1.2.1";
9
+ var version = "1.4.0";
10
10
  //#endregion
11
11
  //#region src/command.ts
12
12
  var CommandError = class extends Error {
@@ -279,6 +279,7 @@ var GitCliRepository = class {
279
279
  remote,
280
280
  ...refspecs
281
281
  ]);
282
+ return branches.filter((branch) => existing.get(branch.name) !== branch.oid).map((branch) => branch.name);
282
283
  }
283
284
  statePath() {
284
285
  return this.git([
@@ -509,6 +510,25 @@ var GitHubCliPlatform = class {
509
510
  }
510
511
  };
511
512
  //#endregion
513
+ //#region src/output.ts
514
+ function formatSyncResult(result, dryRun) {
515
+ const changeCount = `${result.changes.length} change${result.changes.length === 1 ? "" : "s"}`;
516
+ const lines = [dryRun ? `Would sync ${changeCount} against ${result.base}:` : `Synced stack against ${result.base} (${changeCount}):`];
517
+ if (dryRun) {
518
+ for (const change of result.changes) lines.push(` ${change.oid.slice(0, 8)} ${change.subject}`);
519
+ return lines.join("\n");
520
+ }
521
+ for (const outcome of result.outcomes) {
522
+ if (outcome.outcome === "closed") {
523
+ const { pullRequest } = outcome;
524
+ lines.push(` ${outcome.outcome.padEnd(9)} #${pullRequest.number} ${pullRequest.title} ${pullRequest.url}`);
525
+ continue;
526
+ }
527
+ lines.push(` ${outcome.outcome.padEnd(9)} #${outcome.pullRequest.number} ${outcome.change.subject} ${outcome.pullRequest.url}`);
528
+ }
529
+ return lines.join("\n");
530
+ }
531
+ //#endregion
512
532
  //#region src/reporter.ts
513
533
  var ConsoleReporter = class {
514
534
  progress(message) {
@@ -702,7 +722,8 @@ function syncStack(dependencies, options) {
702
722
  base,
703
723
  remote,
704
724
  rewritten,
705
- changes: [...changes]
725
+ changes: [...changes],
726
+ outcomes: []
706
727
  };
707
728
  }
708
729
  reporter.progress("Reading the previous stack state");
@@ -726,11 +747,13 @@ function syncStack(dependencies, options) {
726
747
  }
727
748
  }
728
749
  reporter.progress(`Pushing ${changes.length} remote branch${changes.length === 1 ? "" : "es"}`);
750
+ let pushedBranches = /* @__PURE__ */ new Set();
729
751
  try {
730
- repository.pushBranches(remote, changes.map((change) => ({
752
+ const updatedBranches = repository.pushBranches(remote, changes.map((change) => ({
731
753
  name: change.remoteBranch,
732
754
  oid: change.oid
733
755
  })));
756
+ pushedBranches = new Set(updatedBranches);
734
757
  } catch (error) {
735
758
  if (isReorder) restorePreviousStack(github, previous, base, remote, reporter, error);
736
759
  throw error;
@@ -744,6 +767,7 @@ function syncStack(dependencies, options) {
744
767
  reporter.progress(`Creating pull request: ${change.subject}`);
745
768
  return github.createPullRequest(change, pullRequestBase, options.draft);
746
769
  });
770
+ const createdBranches = new Set(changes.filter((_change, index) => existing[index] === void 0).map((change) => change.remoteBranch));
747
771
  if (changes.length === 1) {
748
772
  if (transition.kind === "partial") reporter.progress("Updating this down-stack prefix while preserving higher pull requests");
749
773
  const pullRequest = pullRequests[0];
@@ -803,16 +827,35 @@ function syncStack(dependencies, options) {
803
827
  if (stackNumber !== void 0) updatedStack.stackNumber = stackNumber;
804
828
  writeUpdatedState(stateStore, state, previous, updatedStack);
805
829
  reporter.progress("Saved the local stack state");
830
+ const synchronized = changes.map((change, index) => ({
831
+ ...change,
832
+ pullRequest: pullRequests[index]
833
+ }));
834
+ const outcomes = synchronized.map((change, index) => ({
835
+ outcome: changeOutcome(change, index, change.pullRequest, previous, changes, base, createdBranches, pushedBranches),
836
+ change,
837
+ pullRequest: change.pullRequest
838
+ }));
839
+ outcomes.push(...omittedPullRequests.map((pullRequest) => ({
840
+ outcome: "closed",
841
+ pullRequest
842
+ })));
806
843
  return {
807
844
  base,
808
845
  remote,
809
846
  rewritten,
810
- changes: changes.map((change, index) => ({
811
- ...change,
812
- pullRequest: pullRequests[index]
813
- }))
847
+ changes: synchronized,
848
+ outcomes
814
849
  };
815
850
  }
851
+ function changeOutcome(change, index, pullRequest, previous, changes, base, createdBranches, pushedBranches) {
852
+ if (createdBranches.has(change.remoteBranch)) return "created";
853
+ const previousIndex = previous?.changes.findIndex((candidate) => candidate.id === change.id);
854
+ const previousBase = previousIndex === void 0 || previousIndex < 0 ? void 0 : previousIndex === 0 ? previous.base : previous.changes[previousIndex - 1].remoteBranch;
855
+ const currentBase = index === 0 ? base : changes[index - 1].remoteBranch;
856
+ const metadataChanged = pullRequest.title !== change.subject || pullRequest.body !== change.body;
857
+ return pushedBranches.has(change.remoteBranch) || previousBase !== currentBase || metadataChanged ? "updated" : "unchanged";
858
+ }
816
859
  function restorePreviousStack(github, previous, base, remote, reporter, rebuildError) {
817
860
  const rebuildMessage = rebuildError instanceof Error ? rebuildError.message : String(rebuildError);
818
861
  reporter.progress("Rebuild failed; restoring the previous native GitHub stack");
@@ -926,11 +969,7 @@ function main() {
926
969
  draft: values.draft,
927
970
  dryRun: values["dry-run"]
928
971
  });
929
- console.log(`${values["dry-run"] ? "Would sync" : "Synced"} ${result.changes.length} change${result.changes.length === 1 ? "" : "s"} against ${result.base}:`);
930
- for (const change of result.changes) {
931
- const destination = change.pullRequest ? ` ${change.pullRequest.url}` : "";
932
- console.log(` ${change.oid.slice(0, 8)} ${change.subject}${destination}`);
933
- }
972
+ console.log(formatSyncResult(result, values["dry-run"]));
934
973
  }
935
974
  try {
936
975
  main();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bstack",
3
- "version": "1.2.1",
3
+ "version": "1.4.0",
4
4
  "description": "Create native GitHub stacked pull requests from a linear series of commits",
5
5
  "license": "MIT",
6
6
  "repository": {