git-stack-cli 1.12.0 → 1.13.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.
- package/README.md +11 -1
- package/dist/cjs/index.cjs +154 -203
- package/package.json +1 -1
- package/src/app/AutoUpdate.tsx +5 -3
- package/src/app/CherryPickCheck.tsx +4 -4
- package/src/app/Debug.tsx +12 -9
- package/src/app/DependencyCheck.tsx +0 -6
- package/src/app/ManualRebase.tsx +114 -183
- package/src/app/PreManualRebase.tsx +6 -5
- package/src/app/RebaseCheck.tsx +3 -3
- package/src/command.ts +0 -16
- package/src/commands/Rebase.tsx +2 -15
- package/src/core/GitReviseTodo.ts +3 -3
- package/src/core/github.tsx +18 -9
- package/src/core/read_json.ts +3 -3
- package/src/core/safe_exists.ts +10 -0
- package/src/core/safe_rm.ts +10 -0
package/src/core/github.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
|
|
3
|
-
import fs from "node:fs";
|
|
3
|
+
import fs from "node:fs/promises";
|
|
4
4
|
import os from "node:os";
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
|
|
@@ -12,6 +12,7 @@ import { cli } from "~/core/cli";
|
|
|
12
12
|
import { colors } from "~/core/colors";
|
|
13
13
|
import { invariant } from "~/core/invariant";
|
|
14
14
|
import { safe_quote } from "~/core/safe_quote";
|
|
15
|
+
import { safe_rm } from "~/core/safe_rm";
|
|
15
16
|
|
|
16
17
|
export async function pr_list(): Promise<Array<PullRequest>> {
|
|
17
18
|
const state = Store.getState();
|
|
@@ -148,7 +149,8 @@ export async function pr_edit(args: EditPullRequestArgs) {
|
|
|
148
149
|
const command_parts = [`gh pr edit ${args.branch} --base ${args.base}`];
|
|
149
150
|
|
|
150
151
|
if (args.body) {
|
|
151
|
-
|
|
152
|
+
const body_file = await write_body_file(args);
|
|
153
|
+
command_parts.push(`--body-file="${body_file}"`);
|
|
152
154
|
}
|
|
153
155
|
|
|
154
156
|
const command = command_parts.join(" ");
|
|
@@ -166,6 +168,10 @@ type DraftPullRequestArgs = {
|
|
|
166
168
|
};
|
|
167
169
|
|
|
168
170
|
export async function pr_draft(args: DraftPullRequestArgs) {
|
|
171
|
+
// https://cli.github.com/manual/gh_api
|
|
172
|
+
// https://docs.github.com/en/graphql/reference/mutations#convertpullrequesttodraft
|
|
173
|
+
// https://docs.github.com/en/graphql/reference/mutations#markpullrequestreadyforreview
|
|
174
|
+
|
|
169
175
|
const mutation_name = args.draft
|
|
170
176
|
? "convertPullRequestToDraft"
|
|
171
177
|
: "markPullRequestReadyForReview";
|
|
@@ -220,7 +226,7 @@ async function gh_json<T>(command: string): Promise<T | Error> {
|
|
|
220
226
|
}
|
|
221
227
|
|
|
222
228
|
// read from file
|
|
223
|
-
const json_str = fs.
|
|
229
|
+
const json_str = await fs.readFile(tmp_pr_json, "utf-8");
|
|
224
230
|
const json = JSON.parse(json_str);
|
|
225
231
|
return json;
|
|
226
232
|
}
|
|
@@ -237,13 +243,16 @@ function handle_error(output: string): never {
|
|
|
237
243
|
}
|
|
238
244
|
|
|
239
245
|
// convert a string to a file for use via github cli `--body-file`
|
|
240
|
-
function
|
|
246
|
+
async function write_body_file(args: EditPullRequestArgs) {
|
|
247
|
+
invariant(args.body, "args.body must exist");
|
|
248
|
+
|
|
241
249
|
const temp_dir = os.tmpdir();
|
|
242
|
-
const temp_path = path.join(temp_dir,
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
fs.
|
|
250
|
+
const temp_path = path.join(temp_dir, `git-stack-body-${args.base}`);
|
|
251
|
+
|
|
252
|
+
await safe_rm(temp_path);
|
|
253
|
+
|
|
254
|
+
await fs.writeFile(temp_path, args.body);
|
|
255
|
+
|
|
247
256
|
return temp_path;
|
|
248
257
|
}
|
|
249
258
|
|
package/src/core/read_json.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import fs from "node:fs";
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
2
|
|
|
3
|
-
export function read_json<T = unknown>(path: string): null | T {
|
|
3
|
+
export async function read_json<T = unknown>(path: string): Promise<null | T> {
|
|
4
4
|
try {
|
|
5
|
-
const file_buffer = fs.
|
|
5
|
+
const file_buffer = await fs.readFile(path);
|
|
6
6
|
const json_str = String(file_buffer);
|
|
7
7
|
const json = JSON.parse(json_str);
|
|
8
8
|
return json;
|