@aaronshaf/ger 1.2.11 → 2.0.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/.ast-grep/rules/no-as-casting.yml +13 -0
- package/.claude-plugin/plugin.json +22 -0
- package/.github/workflows/ci-simple.yml +53 -0
- package/.github/workflows/ci.yml +171 -0
- package/.github/workflows/claude-code-review.yml +83 -0
- package/.github/workflows/claude.yml +50 -0
- package/.github/workflows/dependency-update.yml +84 -0
- package/.github/workflows/release.yml +166 -0
- package/.github/workflows/security-scan.yml +113 -0
- package/.github/workflows/security.yml +96 -0
- package/.husky/pre-commit +16 -0
- package/.husky/pre-push +25 -0
- package/.lintstagedrc.json +6 -0
- package/.tool-versions +1 -0
- package/CLAUDE.md +105 -0
- package/DEVELOPMENT.md +361 -0
- package/EXAMPLES.md +457 -0
- package/README.md +831 -16
- package/bin/ger +3 -18
- package/biome.json +36 -0
- package/bun.lock +678 -0
- package/bunfig.toml +8 -0
- package/docs/adr/0001-use-effect-for-side-effects.md +65 -0
- package/docs/adr/0002-use-bun-runtime.md +64 -0
- package/docs/adr/0003-store-credentials-in-home-directory.md +75 -0
- package/docs/adr/0004-use-commander-for-cli.md +76 -0
- package/docs/adr/0005-use-effect-schema-for-validation.md +93 -0
- package/docs/adr/0006-use-msw-for-api-mocking.md +89 -0
- package/docs/adr/0007-git-hooks-for-quality.md +94 -0
- package/docs/adr/0008-no-as-typecasting.md +83 -0
- package/docs/adr/0009-file-size-limits.md +82 -0
- package/docs/adr/0010-llm-friendly-xml-output.md +93 -0
- package/docs/adr/0011-ai-tool-strategy-pattern.md +102 -0
- package/docs/adr/0012-build-status-message-parsing.md +94 -0
- package/docs/adr/0013-git-subprocess-integration.md +98 -0
- package/docs/adr/0014-group-management-support.md +95 -0
- package/docs/adr/0015-batch-comment-processing.md +111 -0
- package/docs/adr/0016-flexible-change-identifiers.md +94 -0
- package/docs/adr/0017-git-worktree-support.md +102 -0
- package/docs/adr/0018-auto-install-commit-hook.md +103 -0
- package/docs/adr/0019-sdk-package-exports.md +95 -0
- package/docs/adr/0020-code-coverage-enforcement.md +105 -0
- package/docs/adr/0021-typescript-isolated-declarations.md +83 -0
- package/docs/adr/0022-biome-oxlint-tooling.md +124 -0
- package/docs/adr/README.md +30 -0
- package/docs/prd/README.md +12 -0
- package/docs/prd/architecture.md +325 -0
- package/docs/prd/commands.md +425 -0
- package/docs/prd/data-model.md +349 -0
- package/docs/prd/overview.md +124 -0
- package/index.ts +219 -0
- package/oxlint.json +24 -0
- package/package.json +82 -15
- package/scripts/check-coverage.ts +69 -0
- package/scripts/check-file-size.ts +38 -0
- package/scripts/fix-test-mocks.ts +55 -0
- package/skills/gerrit-workflow/SKILL.md +247 -0
- package/skills/gerrit-workflow/examples.md +572 -0
- package/skills/gerrit-workflow/reference.md +728 -0
- package/src/api/gerrit.ts +696 -0
- package/src/cli/commands/abandon.ts +65 -0
- package/src/cli/commands/add-reviewer.ts +156 -0
- package/src/cli/commands/build-status.ts +282 -0
- package/src/cli/commands/checkout.ts +422 -0
- package/src/cli/commands/comment.ts +460 -0
- package/src/cli/commands/comments.ts +85 -0
- package/src/cli/commands/diff.ts +71 -0
- package/src/cli/commands/extract-url.ts +266 -0
- package/src/cli/commands/groups-members.ts +104 -0
- package/src/cli/commands/groups-show.ts +169 -0
- package/src/cli/commands/groups.ts +137 -0
- package/src/cli/commands/incoming.ts +226 -0
- package/src/cli/commands/init.ts +164 -0
- package/src/cli/commands/mine.ts +115 -0
- package/src/cli/commands/open.ts +57 -0
- package/src/cli/commands/projects.ts +68 -0
- package/src/cli/commands/push.ts +430 -0
- package/src/cli/commands/rebase.ts +52 -0
- package/src/cli/commands/remove-reviewer.ts +123 -0
- package/src/cli/commands/restore.ts +50 -0
- package/src/cli/commands/review.ts +486 -0
- package/src/cli/commands/search.ts +162 -0
- package/src/cli/commands/setup.ts +286 -0
- package/src/cli/commands/show.ts +491 -0
- package/src/cli/commands/status.ts +35 -0
- package/src/cli/commands/submit.ts +108 -0
- package/src/cli/commands/vote.ts +119 -0
- package/src/cli/commands/workspace.ts +200 -0
- package/src/cli/index.ts +53 -0
- package/src/cli/register-commands.ts +659 -0
- package/src/cli/register-group-commands.ts +88 -0
- package/src/cli/register-reviewer-commands.ts +97 -0
- package/src/prompts/default-review.md +86 -0
- package/src/prompts/system-inline-review.md +135 -0
- package/src/prompts/system-overall-review.md +206 -0
- package/src/schemas/config.test.ts +245 -0
- package/src/schemas/config.ts +84 -0
- package/src/schemas/gerrit.ts +681 -0
- package/src/services/commit-hook.ts +314 -0
- package/src/services/config.test.ts +150 -0
- package/src/services/config.ts +250 -0
- package/src/services/git-worktree.ts +342 -0
- package/src/services/review-strategy.ts +292 -0
- package/src/test-utils/mock-generator.ts +138 -0
- package/src/utils/change-id.test.ts +98 -0
- package/src/utils/change-id.ts +63 -0
- package/src/utils/comment-formatters.ts +153 -0
- package/src/utils/diff-context.ts +103 -0
- package/src/utils/diff-formatters.ts +141 -0
- package/src/utils/formatters.ts +85 -0
- package/src/utils/git-commit.test.ts +277 -0
- package/src/utils/git-commit.ts +122 -0
- package/src/utils/index.ts +55 -0
- package/src/utils/message-filters.ts +26 -0
- package/src/utils/review-formatters.ts +89 -0
- package/src/utils/review-prompt-builder.ts +110 -0
- package/src/utils/shell-safety.ts +117 -0
- package/src/utils/status-indicators.ts +100 -0
- package/src/utils/url-parser.test.ts +271 -0
- package/src/utils/url-parser.ts +118 -0
- package/tests/abandon.test.ts +230 -0
- package/tests/add-reviewer.test.ts +579 -0
- package/tests/build-status-watch.test.ts +344 -0
- package/tests/build-status.test.ts +789 -0
- package/tests/change-id-formats.test.ts +268 -0
- package/tests/checkout/integration.test.ts +653 -0
- package/tests/checkout/parse-input.test.ts +55 -0
- package/tests/checkout/validation.test.ts +178 -0
- package/tests/comment-batch-advanced.test.ts +431 -0
- package/tests/comment-gerrit-api-compliance.test.ts +414 -0
- package/tests/comment.test.ts +708 -0
- package/tests/comments.test.ts +323 -0
- package/tests/config-service-simple.test.ts +100 -0
- package/tests/diff.test.ts +419 -0
- package/tests/extract-url.test.ts +517 -0
- package/tests/groups-members.test.ts +256 -0
- package/tests/groups-show.test.ts +323 -0
- package/tests/groups.test.ts +334 -0
- package/tests/helpers/build-status-test-setup.ts +83 -0
- package/tests/helpers/config-mock.ts +27 -0
- package/tests/incoming.test.ts +357 -0
- package/tests/init.test.ts +70 -0
- package/tests/integration/commit-hook.test.ts +246 -0
- package/tests/interactive-incoming.test.ts +173 -0
- package/tests/mine.test.ts +285 -0
- package/tests/mocks/msw-handlers.ts +80 -0
- package/tests/open.test.ts +233 -0
- package/tests/projects.test.ts +259 -0
- package/tests/rebase.test.ts +271 -0
- package/tests/remove-reviewer.test.ts +357 -0
- package/tests/restore.test.ts +237 -0
- package/tests/review.test.ts +135 -0
- package/tests/search.test.ts +712 -0
- package/tests/setup.test.ts +63 -0
- package/tests/show-auto-detect.test.ts +324 -0
- package/tests/show.test.ts +813 -0
- package/tests/status.test.ts +145 -0
- package/tests/submit.test.ts +316 -0
- package/tests/unit/commands/push.test.ts +194 -0
- package/tests/unit/git-branch-detection.test.ts +82 -0
- package/tests/unit/git-worktree.test.ts +55 -0
- package/tests/unit/patterns/push-patterns.test.ts +148 -0
- package/tests/unit/schemas/gerrit.test.ts +85 -0
- package/tests/unit/services/commit-hook.test.ts +132 -0
- package/tests/unit/services/review-strategy.test.ts +349 -0
- package/tests/unit/test-utils/mock-generator.test.ts +154 -0
- package/tests/unit/utils/comment-formatters.test.ts +415 -0
- package/tests/unit/utils/diff-context.test.ts +171 -0
- package/tests/unit/utils/diff-formatters.test.ts +165 -0
- package/tests/unit/utils/formatters.test.ts +411 -0
- package/tests/unit/utils/message-filters.test.ts +227 -0
- package/tests/unit/utils/shell-safety.test.ts +230 -0
- package/tests/unit/utils/status-indicators.test.ts +137 -0
- package/tests/vote.test.ts +317 -0
- package/tests/workspace.test.ts +295 -0
- package/tsconfig.json +36 -5
- package/src/commands/branch.ts +0 -196
- package/src/ger.ts +0 -22
- package/src/types.d.ts +0 -35
- package/src/utils.ts +0 -130
package/src/commands/branch.ts
DELETED
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
import { execSync } from "child_process";
|
|
2
|
-
import { createInterface } from "readline";
|
|
3
|
-
import {
|
|
4
|
-
abbreviateApproverDescription,
|
|
5
|
-
bold,
|
|
6
|
-
darkBrown,
|
|
7
|
-
getGerritData,
|
|
8
|
-
getLocalBranchData,
|
|
9
|
-
getLocalBranchNames,
|
|
10
|
-
green,
|
|
11
|
-
grey,
|
|
12
|
-
normalizeApproverName,
|
|
13
|
-
normalizeValue,
|
|
14
|
-
yellow,
|
|
15
|
-
} from "../utils";
|
|
16
|
-
import type {
|
|
17
|
-
LocalBranchDataMap,
|
|
18
|
-
LocalBranchData,
|
|
19
|
-
GerritDataMap,
|
|
20
|
-
} from "../types.d";
|
|
21
|
-
|
|
22
|
-
const Table = require("cli-table3");
|
|
23
|
-
|
|
24
|
-
export function branch({
|
|
25
|
-
v: isVerbose,
|
|
26
|
-
d: shouldPromptForMergedBranchDeletion,
|
|
27
|
-
}: {
|
|
28
|
-
v?: boolean;
|
|
29
|
-
d?: boolean;
|
|
30
|
-
}) {
|
|
31
|
-
const localBranchNameList = getLocalBranchNames();
|
|
32
|
-
const localBranchDataMap = getLocalBranchData(localBranchNameList);
|
|
33
|
-
const changeIds: string[] = Object.values<LocalBranchData>(localBranchDataMap)
|
|
34
|
-
.map((b) => b.changeId)
|
|
35
|
-
.filter(Boolean) as string[];
|
|
36
|
-
const gerritOutputByChangeId = getGerritData(changeIds);
|
|
37
|
-
|
|
38
|
-
const mergedBranches = localBranchNameList.filter((name) => {
|
|
39
|
-
const changeId = localBranchDataMap[name].changeId;
|
|
40
|
-
if (changeId) {
|
|
41
|
-
const gerritData = gerritOutputByChangeId[changeId];
|
|
42
|
-
return (
|
|
43
|
-
gerritData?.status === "MERGED" || gerritData?.status === "ABANDONED"
|
|
44
|
-
);
|
|
45
|
-
}
|
|
46
|
-
return false;
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
output(
|
|
50
|
-
localBranchNameList,
|
|
51
|
-
localBranchDataMap,
|
|
52
|
-
gerritOutputByChangeId,
|
|
53
|
-
Boolean(isVerbose)
|
|
54
|
-
);
|
|
55
|
-
|
|
56
|
-
if (shouldPromptForMergedBranchDeletion) {
|
|
57
|
-
promptForMergedBranchDeletion(mergedBranches);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
function output(
|
|
62
|
-
localBranchNameList: string[],
|
|
63
|
-
localBranchDataMap: LocalBranchDataMap,
|
|
64
|
-
gerritOutputMap: GerritDataMap,
|
|
65
|
-
isVerbose: boolean
|
|
66
|
-
) {
|
|
67
|
-
const tableOptions = {
|
|
68
|
-
chars: {
|
|
69
|
-
top: "",
|
|
70
|
-
"top-mid": "",
|
|
71
|
-
"top-left": "",
|
|
72
|
-
"top-right": "",
|
|
73
|
-
bottom: "",
|
|
74
|
-
"bottom-mid": "",
|
|
75
|
-
"bottom-left": "",
|
|
76
|
-
"bottom-right": "",
|
|
77
|
-
left: "",
|
|
78
|
-
"left-mid": "",
|
|
79
|
-
mid: isVerbose ? "─" : "",
|
|
80
|
-
"mid-mid": "",
|
|
81
|
-
right: "",
|
|
82
|
-
"right-mid": "",
|
|
83
|
-
middle: " ",
|
|
84
|
-
},
|
|
85
|
-
style: { "padding-left": 0, "padding-right": 0 },
|
|
86
|
-
};
|
|
87
|
-
const table = new Table(tableOptions);
|
|
88
|
-
|
|
89
|
-
for (const localBranch of localBranchNameList) {
|
|
90
|
-
const changeId = localBranchDataMap[localBranch].changeId;
|
|
91
|
-
if (changeId && gerritOutputMap[changeId]) {
|
|
92
|
-
const gerritData = gerritOutputMap[changeId];
|
|
93
|
-
const subject = gerritData.subject;
|
|
94
|
-
const isWip = gerritData.wip || subject.toLowerCase().startsWith("WIP");
|
|
95
|
-
const isMerged = gerritData.status === "MERGED";
|
|
96
|
-
const isAbandoned = gerritData.status === "ABANDONED";
|
|
97
|
-
const labels = [
|
|
98
|
-
isWip && darkBrown("WIP"),
|
|
99
|
-
isAbandoned && grey("Abandoned"),
|
|
100
|
-
isMerged && green("Merged"),
|
|
101
|
-
]
|
|
102
|
-
.filter(Boolean)
|
|
103
|
-
.map((str) => `[${str}]`) as string[];
|
|
104
|
-
|
|
105
|
-
const approvals = (gerritData.currentPatchSet.approvals || []).map(
|
|
106
|
-
(a) => {
|
|
107
|
-
let description = a.description;
|
|
108
|
-
if (a.type === "SUBM" && !description) {
|
|
109
|
-
description = "Submitted";
|
|
110
|
-
}
|
|
111
|
-
return isVerbose
|
|
112
|
-
? `${description || a.type}: ${normalizeValue(
|
|
113
|
-
a.value
|
|
114
|
-
)} (${normalizeApproverName(a.by.name)})`
|
|
115
|
-
: `${abbreviateApproverDescription(
|
|
116
|
-
description || a.type
|
|
117
|
-
)}${normalizeValue(a.value)}`;
|
|
118
|
-
}
|
|
119
|
-
);
|
|
120
|
-
|
|
121
|
-
const approvalText = approvals.join(isVerbose ? "\n" : ", ");
|
|
122
|
-
|
|
123
|
-
const topicText = gerritData.topic
|
|
124
|
-
? ` ${grey(`(${gerritData.topic})`)}`
|
|
125
|
-
: "";
|
|
126
|
-
|
|
127
|
-
if (isVerbose) {
|
|
128
|
-
table.push([
|
|
129
|
-
`${bold(localBranch)}${topicText}\n${
|
|
130
|
-
localBranchDataMap[localBranch].shortHash
|
|
131
|
-
}`,
|
|
132
|
-
`${labels.join("\n")}`,
|
|
133
|
-
`${subject}\n${yellow(gerritData.url.replace("https://", ""))}`,
|
|
134
|
-
approvalText,
|
|
135
|
-
]);
|
|
136
|
-
} else {
|
|
137
|
-
table.push([
|
|
138
|
-
localBranch,
|
|
139
|
-
labels.join(" "),
|
|
140
|
-
yellow(String(gerritData.number)),
|
|
141
|
-
subject,
|
|
142
|
-
approvalText,
|
|
143
|
-
]);
|
|
144
|
-
}
|
|
145
|
-
} else {
|
|
146
|
-
if (isVerbose) {
|
|
147
|
-
table.push([
|
|
148
|
-
`${bold(localBranch)}\n${localBranchDataMap[localBranch].shortHash}`,
|
|
149
|
-
"",
|
|
150
|
-
localBranchDataMap[localBranch].subject,
|
|
151
|
-
"",
|
|
152
|
-
]);
|
|
153
|
-
} else {
|
|
154
|
-
table.push([
|
|
155
|
-
localBranch,
|
|
156
|
-
"",
|
|
157
|
-
"",
|
|
158
|
-
localBranchDataMap[localBranch].subject,
|
|
159
|
-
"",
|
|
160
|
-
]);
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
console.log(table.toString());
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
async function promptForMergedBranchDeletion(mergedBranches: string[]) {
|
|
168
|
-
const readline = createInterface({
|
|
169
|
-
input: process.stdin,
|
|
170
|
-
output: process.stdout,
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
if (mergedBranches.length > 0) {
|
|
174
|
-
console.log('')
|
|
175
|
-
console.log(
|
|
176
|
-
`The following ${bold(String(mergedBranches.length))} local branches are merged or abandoned:`
|
|
177
|
-
);
|
|
178
|
-
for (const mergedLocalBranch of mergedBranches) {
|
|
179
|
-
console.log(` ${bold(mergedLocalBranch)}`);
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
for (const mergedLocalBranch of mergedBranches) {
|
|
184
|
-
const answer: string = await new Promise((resolve) => {
|
|
185
|
-
readline.question(
|
|
186
|
-
`Delete local branch ${bold(mergedLocalBranch)}? (y/n) `,
|
|
187
|
-
resolve
|
|
188
|
-
);
|
|
189
|
-
});
|
|
190
|
-
if (answer.toLowerCase() === "y") {
|
|
191
|
-
execSync(`git branch -D ${mergedLocalBranch}`);
|
|
192
|
-
console.log(` Deleted ${bold(mergedLocalBranch)}`);
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
process.exit(0);
|
|
196
|
-
}
|
package/src/ger.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env ts-node
|
|
2
|
-
|
|
3
|
-
import { Command } from '@commander-js/extra-typings';
|
|
4
|
-
import { branch } from "./commands/branch";
|
|
5
|
-
|
|
6
|
-
const version = require("../package.json").version;
|
|
7
|
-
|
|
8
|
-
const program = new Command();
|
|
9
|
-
program.name("ger").description("Gerrit CLI").version(version);
|
|
10
|
-
|
|
11
|
-
program
|
|
12
|
-
.command("branch")
|
|
13
|
-
.description("Get a list of local branches with Gerrit info")
|
|
14
|
-
.option("-v", "Show extra information, i.e. approvals")
|
|
15
|
-
.option("-d", "Prompt to delete already-merged branches")
|
|
16
|
-
.action((
|
|
17
|
-
_program: any,
|
|
18
|
-
) => {
|
|
19
|
-
branch(_program);
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
program.parse();
|
package/src/types.d.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
export type LocalBranchData = {
|
|
2
|
-
changeId: string | null;
|
|
3
|
-
shortHash: string
|
|
4
|
-
subject: string;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export type LocalBranchDataMap = {
|
|
8
|
-
[branchName: string]: LocalBranchData;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export type GerritApproval = {
|
|
12
|
-
type: 'SUBM';
|
|
13
|
-
description: string;
|
|
14
|
-
value: string;
|
|
15
|
-
by: {
|
|
16
|
-
name: string;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export type GerritData = {
|
|
21
|
-
currentPatchSet: {
|
|
22
|
-
approvals?: GerritApproval[]
|
|
23
|
-
}
|
|
24
|
-
id: string;
|
|
25
|
-
status: 'MERGED' | 'ABANDONED';
|
|
26
|
-
subject: string;
|
|
27
|
-
topic?: string;
|
|
28
|
-
url: string;
|
|
29
|
-
wip: boolean;
|
|
30
|
-
number: number
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export type GerritDataMap = {
|
|
34
|
-
[changeId: string]: GerritData;
|
|
35
|
-
}
|
package/src/utils.ts
DELETED
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
import { execSync } from "child_process";
|
|
2
|
-
import {
|
|
3
|
-
GerritData,
|
|
4
|
-
GerritDataMap,
|
|
5
|
-
LocalBranchData,
|
|
6
|
-
LocalBranchDataMap,
|
|
7
|
-
} from "./types.d";
|
|
8
|
-
|
|
9
|
-
type Row = string[];
|
|
10
|
-
|
|
11
|
-
export function bold(text: string) {
|
|
12
|
-
return `\x1b[1m${text}\x1b[0m`;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function grey(text: string) {
|
|
16
|
-
return `\x1b[90m${text}\x1b[0m`;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function darkBrown(text: string) {
|
|
20
|
-
// return `\x1b[43m\x1b[30m${text}\x1b[0m`;
|
|
21
|
-
return `\x1b[33m${text}\x1b[0m`;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export function green(text: string) {
|
|
25
|
-
return `\x1b[32m${text}\x1b[0m`;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export function yellow(text: string) {
|
|
29
|
-
// return `\x1b[33m\x1b[40m${text}\x1b[0m`;
|
|
30
|
-
return `\x1b[33m${text}\x1b[0m`;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export function getChangeIdFromCommitMessage(message: string) {
|
|
34
|
-
// Extract the Change-Id
|
|
35
|
-
const regex = /Change-Id: .{41}/;
|
|
36
|
-
const change_id_match = message.match(regex);
|
|
37
|
-
|
|
38
|
-
if (change_id_match) {
|
|
39
|
-
const change_id = change_id_match[0].substring(11);
|
|
40
|
-
return change_id;
|
|
41
|
-
}
|
|
42
|
-
return null;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export function getLocalBranchNames(): string[] {
|
|
46
|
-
// Extract local branch names
|
|
47
|
-
const stdout = execSync(
|
|
48
|
-
`git for-each-ref --sort=committerdate refs/heads/ --format='%(refname:lstrip=2)' | grep -v '^master$'`
|
|
49
|
-
);
|
|
50
|
-
return stdout.toString().trim().split("\n");
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export function getGerritData(changeIds: string[]) {
|
|
54
|
-
const query = changeIds.map((cid) => `change:${cid}`).join(" OR ");
|
|
55
|
-
|
|
56
|
-
// if query is empty
|
|
57
|
-
if (!query) {
|
|
58
|
-
console.log("No change IDs found");
|
|
59
|
-
process.exit(0);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// Run the gerrit query command
|
|
63
|
-
const gerritData = execSync(
|
|
64
|
-
`ssh gerrit "gerrit query --current-patch-set --format=JSON '${query}'"`
|
|
65
|
-
)
|
|
66
|
-
.toString()
|
|
67
|
-
.trim()
|
|
68
|
-
.split("\n")
|
|
69
|
-
.map((line) => JSON.parse(line) as GerritData);
|
|
70
|
-
|
|
71
|
-
return gerritData.reduce<GerritDataMap>((acc, change) => {
|
|
72
|
-
return {
|
|
73
|
-
...acc,
|
|
74
|
-
[change.id]: change,
|
|
75
|
-
};
|
|
76
|
-
}, {});
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export function getLocalBranchData(branchNames: string[]) {
|
|
80
|
-
return branchNames.reduce<LocalBranchDataMap>((acc, branchName) => {
|
|
81
|
-
// Get the latest commit SHA and message
|
|
82
|
-
const gitLogOutput = execSync(`git log -1 --pretty=format:%h%n%B ${branchName}`)
|
|
83
|
-
.toString()
|
|
84
|
-
.trim();
|
|
85
|
-
|
|
86
|
-
// Split the output into commit SHA and message
|
|
87
|
-
const [shortHash, ...commitMessageLines] = gitLogOutput.split("\n");
|
|
88
|
-
|
|
89
|
-
const localBranchData: LocalBranchData = {
|
|
90
|
-
changeId: getChangeIdFromCommitMessage(commitMessageLines.join("\n")) || null,
|
|
91
|
-
subject: commitMessageLines[0],
|
|
92
|
-
shortHash,
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
return {
|
|
96
|
-
...acc,
|
|
97
|
-
[branchName]: localBranchData,
|
|
98
|
-
};
|
|
99
|
-
}, {});
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
export const normalizeValue = (value: string) => {
|
|
103
|
-
if (value === "1" || value === "2") {
|
|
104
|
-
return `+${value}`;
|
|
105
|
-
}
|
|
106
|
-
return value;
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
export function normalizeApproverName(name: string) {
|
|
110
|
-
return name
|
|
111
|
-
.replace(" (Bot)", "")
|
|
112
|
-
.replace("Service Cloud Jenkins", "Jenkins")
|
|
113
|
-
.replace("Larry Gergich", "Gergich");
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
export function abbreviateApproverDescription(name: string) {
|
|
117
|
-
if (name === "Lint-Review") {
|
|
118
|
-
return `Lint `;
|
|
119
|
-
}
|
|
120
|
-
if (name === "Code-Review") {
|
|
121
|
-
return `CR `;
|
|
122
|
-
}
|
|
123
|
-
if (name === "Product-Review") {
|
|
124
|
-
return `PR `;
|
|
125
|
-
}
|
|
126
|
-
if (name === "QA-Review") {
|
|
127
|
-
return `QA `;
|
|
128
|
-
}
|
|
129
|
-
return `${name} `;
|
|
130
|
-
}
|