git-stack-cli 0.7.0 → 0.7.2

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.
@@ -50,9 +50,11 @@ async function run(props) {
50
50
  try {
51
51
  // create temporary branch based on merge base
52
52
  await cli(`git checkout -b ${temp_branch_name} ${rebase_merge_base}`);
53
+ const pr_url_list = commit_range.group_list.map(get_group_url);
53
54
  for (let i = rebase_group_index; i < commit_range.group_list.length; i++) {
54
55
  const group = commit_range.group_list[i];
55
56
  invariant(group.base, "group.base must exist");
57
+ const selected_url = get_group_url(group);
56
58
  // cherry-pick and amend commits one by one
57
59
  for (const commit of group.commits) {
58
60
  await cli(`git cherry-pick ${commit.sha}`);
@@ -78,8 +80,8 @@ async function run(props) {
78
80
  base: group.base,
79
81
  body: StackSummaryTable.write({
80
82
  body: group.pr.body,
81
- commit_range,
82
- selected_group_id: group.id,
83
+ pr_url_list,
84
+ selected_url,
83
85
  }),
84
86
  });
85
87
  }
@@ -89,21 +91,51 @@ async function run(props) {
89
91
  // move to temporary branch for creating pr
90
92
  await cli(`git checkout -b ${group.id}`);
91
93
  // create pr in github
92
- await github.pr_create({
94
+ const pr_url = await github.pr_create({
93
95
  branch: group.id,
94
96
  base: group.base,
95
97
  title: group.title,
96
- body: StackSummaryTable.write({
97
- body: "",
98
- commit_range,
99
- selected_group_id: group.id,
100
- }),
98
+ body: "",
101
99
  });
100
+ if (!pr_url) {
101
+ throw new Error("unable to create pr");
102
+ }
103
+ // update pr_url_list with created pr_url
104
+ for (let i = 0; i < pr_url_list.length; i++) {
105
+ const url = pr_url_list[i];
106
+ if (url === selected_url) {
107
+ pr_url_list[i] = pr_url;
108
+ }
109
+ }
102
110
  // move back to temp branch
103
111
  await cli(`git checkout ${temp_branch_name}`);
104
112
  }
105
113
  }
106
114
  }
115
+ // finally, ensure all prs have the updated stack table from updated pr_url_list
116
+ for (let i = 0; i < commit_range.group_list.length; i++) {
117
+ const group = commit_range.group_list[i];
118
+ // use the updated pr_url_list to get the actual selected_url
119
+ const selected_url = pr_url_list[i];
120
+ invariant(group.base, "group.base must exist");
121
+ const body = group.pr?.body || "";
122
+ const update_body = StackSummaryTable.write({
123
+ body,
124
+ pr_url_list,
125
+ selected_url,
126
+ });
127
+ if (update_body === body) {
128
+ actions.debug(`Skipping body update for ${selected_url}`);
129
+ }
130
+ else {
131
+ actions.debug(`Update body for ${selected_url}`);
132
+ await github.pr_edit({
133
+ branch: group.id,
134
+ base: group.base,
135
+ body: update_body,
136
+ });
137
+ }
138
+ }
107
139
  // after all commits have been cherry-picked and amended
108
140
  // move the branch pointer to the newly created temporary branch
109
141
  // now we are in locally in sync with github and on the original branch
@@ -152,3 +184,4 @@ async function run(props) {
152
184
  actions.exit(5);
153
185
  }
154
186
  }
187
+ const get_group_url = (group) => group.pr?.url || group.id;
@@ -2,6 +2,7 @@ import * as React from "react";
2
2
  import * as Ink from "ink";
3
3
  import { clamp } from "../core/clamp.js";
4
4
  import { colors } from "../core/colors.js";
5
+ import { is_finite_value } from "../core/is_finite_value.js";
5
6
  import { wrap_index } from "../core/wrap_index.js";
6
7
  export function MultiSelect(props) {
7
8
  const [selected_set, select] = React.useReducer((state, value) => {
@@ -25,18 +26,18 @@ export function MultiSelect(props) {
25
26
  const [index, set_index] = React.useReducer((_, value) => {
26
27
  return clamp(value, 0, props.items.length - 1);
27
28
  }, 0, function find_initial_index() {
28
- let firstEnabled;
29
+ let last_enabled;
29
30
  for (let i = props.items.length - 1; i >= 0; i--) {
30
31
  const item = props.items[i];
31
- if (!item.disabled && firstEnabled === undefined) {
32
- firstEnabled = i;
32
+ if (!item.disabled) {
33
+ last_enabled = i;
33
34
  }
34
- if (item.selected && !item.disabled) {
35
+ if (!item.selected && !item.disabled) {
35
36
  return i;
36
37
  }
37
38
  }
38
- if (typeof firstEnabled === "number") {
39
- return firstEnabled;
39
+ if (is_finite_value(last_enabled)) {
40
+ return last_enabled;
40
41
  }
41
42
  return 0;
42
43
  });
@@ -1,17 +1,19 @@
1
1
  export function write(args) {
2
- const group_list = args.commit_range?.group_list;
3
- if (!Array.isArray(group_list) || group_list.length === 0) {
4
- return "";
5
- }
6
2
  const stack_list = [];
7
- for (const group of group_list) {
8
- if (group.pr?.url) {
9
- const selected = args.selected_group_id === group.id;
3
+ for (const pr_url of args.pr_url_list) {
4
+ if (pr_url) {
5
+ const selected = args.selected_url === pr_url;
10
6
  const icon = selected ? "👉" : "⏳";
11
- stack_list.push(`- ${icon} ${group.pr.url}`);
7
+ stack_list.push(`- ${icon} ${pr_url}`);
12
8
  }
13
9
  }
14
- const stack_table = TEMPLATE.stack_table(["", ...stack_list, "", ""].join("\n"));
10
+ let stack_table;
11
+ if (stack_list.length > 1) {
12
+ stack_table = TEMPLATE.stack_table(["", ...stack_list, "", ""].join("\n"));
13
+ }
14
+ else {
15
+ stack_table = "";
16
+ }
15
17
  let result = args.body;
16
18
  if (RE.stack_table.test(result)) {
17
19
  // replace stack table
@@ -86,7 +86,9 @@ export async function pr_create(args) {
86
86
  const cli_result = await cli(`gh pr create --fill --head ${args.branch} --base ${args.base} --title="${title}" --body="${args.body}"`);
87
87
  if (cli_result.code !== 0) {
88
88
  handle_error(cli_result.output);
89
+ return null;
89
90
  }
91
+ return cli_result.stdout;
90
92
  }
91
93
  export async function pr_edit(args) {
92
94
  const cli_result = await cli(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "git-stack-cli",
3
- "version": "0.7.0",
3
+ "version": "0.7.2",
4
4
  "description": "",
5
5
  "author": "magus",
6
6
  "license": "MIT",