@aaronshaf/ger 1.2.2 → 1.2.4

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 CHANGED
@@ -1,3 +1,9 @@
1
+ ## Install
2
+
3
+ ```bash
4
+ npm i -g @aaronshaf/ger
5
+ ```
6
+
1
7
  ## Usage
2
8
 
3
9
  ```bash
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aaronshaf/ger",
3
- "version": "1.2.2",
3
+ "version": "1.2.4",
4
4
  "description": "Gerrit CLI",
5
5
  "main": "src/ger.ts",
6
6
  "bin": {
@@ -21,7 +21,7 @@
21
21
  "homepage": "https://github.com/aaronshaf/ger#readme",
22
22
  "devDependencies": {
23
23
  "@commander-js/extra-typings": "^10.0.3",
24
- "@types/node": "^18.16.0",
24
+ "@types/node": "^18.16.1",
25
25
  "cli-table3": "^0.6.3",
26
26
  "eslint": "^8.39.0",
27
27
  "ts-node": "^10.9.1",
@@ -1,6 +1,7 @@
1
1
  import { execSync } from "child_process";
2
2
  import { createInterface } from "readline";
3
3
  import {
4
+ abbreviateApproverDescription,
4
5
  bold,
5
6
  darkBrown,
6
7
  getGerritData,
@@ -8,6 +9,7 @@ import {
8
9
  getLocalBranchNames,
9
10
  green,
10
11
  grey,
12
+ normalizeApproverName,
11
13
  normalizeValue,
12
14
  yellow,
13
15
  } from "../utils";
@@ -16,7 +18,6 @@ import type {
16
18
  LocalBranchData,
17
19
  GerritDataMap,
18
20
  } from "../types.d";
19
- import { isDataView } from "util/types";
20
21
 
21
22
  const Table = require("cli-table3");
22
23
 
@@ -95,7 +96,9 @@ function output(
95
96
  isWip && darkBrown("WIP"),
96
97
  isAbandoned && grey("Abandoned"),
97
98
  isMerged && green("Merged"),
98
- ].filter(Boolean) as string[];
99
+ ]
100
+ .filter(Boolean)
101
+ .map((str) => `[${str}]`) as string[];
99
102
 
100
103
  const approvals = gerritData.currentPatchSet.approvals.map((a) => {
101
104
  let description = a.description;
@@ -103,20 +106,21 @@ function output(
103
106
  description = "Submitted";
104
107
  }
105
108
  return isVerbose
106
- ? `${description || a.type}: ${normalizeValue(a.value)} (${a.by.name
107
- .replace(" (Bot)", "")
108
- .replace("Service Cloud Jenkins", "Jenkins")
109
- .replace("Larry Gergich", "Gergich")})`
110
- : normalizeValue(a.value);
109
+ ? `${description || a.type}: ${normalizeValue(
110
+ a.value
111
+ )} (${normalizeApproverName(a.by.name)})`
112
+ : `${abbreviateApproverDescription(
113
+ description || a.type
114
+ )}${normalizeValue(a.value)}`;
111
115
  });
112
116
 
113
117
  const approvalText = approvals.join(isVerbose ? "\n" : ", ");
114
118
 
115
119
  if (isVerbose) {
116
120
  table.push([
117
- `${localBranch}\n${yellow(gerritData.url.replace("https://", ""))}`,
121
+ `${bold(localBranch)}\n${localBranchDataMap[localBranch].shortHash}`,
118
122
  labels.join(" "),
119
- subject,
123
+ `${subject}\n${yellow(gerritData.url.replace("https://", ""))}`,
120
124
  approvalText,
121
125
  ]);
122
126
  } else {
@@ -129,13 +133,22 @@ function output(
129
133
  ]);
130
134
  }
131
135
  } else {
132
- // table.push([
133
- // localBranch,
134
- // "",
135
- // "",
136
- // localBranchDataMap[localBranch].subject,
137
- // "",
138
- // ]);
136
+ if (isVerbose) {
137
+ table.push([
138
+ `${bold(localBranch)}\n${localBranchDataMap[localBranch].shortHash}`,
139
+ "",
140
+ localBranchDataMap[localBranch].subject,
141
+ "",
142
+ ]);
143
+ } else {
144
+ table.push([
145
+ localBranch,
146
+ "",
147
+ "",
148
+ localBranchDataMap[localBranch].subject,
149
+ "",
150
+ ]);
151
+ }
139
152
  }
140
153
  }
141
154
  console.log(table.toString());
package/src/types.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export type LocalBranchData = {
2
2
  changeId: string | null;
3
+ shortHash: string
3
4
  subject: string;
4
5
  }
5
6
 
package/src/utils.ts CHANGED
@@ -17,8 +17,10 @@ export function grey(text: string) {
17
17
  return `\x1b[47m\x1b[30m${text}\x1b[0m`;
18
18
  }
19
19
 
20
+ // brown with transparent background
20
21
  export function darkBrown(text: string) {
21
- return `\x1b[43m\x1b[30m${text}\x1b[0m`;
22
+ // return `\x1b[43m\x1b[30m${text}\x1b[0m`;
23
+ return `\x1b[33m${text}\x1b[0m`;
22
24
  }
23
25
 
24
26
  export function green(text: string) {
@@ -27,7 +29,8 @@ export function green(text: string) {
27
29
 
28
30
  // yellow text with transparent background
29
31
  export function yellow(text: string) {
30
- return `\x1b[33m\x1b[40m${text}\x1b[0m`;
32
+ // return `\x1b[33m\x1b[40m${text}\x1b[0m`;
33
+ return `\x1b[33m${text}\x1b[0m`;
31
34
  }
32
35
 
33
36
  export function getChangeIdFromCommitMessage(message: string) {
@@ -78,17 +81,18 @@ export function getGerritData(changeIds: string[]) {
78
81
 
79
82
  export function getLocalBranchData(branchNames: string[]) {
80
83
  return branchNames.reduce<LocalBranchDataMap>((acc, branchName) => {
81
- // Get the latest commit message
82
- const commit_message = execSync(`git log -1 --pretty=%B ${branchName}`)
84
+ // Get the latest commit SHA and message
85
+ const gitLogOutput = execSync(`git log -1 --pretty=format:%h%n%B ${branchName}`)
83
86
  .toString()
84
87
  .trim();
85
88
 
86
- // Get first line of commit message
87
- const firstLine = commit_message.split("\n")[0];
89
+ // Split the output into commit SHA and message
90
+ const [shortHash, ...commitMessageLines] = gitLogOutput.split("\n");
88
91
 
89
92
  const localBranchData: LocalBranchData = {
90
- changeId: getChangeIdFromCommitMessage(commit_message) || null,
91
- subject: firstLine,
93
+ changeId: getChangeIdFromCommitMessage(commitMessageLines.join("\n")) || null,
94
+ subject: commitMessageLines[0],
95
+ shortHash,
92
96
  };
93
97
 
94
98
  return {
@@ -103,4 +107,27 @@ export const normalizeValue = (value: string) => {
103
107
  return `+${value}`;
104
108
  }
105
109
  return value;
106
- };
110
+ };
111
+
112
+ export function normalizeApproverName(name: string) {
113
+ return name
114
+ .replace(" (Bot)", "")
115
+ .replace("Service Cloud Jenkins", "Jenkins")
116
+ .replace("Larry Gergich", "Gergich");
117
+ }
118
+
119
+ export function abbreviateApproverDescription(name: string) {
120
+ if (name === "Lint-Review") {
121
+ return `Lint `;
122
+ }
123
+ if (name === "Code-Review") {
124
+ return `CR `;
125
+ }
126
+ if (name === "Product-Review") {
127
+ return `PR `;
128
+ }
129
+ if (name === "QA-Review") {
130
+ return `QA `;
131
+ }
132
+ return `${name} `;
133
+ }