git-stack-cli 1.8.0 → 1.8.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.
@@ -27273,8 +27273,6 @@ const RE$1 = {
27273
27273
  group_title: new RegExp(TEMPLATE$1.group_title("(?<title>[^\\n^\\r]+)"), "i"),
27274
27274
  };
27275
27275
 
27276
- // prettier-ignore
27277
- const JSON_FIELDS = "--json number,state,baseRefName,headRefName,commits,title,body,url";
27278
27276
  async function pr_list() {
27279
27277
  const state = Store.getState();
27280
27278
  const actions = state.actions;
@@ -27282,13 +27280,10 @@ async function pr_list() {
27282
27280
  const repo_path = state.repo_path;
27283
27281
  invariant(username, "username must exist");
27284
27282
  invariant(repo_path, "repo_path must exist");
27285
- const cli_result = await cli(`gh pr list --repo ${repo_path} --author ${username} --state open ${JSON_FIELDS}`, {
27286
- ignoreExitCode: true,
27287
- });
27288
- if (cli_result.code !== 0) {
27289
- handle_error(cli_result.output);
27283
+ const result_pr_list = await gh_json(`pr list --repo ${repo_path} --author ${username} --state open ${JSON_FIELDS}`);
27284
+ if (result_pr_list instanceof Error) {
27285
+ handle_error(result_pr_list.message);
27290
27286
  }
27291
- const result_pr_list = JSON.parse(cli_result.stdout);
27292
27287
  if (actions.isDebug()) {
27293
27288
  actions.output(reactExports.createElement(Text, { dimColor: true },
27294
27289
  reactExports.createElement(Text, null, "Github cache "),
@@ -27332,14 +27327,10 @@ async function pr_status(branch) {
27332
27327
  reactExports.createElement(Text, null, " "),
27333
27328
  reactExports.createElement(Text, { dimColor: true }, branch)));
27334
27329
  }
27335
- const cli_result = await cli(`gh pr view ${branch} --repo ${repo_path} ${JSON_FIELDS}`, {
27336
- ignoreExitCode: true,
27337
- });
27338
- if (cli_result.code !== 0) {
27339
- // handle_error(cli_result.output);
27330
+ const pr = await gh_json(`pr view ${branch} --repo ${repo_path} ${JSON_FIELDS}`);
27331
+ if (pr instanceof Error) {
27340
27332
  return null;
27341
27333
  }
27342
- const pr = JSON.parse(cli_result.stdout);
27343
27334
  actions.set((state) => {
27344
27335
  state.pr[pr.headRefName] = pr;
27345
27336
  });
@@ -27366,6 +27357,22 @@ async function pr_edit(args) {
27366
27357
  handle_error(cli_result.output);
27367
27358
  }
27368
27359
  }
27360
+ // prettier-ignore
27361
+ const JSON_FIELDS = "--json number,state,baseRefName,headRefName,commits,title,body,url";
27362
+ // consistent handle gh cli commands returning json
27363
+ // redirect to tmp file to avoid scrollback overflow causing scrollback to be cleared
27364
+ async function gh_json(command) {
27365
+ const tmp_pr_json = path.join(os.tmpdir(), "git-stack-gh.json");
27366
+ const options = { ignoreExitCode: true };
27367
+ const cli_result = await cli(`gh ${command} > ${tmp_pr_json}`, options);
27368
+ if (cli_result.code !== 0) {
27369
+ return new Error(cli_result.output);
27370
+ }
27371
+ // read from file
27372
+ const json_str = fs.readFileSync(tmp_pr_json, "utf-8");
27373
+ const json = JSON.parse(json_str);
27374
+ return json;
27375
+ }
27369
27376
  function handle_error(output) {
27370
27377
  const state = Store.getState();
27371
27378
  const actions = state.actions;
@@ -27658,7 +27665,7 @@ async function run$4() {
27658
27665
  process.once("SIGINT", handle_exit);
27659
27666
  const temp_branch_name = `${branch_name}_${short_id()}`;
27660
27667
  try {
27661
- actions.debug(`commit_range=${JSON.stringify(commit_range, null, 2)}`);
27668
+ // actions.debug(`commit_range=${JSON.stringify(commit_range, null, 2)}`);
27662
27669
  // must perform rebase from repo root for applying git patch
27663
27670
  process.chdir(repo_root);
27664
27671
  await cli(`pwd`);
@@ -27976,7 +27983,7 @@ async function run$3() {
27976
27983
  }
27977
27984
  actions.debug(`rebase_merge_base = ${rebase_merge_base}`);
27978
27985
  actions.debug(`rebase_group_index = ${rebase_group_index}`);
27979
- actions.debug(`commit_range=${JSON.stringify(commit_range, null, 2)}`);
27986
+ // actions.debug(`commit_range=${JSON.stringify(commit_range, null, 2)}`);
27980
27987
  try {
27981
27988
  // must perform rebase from repo root for applying git patch
27982
27989
  process.chdir(repo_root);
@@ -28062,7 +28069,7 @@ echo "$GIT_REVISE_TODO" > "$git_revise_todo_path"
28062
28069
  `GIT_REVISE_TODO="${git_revise_todo}"`,
28063
28070
  `git`,
28064
28071
  `revise --edit -i ${rebase_merge_base}`,
28065
- ]);
28072
+ ], { stdio: ["ignore", "ignore", "ignore"] });
28066
28073
  // early return since we do not need to sync
28067
28074
  if (!argv.sync) {
28068
28075
  return;
@@ -34550,7 +34557,7 @@ async function command() {
34550
34557
  .wrap(123)
34551
34558
  // disallow unknown options
34552
34559
  .strict()
34553
- .version("1.8.0" )
34560
+ .version("1.8.2" )
34554
34561
  .showHidden("show-hidden", "Show hidden options via `git stack help --show-hidden`")
34555
34562
  .help("help", "Show usage via `git stack help`").argv);
34556
34563
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "git-stack-cli",
3
- "version": "1.8.0",
3
+ "version": "1.8.2",
4
4
  "description": "",
5
5
  "author": "magus",
6
6
  "license": "MIT",
@@ -63,7 +63,6 @@
63
63
  "@types/yargs": "^17.0.29",
64
64
  "@typescript-eslint/eslint-plugin": "^6.9.0",
65
65
  "@typescript-eslint/parser": "^6.9.0",
66
- "bun": "^1.0.26",
67
66
  "bun-types": "^1.0.21",
68
67
  "eslint": "^8.52.0",
69
68
  "eslint-import-resolver-typescript": "^3.6.1",
@@ -43,7 +43,7 @@ async function run() {
43
43
  const temp_branch_name = `${branch_name}_${short_id()}`;
44
44
 
45
45
  try {
46
- actions.debug(`commit_range=${JSON.stringify(commit_range, null, 2)}`);
46
+ // actions.debug(`commit_range=${JSON.stringify(commit_range, null, 2)}`);
47
47
 
48
48
  // must perform rebase from repo root for applying git patch
49
49
  process.chdir(repo_root);
@@ -83,7 +83,8 @@ async function run() {
83
83
 
84
84
  actions.debug(`rebase_merge_base = ${rebase_merge_base}`);
85
85
  actions.debug(`rebase_group_index = ${rebase_group_index}`);
86
- actions.debug(`commit_range=${JSON.stringify(commit_range, null, 2)}`);
86
+
87
+ // actions.debug(`commit_range=${JSON.stringify(commit_range, null, 2)}`);
87
88
 
88
89
  try {
89
90
  // must perform rebase from repo root for applying git patch
@@ -153,12 +154,15 @@ async function run() {
153
154
 
154
155
  // execute cli with temporary git sequence editor script
155
156
  // revise from merge base to pick correct commits
156
- await cli([
157
- `GIT_EDITOR="${tmp_git_sequence_editor_path}"`,
158
- `GIT_REVISE_TODO="${git_revise_todo}"`,
159
- `git`,
160
- `revise --edit -i ${rebase_merge_base}`,
161
- ]);
157
+ await cli(
158
+ [
159
+ `GIT_EDITOR="${tmp_git_sequence_editor_path}"`,
160
+ `GIT_REVISE_TODO="${git_revise_todo}"`,
161
+ `git`,
162
+ `revise --edit -i ${rebase_merge_base}`,
163
+ ],
164
+ { stdio: ["ignore", "ignore", "ignore"] }
165
+ );
162
166
 
163
167
  // early return since we do not need to sync
164
168
  if (!argv.sync) {
@@ -13,9 +13,6 @@ import { colors } from "~/core/colors";
13
13
  import { invariant } from "~/core/invariant";
14
14
  import { safe_quote } from "~/core/safe_quote";
15
15
 
16
- // prettier-ignore
17
- const JSON_FIELDS = "--json number,state,baseRefName,headRefName,commits,title,body,url";
18
-
19
16
  export async function pr_list(): Promise<Array<PullRequest>> {
20
17
  const state = Store.getState();
21
18
  const actions = state.actions;
@@ -25,19 +22,14 @@ export async function pr_list(): Promise<Array<PullRequest>> {
25
22
  invariant(username, "username must exist");
26
23
  invariant(repo_path, "repo_path must exist");
27
24
 
28
- const cli_result = await cli(
29
- `gh pr list --repo ${repo_path} --author ${username} --state open ${JSON_FIELDS}`,
30
- {
31
- ignoreExitCode: true,
32
- }
25
+ const result_pr_list = await gh_json<Array<PullRequest>>(
26
+ `pr list --repo ${repo_path} --author ${username} --state open ${JSON_FIELDS}`
33
27
  );
34
28
 
35
- if (cli_result.code !== 0) {
36
- handle_error(cli_result.output);
29
+ if (result_pr_list instanceof Error) {
30
+ handle_error(result_pr_list.message);
37
31
  }
38
32
 
39
- const result_pr_list: Array<PullRequest> = JSON.parse(cli_result.stdout);
40
-
41
33
  if (actions.isDebug()) {
42
34
  actions.output(
43
35
  <Ink.Text dimColor>
@@ -105,20 +97,14 @@ export async function pr_status(branch: string): Promise<null | PullRequest> {
105
97
  );
106
98
  }
107
99
 
108
- const cli_result = await cli(
109
- `gh pr view ${branch} --repo ${repo_path} ${JSON_FIELDS}`,
110
- {
111
- ignoreExitCode: true,
112
- }
100
+ const pr = await gh_json<PullRequest>(
101
+ `pr view ${branch} --repo ${repo_path} ${JSON_FIELDS}`
113
102
  );
114
103
 
115
- if (cli_result.code !== 0) {
116
- // handle_error(cli_result.output);
104
+ if (pr instanceof Error) {
117
105
  return null;
118
106
  }
119
107
 
120
- const pr: PullRequest = JSON.parse(cli_result.stdout);
121
-
122
108
  actions.set((state) => {
123
109
  state.pr[pr.headRefName] = pr;
124
110
  });
@@ -169,6 +155,27 @@ export async function pr_edit(args: EditPullRequestArgs) {
169
155
  }
170
156
  }
171
157
 
158
+ // prettier-ignore
159
+ const JSON_FIELDS = "--json number,state,baseRefName,headRefName,commits,title,body,url";
160
+
161
+ // consistent handle gh cli commands returning json
162
+ // redirect to tmp file to avoid scrollback overflow causing scrollback to be cleared
163
+ async function gh_json<T>(command: string): Promise<T | Error> {
164
+ const tmp_pr_json = path.join(os.tmpdir(), "git-stack-gh.json");
165
+
166
+ const options = { ignoreExitCode: true };
167
+ const cli_result = await cli(`gh ${command} > ${tmp_pr_json}`, options);
168
+
169
+ if (cli_result.code !== 0) {
170
+ return new Error(cli_result.output);
171
+ }
172
+
173
+ // read from file
174
+ const json_str = fs.readFileSync(tmp_pr_json, "utf-8");
175
+ const json = JSON.parse(json_str);
176
+ return json;
177
+ }
178
+
172
179
  function handle_error(output: string): never {
173
180
  const state = Store.getState();
174
181
  const actions = state.actions;