git-stack-cli 2.7.8 → 2.8.1

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/src/core/git.ts CHANGED
@@ -1,8 +1,11 @@
1
1
  import { Store } from "~/app/Store";
2
2
  import * as Metadata from "~/core/Metadata";
3
3
  import { cli } from "~/core/cli";
4
+ import { invariant } from "~/core/invariant";
4
5
 
5
- export type Commit = Awaited<ReturnType<typeof get_commits>>[0];
6
+ type CommitList = Awaited<ReturnType<typeof get_commits>>;
7
+
8
+ export type Commit = CommitList[0];
6
9
 
7
10
  export async function get_commits(dot_range: string) {
8
11
  const log_result = await cli(`git log ${dot_range} --format=${FORMAT} --color=never`);
@@ -34,6 +37,7 @@ export async function get_commits(dot_range: string) {
34
37
  const branch_id = metadata.id;
35
38
  const subject_line = metadata.subject || "";
36
39
  const title = metadata.title;
40
+ const master_base = metadata.base === "master";
37
41
 
38
42
  const commit = {
39
43
  sha,
@@ -41,6 +45,7 @@ export async function get_commits(dot_range: string) {
41
45
  subject_line,
42
46
  branch_id,
43
47
  title,
48
+ master_base,
44
49
  };
45
50
 
46
51
  commit_list.push(commit);
@@ -51,6 +56,15 @@ export async function get_commits(dot_range: string) {
51
56
  return commit_list;
52
57
  }
53
58
 
59
+ export async function get_diff(commit_list: CommitList) {
60
+ invariant(commit_list.length, "commit_list must exist");
61
+ const first_commit = commit_list[0];
62
+ const last_commit = commit_list[commit_list.length - 1];
63
+ const sha_range = `${first_commit.sha}~1..${last_commit.sha}`;
64
+ const diff_result = await cli(`git --no-pager diff --color=never ${sha_range}`);
65
+ return diff_result.stdout;
66
+ }
67
+
54
68
  // Why these separators?
55
69
  // - Rare in human written text
56
70
  // - Supported in git %xNN to write bytes
@@ -167,6 +167,10 @@ type EditPullRequestArgs = {
167
167
  };
168
168
 
169
169
  export async function pr_edit(args: EditPullRequestArgs) {
170
+ // const state = Store.getState();
171
+ // const actions = state.actions;
172
+ // actions.debug(`github.pr_edit ${JSON.stringify(args)}`);
173
+
170
174
  const command_parts = [`gh pr edit ${args.branch}`];
171
175
 
172
176
  if (args.base) {
@@ -237,6 +241,20 @@ export async function pr_draft(args: DraftPullRequestArgs) {
237
241
  }
238
242
  }
239
243
 
244
+ export async function pr_diff(number: number) {
245
+ // https://cli.github.com/manual/gh_pr_diff
246
+
247
+ const cli_result = await cli(`gh pr diff --color=never ${number}`);
248
+
249
+ if (cli_result.code !== 0) {
250
+ handle_error(cli_result.output);
251
+ }
252
+
253
+ return cli_result.stdout;
254
+ }
255
+
256
+ // pull request JSON fields
257
+ // https://cli.github.com/manual/gh_pr_list
240
258
  // prettier-ignore
241
259
  const JSON_FIELDS = "--json id,number,state,baseRefName,headRefName,commits,title,body,url,isDraft";
242
260
 
@@ -281,11 +299,10 @@ async function write_body_file(args: EditPullRequestArgs) {
281
299
  invariant(args.body, "args.body must exist");
282
300
 
283
301
  // ensure unique filename is safe for filesystem
284
- // base (group id) might contain slashes, e.g. dev/magus/gs-3cmrMBSUj
302
+ // args.branch_id (group id) might contain slashes, e.g. dev/magus/gs-3cmrMBSUj
285
303
  // the flashes would mess up the filesystem path to this file
286
- let base = args.base || "master";
287
- base = base.replace(/^origin\//, "");
288
- let tmp_filename = safe_filename(`git-stack-body-${base}`);
304
+ const branch = args.branch;
305
+ let tmp_filename = safe_filename(`git-stack-body-${branch}`);
289
306
 
290
307
  const temp_path = path.join(await get_tmp_dir(), tmp_filename);
291
308