git-stack-cli 0.8.5 → 0.8.6
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.
|
@@ -1,28 +1,9 @@
|
|
|
1
1
|
export function write(args) {
|
|
2
|
-
const
|
|
3
|
-
const digits = String(args.pr_url_list.length).length;
|
|
4
|
-
for (let i = 0; i < args.pr_url_list.length; i++) {
|
|
5
|
-
const pr_url = args.pr_url_list[i];
|
|
6
|
-
if (pr_url) {
|
|
7
|
-
const selected = args.selected_url === pr_url;
|
|
8
|
-
const icon = selected ? "👉" : "⏳";
|
|
9
|
-
const num = String(i + 1).padStart(digits, "0");
|
|
10
|
-
stack_list.push(`- ${icon} \`${num}\` ${pr_url}`);
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
// reverse order of pr list to match the order of git stack
|
|
14
|
-
stack_list.reverse();
|
|
15
|
-
let stack_table;
|
|
16
|
-
if (stack_list.length > 1) {
|
|
17
|
-
stack_table = TEMPLATE.stack_table(["", ...stack_list, "", ""].join("\n"));
|
|
18
|
-
}
|
|
19
|
-
else {
|
|
20
|
-
stack_table = "";
|
|
21
|
-
}
|
|
2
|
+
const stack_table = table(args);
|
|
22
3
|
let result = args.body;
|
|
23
4
|
if (RE.stack_table.test(result)) {
|
|
24
5
|
// replace stack table
|
|
25
|
-
result = result.replace(
|
|
6
|
+
result = result.replace(RE.stack_table, stack_table);
|
|
26
7
|
}
|
|
27
8
|
else {
|
|
28
9
|
// append stack table
|
|
@@ -31,12 +12,76 @@ export function write(args) {
|
|
|
31
12
|
result = result.trimEnd();
|
|
32
13
|
return result;
|
|
33
14
|
}
|
|
15
|
+
export function table(args) {
|
|
16
|
+
const stack_pr_url_list = [...args.pr_url_list];
|
|
17
|
+
const old_stack = parse(args.body);
|
|
18
|
+
// remove existing stack pr urls from the old stack pr urls
|
|
19
|
+
for (const pr_url of stack_pr_url_list) {
|
|
20
|
+
old_stack.delete(pr_url);
|
|
21
|
+
}
|
|
22
|
+
// add remaining old stack pr urls to the front of stack pr url list
|
|
23
|
+
for (const pr_url of old_stack.keys()) {
|
|
24
|
+
stack_pr_url_list.unshift(pr_url);
|
|
25
|
+
}
|
|
26
|
+
const stack_list = [];
|
|
27
|
+
const num_digits = String(stack_pr_url_list.length).length;
|
|
28
|
+
for (let i = 0; i < stack_pr_url_list.length; i++) {
|
|
29
|
+
const pr_url = stack_pr_url_list[i];
|
|
30
|
+
const selected = args.selected_url === pr_url;
|
|
31
|
+
let icon;
|
|
32
|
+
if (old_stack.has(pr_url)) {
|
|
33
|
+
icon = "✅";
|
|
34
|
+
}
|
|
35
|
+
else if (selected) {
|
|
36
|
+
icon = "👉";
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
icon = "⏳";
|
|
40
|
+
}
|
|
41
|
+
const num = String(i + 1).padStart(num_digits, "0");
|
|
42
|
+
stack_list.push(TEMPLATE.row({ icon, num, pr_url }));
|
|
43
|
+
}
|
|
44
|
+
if (!stack_list.length) {
|
|
45
|
+
return "";
|
|
46
|
+
}
|
|
47
|
+
// reverse order of pr list to match the order of git stack
|
|
48
|
+
stack_list.reverse();
|
|
49
|
+
return TEMPLATE.stack_table(["", ...stack_list, "", ""].join("\n"));
|
|
50
|
+
}
|
|
51
|
+
export function parse(body) {
|
|
52
|
+
const stack_table_match = body.match(RE.stack_table);
|
|
53
|
+
if (!stack_table_match?.groups) {
|
|
54
|
+
return new Map();
|
|
55
|
+
}
|
|
56
|
+
const rows_string = stack_table_match.groups["rows"];
|
|
57
|
+
const row_list = rows_string.split("\n");
|
|
58
|
+
const result = new Map();
|
|
59
|
+
for (const row of row_list) {
|
|
60
|
+
const row_match = row.match(RE.row);
|
|
61
|
+
const parsed_row = row_match?.groups;
|
|
62
|
+
if (!parsed_row) {
|
|
63
|
+
// eslint-disable-next-line no-console
|
|
64
|
+
console.error(`parse row [${row}]`);
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
result.set(parsed_row.pr_url, parsed_row);
|
|
68
|
+
}
|
|
69
|
+
return result;
|
|
70
|
+
}
|
|
34
71
|
const TEMPLATE = {
|
|
35
72
|
stack_table(rows) {
|
|
36
73
|
return `#### git stack${rows}`;
|
|
37
74
|
},
|
|
75
|
+
row(args) {
|
|
76
|
+
return `- ${args.icon} \`${args.num}\` ${args.pr_url}`;
|
|
77
|
+
},
|
|
38
78
|
};
|
|
39
79
|
const RE = {
|
|
40
80
|
// https://regex101.com/r/kqB9Ft/1
|
|
41
81
|
stack_table: new RegExp(TEMPLATE.stack_table("\\s+(?<rows>(?:- [^\r^\n]*(?:[\r\n]+)?)+)")),
|
|
82
|
+
row: new RegExp(TEMPLATE.row({
|
|
83
|
+
icon: "(?<icon>.+)",
|
|
84
|
+
num: "(?<num>\\d+)",
|
|
85
|
+
pr_url: "(?<pr_url>.+)",
|
|
86
|
+
})),
|
|
42
87
|
};
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { test, expect } from "bun:test";
|
|
2
|
+
import * as StackSummaryTable from "./StackSummaryTable.js";
|
|
3
|
+
test("blank", () => {
|
|
4
|
+
const output = StackSummaryTable.write({
|
|
5
|
+
body: "",
|
|
6
|
+
pr_url_list: [],
|
|
7
|
+
selected_url: "",
|
|
8
|
+
});
|
|
9
|
+
expect(output).toBe("");
|
|
10
|
+
});
|
|
11
|
+
test("no prs does not modify body", () => {
|
|
12
|
+
const args = {
|
|
13
|
+
body: `## Problem\n\nDescription of the problem\n\n## Solution\n\nSolved problem by doing x, y, z.`,
|
|
14
|
+
pr_url_list: [],
|
|
15
|
+
selected_url: "",
|
|
16
|
+
};
|
|
17
|
+
const output = StackSummaryTable.write(args);
|
|
18
|
+
expect(output).toBe(args.body);
|
|
19
|
+
});
|
|
20
|
+
test("builds list of prs with selected emoji", () => {
|
|
21
|
+
const args = {
|
|
22
|
+
body: "## Problem\n\nDescription of the problem\n\n## Solution\n\nSolved problem by doing x, y, z.",
|
|
23
|
+
pr_url_list: [
|
|
24
|
+
"https://github.com/magus/git-multi-diff-playground/pull/43",
|
|
25
|
+
"https://github.com/magus/git-multi-diff-playground/pull/47",
|
|
26
|
+
],
|
|
27
|
+
selected_url: "https://github.com/magus/git-multi-diff-playground/pull/43",
|
|
28
|
+
};
|
|
29
|
+
const output = StackSummaryTable.write(args);
|
|
30
|
+
expect(output.split("\n")).toEqual([
|
|
31
|
+
...args.body.split("\n"),
|
|
32
|
+
"",
|
|
33
|
+
"#### git stack",
|
|
34
|
+
"- ⏳ `2` https://github.com/magus/git-multi-diff-playground/pull/47",
|
|
35
|
+
"- 👉 `1` https://github.com/magus/git-multi-diff-playground/pull/43",
|
|
36
|
+
]);
|
|
37
|
+
});
|
|
38
|
+
test("can parse stack table from body", () => {
|
|
39
|
+
const body_line_list = [
|
|
40
|
+
"",
|
|
41
|
+
"",
|
|
42
|
+
"#### git stack",
|
|
43
|
+
"- invalid line that will be dropped",
|
|
44
|
+
"- ⏳ `2` https://github.com/magus/git-multi-diff-playground/pull/47",
|
|
45
|
+
"- 👉 `1` https://github.com/magus/git-multi-diff-playground/pull/43",
|
|
46
|
+
];
|
|
47
|
+
const parsed = StackSummaryTable.parse(body_line_list.join("\n"));
|
|
48
|
+
expect(Array.from(parsed.entries())).toEqual([
|
|
49
|
+
[
|
|
50
|
+
"https://github.com/magus/git-multi-diff-playground/pull/47",
|
|
51
|
+
{
|
|
52
|
+
icon: "⏳",
|
|
53
|
+
num: "2",
|
|
54
|
+
pr_url: "https://github.com/magus/git-multi-diff-playground/pull/47",
|
|
55
|
+
},
|
|
56
|
+
],
|
|
57
|
+
[
|
|
58
|
+
"https://github.com/magus/git-multi-diff-playground/pull/43",
|
|
59
|
+
{
|
|
60
|
+
icon: "👉",
|
|
61
|
+
num: "1",
|
|
62
|
+
pr_url: "https://github.com/magus/git-multi-diff-playground/pull/43",
|
|
63
|
+
},
|
|
64
|
+
],
|
|
65
|
+
]);
|
|
66
|
+
});
|
|
67
|
+
test("persists removed pr urls from previous stack table", () => {
|
|
68
|
+
const args = {
|
|
69
|
+
body: [
|
|
70
|
+
"Summary of problem",
|
|
71
|
+
"",
|
|
72
|
+
"#### git stack",
|
|
73
|
+
"- 👉 `3` https://github.com/magus/git-multi-diff-playground/pull/47",
|
|
74
|
+
"- ⏳ `2` https://github.com/magus/git-multi-diff-playground/pull/44",
|
|
75
|
+
"- ⏳ `1` https://github.com/magus/git-multi-diff-playground/pull/43",
|
|
76
|
+
].join("\n"),
|
|
77
|
+
pr_url_list: [
|
|
78
|
+
"https://github.com/magus/git-multi-diff-playground/pull/47",
|
|
79
|
+
"https://github.com/magus/git-multi-diff-playground/pull/54",
|
|
80
|
+
"https://github.com/magus/git-multi-diff-playground/pull/61",
|
|
81
|
+
],
|
|
82
|
+
selected_url: "https://github.com/magus/git-multi-diff-playground/pull/47",
|
|
83
|
+
};
|
|
84
|
+
const output = StackSummaryTable.write(args);
|
|
85
|
+
expect(output.split("\n")).toEqual([
|
|
86
|
+
"Summary of problem",
|
|
87
|
+
"",
|
|
88
|
+
"#### git stack",
|
|
89
|
+
"- ⏳ `5` https://github.com/magus/git-multi-diff-playground/pull/61",
|
|
90
|
+
"- ⏳ `4` https://github.com/magus/git-multi-diff-playground/pull/54",
|
|
91
|
+
"- 👉 `3` https://github.com/magus/git-multi-diff-playground/pull/47",
|
|
92
|
+
"- ✅ `2` https://github.com/magus/git-multi-diff-playground/pull/44",
|
|
93
|
+
"- ✅ `1` https://github.com/magus/git-multi-diff-playground/pull/43",
|
|
94
|
+
]);
|
|
95
|
+
// run again on the output to make sure it doesn't change
|
|
96
|
+
const rerun_output = StackSummaryTable.write({ ...args, body: output });
|
|
97
|
+
expect(rerun_output).toBe(output);
|
|
98
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "git-stack-cli",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.6",
|
|
4
4
|
"description": "",
|
|
5
5
|
"author": "magus",
|
|
6
6
|
"license": "MIT",
|
|
@@ -23,8 +23,10 @@
|
|
|
23
23
|
"lint": "npm run lint:check -- --fix",
|
|
24
24
|
"prettier:check": "prettier ./src --check",
|
|
25
25
|
"prettier": "npm run prettier:check -- --write",
|
|
26
|
-
"test": "
|
|
27
|
-
"
|
|
26
|
+
"test": "bun test src",
|
|
27
|
+
"test:watch": "npm run test -- --watch",
|
|
28
|
+
"test:all": "npm run prettier:check && npm run lint:check && npm run build",
|
|
29
|
+
"prepublishOnly": "npm run test:all"
|
|
28
30
|
},
|
|
29
31
|
"dependencies": {
|
|
30
32
|
"chalk": "^5.3.0",
|
|
@@ -42,6 +44,7 @@
|
|
|
42
44
|
"@types/yargs": "^17.0.29",
|
|
43
45
|
"@typescript-eslint/eslint-plugin": "^6.9.0",
|
|
44
46
|
"@typescript-eslint/parser": "^6.9.0",
|
|
47
|
+
"bun-types": "^1.0.21",
|
|
45
48
|
"eslint": "^8.52.0",
|
|
46
49
|
"eslint-import-resolver-typescript": "^3.6.1",
|
|
47
50
|
"eslint-plugin-import": "^2.29.0",
|