git-stack-cli 2.9.0 → 2.9.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.
@@ -7,6 +7,7 @@ import path from "node:path";
7
7
  import * as Ink from "ink-cjs";
8
8
 
9
9
  import { Brackets } from "~/app/Brackets";
10
+ import { FormatText } from "~/app/FormatText";
10
11
  import { Store } from "~/app/Store";
11
12
  import { Timer } from "~/core/Timer";
12
13
  import { cli } from "~/core/cli";
@@ -38,16 +39,19 @@ export async function pr_list(): Promise<Array<PullRequest>> {
38
39
 
39
40
  if (actions.isDebug()) {
40
41
  actions.output(
41
- <Ink.Text dimColor>
42
- <Ink.Text>{"Github cache "}</Ink.Text>
43
- <Ink.Text bold color={colors.yellow}>
44
- {result_pr_list.length}
45
- </Ink.Text>
46
- <Ink.Text>{" open PRs from "}</Ink.Text>
47
- <Brackets>{repo_path}</Brackets>
48
- <Ink.Text>{" authored by "}</Ink.Text>
49
- <Brackets>{username}</Brackets>
50
- </Ink.Text>,
42
+ <FormatText
43
+ wrapper={<Ink.Text dimColor />}
44
+ message="Github cache {count} open PRs from {repo_path} authored by {username}"
45
+ values={{
46
+ count: (
47
+ <Ink.Text bold color={colors.yellow}>
48
+ {result_pr_list.length}
49
+ </Ink.Text>
50
+ ),
51
+ repo_path: <Brackets>{repo_path}</Brackets>,
52
+ username: <Brackets>{username}</Brackets>,
53
+ }}
54
+ />,
51
55
  );
52
56
  }
53
57
 
@@ -76,15 +80,11 @@ export async function pr_status(branch: string): Promise<null | PullRequest> {
76
80
  if (cache) {
77
81
  if (actions.isDebug()) {
78
82
  actions.debug(
79
- <Ink.Text>
80
- <Ink.Text dimColor>Github pr_status cache</Ink.Text>
81
- <Ink.Text> </Ink.Text>
82
- <Ink.Text bold color={colors.green}>
83
- {"HIT "}
84
- </Ink.Text>
85
- <Ink.Text> </Ink.Text>
86
- <Ink.Text dimColor>{branch}</Ink.Text>
87
- </Ink.Text>,
83
+ cache_message({
84
+ hit: true,
85
+ message: "Github pr_status cache",
86
+ extra: branch,
87
+ }),
88
88
  );
89
89
  }
90
90
 
@@ -93,15 +93,11 @@ export async function pr_status(branch: string): Promise<null | PullRequest> {
93
93
 
94
94
  if (actions.isDebug()) {
95
95
  actions.debug(
96
- <Ink.Text>
97
- <Ink.Text dimColor>Github pr_status cache</Ink.Text>
98
- <Ink.Text> </Ink.Text>
99
- <Ink.Text bold color={colors.red}>
100
- MISS
101
- </Ink.Text>
102
- <Ink.Text> </Ink.Text>
103
- <Ink.Text dimColor>{branch}</Ink.Text>
104
- </Ink.Text>,
96
+ cache_message({
97
+ hit: false,
98
+ message: "Github pr_status cache",
99
+ extra: branch,
100
+ }),
105
101
  );
106
102
  }
107
103
 
@@ -246,14 +242,46 @@ export async function pr_draft(args: DraftPullRequestArgs) {
246
242
  }
247
243
 
248
244
  export async function pr_diff(number: number) {
249
- // https://cli.github.com/manual/gh_pr_diff
245
+ const state = Store.getState();
246
+ const actions = state.actions;
247
+
248
+ const maybe_diff = state.cache_pr_diff[number];
249
+
250
+ if (maybe_diff) {
251
+ if (actions.isDebug()) {
252
+ actions.debug(
253
+ cache_message({
254
+ hit: true,
255
+ message: "Github pr_diff cache",
256
+ extra: number,
257
+ }),
258
+ );
259
+ }
260
+
261
+ return maybe_diff;
262
+ }
250
263
 
264
+ if (actions.isDebug()) {
265
+ actions.debug(
266
+ cache_message({
267
+ hit: false,
268
+ message: "Github pr_diff cache",
269
+ extra: number,
270
+ }),
271
+ );
272
+ }
273
+
274
+ // https://cli.github.com/manual/gh_pr_diff
251
275
  const cli_result = await cli(`gh pr diff --color=never ${number}`);
252
276
 
253
277
  if (cli_result.code !== 0) {
254
278
  handle_error(cli_result.output);
255
279
  }
256
280
 
281
+ actions.set((state) => {
282
+ state.cache_pr_diff[number] = cli_result.output;
283
+ });
284
+
257
285
  return cli_result.stdout;
258
286
  }
259
287
 
@@ -321,6 +349,36 @@ function safe_filename(value: string): string {
321
349
  return value.replace(RE.non_alphanumeric_dash, "-");
322
350
  }
323
351
 
352
+ type CacheMessageArgs = {
353
+ hit: boolean;
354
+ message: React.ReactNode;
355
+ extra: React.ReactNode;
356
+ };
357
+
358
+ function cache_message(args: CacheMessageArgs) {
359
+ const status = args.hit ? (
360
+ <Ink.Text bold color={colors.green}>
361
+ HIT
362
+ </Ink.Text>
363
+ ) : (
364
+ <Ink.Text bold color={colors.red}>
365
+ MISS
366
+ </Ink.Text>
367
+ );
368
+
369
+ return (
370
+ <FormatText
371
+ wrapper={<Ink.Text dimColor />}
372
+ message="{message} {status} {extra}"
373
+ values={{
374
+ message: args.message,
375
+ status,
376
+ extra: args.extra,
377
+ }}
378
+ />
379
+ );
380
+ }
381
+
324
382
  type Commit = {
325
383
  authoredDate: string; // "2023-10-22T23:13:35Z"
326
384
  authors: [