@bdsqqq/lnr-cli 1.6.0 โ 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/package.json +2 -3
- package/src/bench-lnr-overhead.ts +160 -0
- package/src/e2e-mutations.test.ts +378 -0
- package/src/e2e-readonly.test.ts +103 -0
- package/src/generated/doc.ts +270 -0
- package/src/generated/issue.ts +807 -0
- package/src/generated/label.ts +273 -0
- package/src/generated/project.ts +596 -0
- package/src/generated/template.ts +157 -0
- package/src/hand-crafted/issue.ts +27 -0
- package/src/lib/adapters/doc.ts +14 -0
- package/src/lib/adapters/index.ts +4 -0
- package/src/lib/adapters/issue.ts +32 -0
- package/src/lib/adapters/label.ts +20 -0
- package/src/lib/adapters/project.ts +23 -0
- package/src/lib/arktype-config.ts +18 -0
- package/src/lib/command-introspection.ts +97 -0
- package/src/lib/dispatch-effects.test.ts +297 -0
- package/src/lib/error.ts +37 -1
- package/src/lib/operation-spec.test.ts +317 -0
- package/src/lib/operation-spec.ts +11 -0
- package/src/lib/operation-specs.ts +21 -0
- package/src/lib/output.test.ts +3 -1
- package/src/lib/output.ts +1 -296
- package/src/lib/renderers/comments.ts +300 -0
- package/src/lib/renderers/detail.ts +61 -0
- package/src/lib/renderers/index.ts +2 -0
- package/src/router/agent-sessions.ts +253 -0
- package/src/router/auth.ts +6 -5
- package/src/router/config.ts +7 -6
- package/src/router/contract.test.ts +364 -0
- package/src/router/cycles.ts +372 -95
- package/src/router/git-automation-states.ts +355 -0
- package/src/router/git-automation-target-branches.ts +309 -0
- package/src/router/index.ts +26 -8
- package/src/router/initiatives.ts +260 -0
- package/src/router/me.ts +8 -7
- package/src/router/notifications.ts +176 -0
- package/src/router/roadmaps.ts +172 -0
- package/src/router/search.ts +7 -6
- package/src/router/teams.ts +82 -24
- package/src/router/users.ts +126 -0
- package/src/router/views.ts +399 -0
- package/src/router/docs.ts +0 -153
- package/src/router/issues.ts +0 -606
- package/src/router/labels.ts +0 -192
- package/src/router/projects.ts +0 -220
package/src/lib/output.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import chalk from "chalk";
|
|
2
|
-
import { getConfigValue
|
|
2
|
+
import { getConfigValue } from "@bdsqqq/lnr-core";
|
|
3
3
|
|
|
4
4
|
export type OutputFormat = "table" | "json" | "quiet";
|
|
5
5
|
|
|
@@ -117,299 +117,4 @@ export function formatRelativeTime(date: Date): string {
|
|
|
117
117
|
return `${diffYears}y ago`;
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
-
export function buildChildMap(comments: Comment[]): Map<string | null, Comment[]> {
|
|
121
|
-
const childMap = new Map<string | null, Comment[]>();
|
|
122
120
|
|
|
123
|
-
for (const c of comments) {
|
|
124
|
-
const parentKey = c.parentId ?? null;
|
|
125
|
-
const existing = childMap.get(parentKey) ?? [];
|
|
126
|
-
existing.push(c);
|
|
127
|
-
childMap.set(parentKey, existing);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
for (const children of Array.from(childMap.values())) {
|
|
131
|
-
children.sort((a, b) => a.createdAt.getTime() - b.createdAt.getTime());
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
return childMap;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
const EMOJI_MAP: Record<string, string> = {
|
|
138
|
-
// gestures
|
|
139
|
-
"+1": "๐", thumbsup: "๐", "-1": "๐", thumbsdown: "๐",
|
|
140
|
-
wave: "๐", raised_back_of_hand: "๐ค", raised_hand: "โ", hand: "โ",
|
|
141
|
-
vulcan_salute: "๐", ok_hand: "๐", pinched_fingers: "๐ค", pinching_hand: "๐ค",
|
|
142
|
-
v: "โ๏ธ", crossed_fingers: "๐ค", love_you_gesture: "๐ค", metal: "๐ค",
|
|
143
|
-
call_me_hand: "๐ค", point_left: "๐", point_right: "๐", point_up_2: "๐",
|
|
144
|
-
point_down: "๐", point_up: "โ๏ธ", fist: "โ", fist_raised: "โ",
|
|
145
|
-
facepunch: "๐", punch: "๐", fist_oncoming: "๐", fist_left: "๐ค", fist_right: "๐ค",
|
|
146
|
-
clap: "๐", raised_hands: "๐", open_hands: "๐", palms_up_together: "๐คฒ",
|
|
147
|
-
handshake: "๐ค", pray: "๐", writing_hand: "โ๏ธ", nail_care: "๐
",
|
|
148
|
-
selfie: "๐คณ", muscle: "๐ช", mechanical_arm: "๐ฆพ",
|
|
149
|
-
eyes: "๐", eye: "๐๏ธ", tongue: "๐
", lips: "๐",
|
|
150
|
-
|
|
151
|
-
// smileys
|
|
152
|
-
grinning: "๐", smile: "๐", grin: "๐", joy: "๐", rofl: "๐คฃ",
|
|
153
|
-
smiley: "๐", sweat_smile: "๐
", laughing: "๐", laugh: "๐",
|
|
154
|
-
wink: "๐", blush: "๐", yum: "๐", sunglasses: "๐", heart_eyes: "๐",
|
|
155
|
-
kissing_heart: "๐", kissing: "๐", relaxed: "โบ๏ธ",
|
|
156
|
-
stuck_out_tongue: "๐", stuck_out_tongue_winking_eye: "๐", stuck_out_tongue_closed_eyes: "๐",
|
|
157
|
-
disappointed: "๐", worried: "๐", angry: "๐ ", rage: "๐ก", pout: "๐ก",
|
|
158
|
-
cry: "๐ข", persevere: "๐ฃ", triumph: "๐ค", disappointed_relieved: "๐ฅ",
|
|
159
|
-
frowning: "๐ฆ", anguished: "๐ง", fearful: "๐จ", weary: "๐ฉ",
|
|
160
|
-
sleepy: "๐ช", tired_face: "๐ซ", grimacing: "๐ฌ", sob: "๐ญ",
|
|
161
|
-
open_mouth: "๐ฎ", hushed: "๐ฏ", cold_sweat: "๐ฐ", scream: "๐ฑ",
|
|
162
|
-
astonished: "๐ฒ", flushed: "๐ณ", sleeping: "๐ด", dizzy_face: "๐ต",
|
|
163
|
-
no_mouth: "๐ถ", mask: "๐ท", neutral_face: "๐", expressionless: "๐",
|
|
164
|
-
unamused: "๐", sweat: "๐", pensive: "๐", confused: "๐", confounded: "๐",
|
|
165
|
-
upside_down_face: "๐", money_mouth_face: "๐ค", thinking_face: "๐ค", thinking: "๐ค",
|
|
166
|
-
zipper_mouth_face: "๐ค", nerd_face: "๐ค", hugs: "๐ค", rolling_eyes: "๐",
|
|
167
|
-
smirk: "๐", drooling_face: "๐คค", lying_face: "๐คฅ",
|
|
168
|
-
face_with_raised_eyebrow: "๐คจ", shushing_face: "๐คซ", face_with_hand_over_mouth: "๐คญ",
|
|
169
|
-
face_vomiting: "๐คฎ", exploding_head: "๐คฏ", cowboy_hat_face: "๐ค ",
|
|
170
|
-
partying_face: "๐ฅณ", disguised_face: "๐ฅธ", pleading_face: "๐ฅบ",
|
|
171
|
-
skull: "๐", skull_and_crossbones: "โ ๏ธ", ghost: "๐ป", alien: "๐ฝ",
|
|
172
|
-
robot: "๐ค", poop: "๐ฉ", hankey: "๐ฉ", clown_face: "๐คก",
|
|
173
|
-
|
|
174
|
-
// hearts
|
|
175
|
-
heart: "โค๏ธ", red_heart: "โค๏ธ", orange_heart: "๐งก", yellow_heart: "๐",
|
|
176
|
-
green_heart: "๐", blue_heart: "๐", purple_heart: "๐", black_heart: "๐ค",
|
|
177
|
-
white_heart: "๐ค", brown_heart: "๐ค", broken_heart: "๐", heart_exclamation: "โฃ๏ธ",
|
|
178
|
-
two_hearts: "๐", revolving_hearts: "๐", heartbeat: "๐", heartpulse: "๐",
|
|
179
|
-
sparkling_heart: "๐", cupid: "๐", gift_heart: "๐", heart_decoration: "๐",
|
|
180
|
-
|
|
181
|
-
// celebration
|
|
182
|
-
tada: "๐", confetti_ball: "๐", balloon: "๐", birthday: "๐", gift: "๐",
|
|
183
|
-
trophy: "๐", medal_military: "๐๏ธ", medal_sports: "๐
",
|
|
184
|
-
first_place_medal: "๐ฅ", second_place_medal: "๐ฅ", third_place_medal: "๐ฅ",
|
|
185
|
-
|
|
186
|
-
// symbols
|
|
187
|
-
fire: "๐ฅ", sparkles: "โจ", star: "โญ", star2: "๐", dizzy: "๐ซ",
|
|
188
|
-
boom: "๐ฅ", collision: "๐ฅ", zap: "โก", lightning: "โก",
|
|
189
|
-
snowflake: "โ๏ธ", cloud: "โ๏ธ", sunny: "โ๏ธ", rainbow: "๐",
|
|
190
|
-
rocket: "๐", airplane: "โ๏ธ", 100: "๐ฏ",
|
|
191
|
-
check: "โ
", white_check_mark: "โ
", ballot_box_with_check: "โ๏ธ", heavy_check_mark: "โ๏ธ",
|
|
192
|
-
x: "โ", cross_mark: "โ", negative_squared_cross_mark: "โ",
|
|
193
|
-
warning: "โ ๏ธ", exclamation: "โ", question: "โ",
|
|
194
|
-
grey_exclamation: "โ", grey_question: "โ", bangbang: "โผ๏ธ", interrobang: "โ๏ธ",
|
|
195
|
-
bulb: "๐ก", memo: "๐", pencil: "โ๏ธ", pencil2: "โ๏ธ", pen: "๐๏ธ",
|
|
196
|
-
lock: "๐", unlock: "๐", key: "๐", bell: "๐", no_bell: "๐",
|
|
197
|
-
bookmark: "๐", link: "๐", paperclip: "๐", pushpin: "๐", scissors: "โ๏ธ",
|
|
198
|
-
file_folder: "๐", open_file_folder: "๐", page_facing_up: "๐", page_with_curl: "๐",
|
|
199
|
-
calendar: "๐
", date: "๐
", clipboard: "๐",
|
|
200
|
-
chart_with_upwards_trend: "๐", chart_with_downwards_trend: "๐", bar_chart: "๐",
|
|
201
|
-
email: "๐ง", envelope: "โ๏ธ", inbox_tray: "๐ฅ", outbox_tray: "๐ค",
|
|
202
|
-
package: "๐ฆ", mailbox: "๐ซ", speech_balloon: "๐ฌ", thought_balloon: "๐ญ",
|
|
203
|
-
mag: "๐", mag_right: "๐", gear: "โ๏ธ", wrench: "๐ง", hammer: "๐จ",
|
|
204
|
-
hammer_and_wrench: "๐ ๏ธ", tools: "๐ ๏ธ", nut_and_bolt: "๐ฉ", shield: "๐ก๏ธ",
|
|
205
|
-
hourglass: "โ", hourglass_flowing_sand: "โณ", watch: "โ", alarm_clock: "โฐ",
|
|
206
|
-
stopwatch: "โฑ๏ธ", timer_clock: "โฒ๏ธ",
|
|
207
|
-
|
|
208
|
-
// animals
|
|
209
|
-
see_no_evil: "๐", hear_no_evil: "๐", speak_no_evil: "๐",
|
|
210
|
-
monkey: "๐", monkey_face: "๐ต", dog: "๐", dog2: "๐", cat: "๐", cat2: "๐",
|
|
211
|
-
tiger: "๐
", tiger2: "๐
", lion: "๐ฆ", horse: "๐ด", unicorn: "๐ฆ",
|
|
212
|
-
cow: "๐", cow2: "๐", pig: "๐ท", pig2: "๐ท", chicken: "๐", penguin: "๐ง",
|
|
213
|
-
bird: "๐ฆ", eagle: "๐ฆ
", duck: "๐ฆ", owl: "๐ฆ", bat: "๐ฆ", wolf: "๐บ",
|
|
214
|
-
fox_face: "๐ฆ", bear: "๐ป", panda_face: "๐ผ", koala: "๐จ",
|
|
215
|
-
rabbit: "๐ฐ", rabbit2: "๐", mouse: "๐ญ", mouse2: "๐", rat: "๐", hamster: "๐น",
|
|
216
|
-
frog: "๐ธ", snake: "๐", turtle: "๐ข", lizard: "๐ฆ", dragon: "๐", dragon_face: "๐ฒ",
|
|
217
|
-
whale: "๐", whale2: "๐", dolphin: "๐ฌ", fish: "๐", tropical_fish: "๐ ",
|
|
218
|
-
blowfish: "๐ก", shark: "๐ฆ", octopus: "๐", crab: "๐ฆ", lobster: "๐ฆ",
|
|
219
|
-
shrimp: "๐ฆ", squid: "๐ฆ", snail: "๐", butterfly: "๐ฆ", bug: "๐",
|
|
220
|
-
ant: "๐", bee: "๐", honeybee: "๐", spider: "๐ท๏ธ", spider_web: "๐ธ๏ธ",
|
|
221
|
-
|
|
222
|
-
// food & drink
|
|
223
|
-
apple: "๐", green_apple: "๐", pear: "๐", tangerine: "๐", orange: "๐",
|
|
224
|
-
lemon: "๐", banana: "๐", watermelon: "๐", grapes: "๐", strawberry: "๐",
|
|
225
|
-
peach: "๐", cherries: "๐", pizza: "๐", hamburger: "๐", fries: "๐",
|
|
226
|
-
hotdog: "๐ญ", sandwich: "๐ฅช", taco: "๐ฎ", burrito: "๐ฏ", egg: "๐ฅ", cooking: "๐ณ",
|
|
227
|
-
cake: "๐ฐ", cookie: "๐ช", chocolate_bar: "๐ซ", candy: "๐ฌ", lollipop: "๐ญ",
|
|
228
|
-
ice_cream: "๐จ", icecream: "๐ฆ", doughnut: "๐ฉ",
|
|
229
|
-
coffee: "โ", tea: "๐ต", beer: "๐บ", beers: "๐ป", wine_glass: "๐ท",
|
|
230
|
-
cocktail: "๐ธ", tropical_drink: "๐น", champagne: "๐พ",
|
|
231
|
-
|
|
232
|
-
// objects
|
|
233
|
-
computer: "๐ป", keyboard: "โจ๏ธ", desktop_computer: "๐ฅ๏ธ", printer: "๐จ๏ธ",
|
|
234
|
-
mouse_three_button: "๐ฑ๏ธ", trackball: "๐ฒ๏ธ", joystick: "๐น๏ธ", video_game: "๐ฎ",
|
|
235
|
-
phone: "๐ฑ", iphone: "๐ฑ", telephone: "โ๏ธ", telephone_receiver: "๐",
|
|
236
|
-
battery: "๐", electric_plug: "๐", camera: "๐ท", camera_flash: "๐ธ",
|
|
237
|
-
video_camera: "๐น", movie_camera: "๐ฅ", film_projector: "๐ฝ๏ธ", tv: "๐บ",
|
|
238
|
-
radio: "๐ป", microphone: "๐ค", headphones: "๐ง", musical_note: "๐ต", notes: "๐ถ",
|
|
239
|
-
art: "๐จ", performing_arts: "๐ญ", tickets: "๐๏ธ", clapper: "๐ฌ",
|
|
240
|
-
books: "๐", book: "๐", notebook: "๐", newspaper: "๐ฐ", scroll: "๐",
|
|
241
|
-
moneybag: "๐ฐ", dollar: "๐ต", credit_card: "๐ณ", gem: "๐", ring: "๐",
|
|
242
|
-
crown: "๐", tophat: "๐ฉ", necktie: "๐", shirt: "๐", jeans: "๐",
|
|
243
|
-
dress: "๐", lipstick: "๐", kiss: "๐", footprints: "๐ฃ",
|
|
244
|
-
|
|
245
|
-
// arrows
|
|
246
|
-
arrow_up: "โฌ๏ธ", arrow_down: "โฌ๏ธ", arrow_left: "โฌ
๏ธ", arrow_right: "โก๏ธ",
|
|
247
|
-
arrow_upper_left: "โ๏ธ", arrow_upper_right: "โ๏ธ", arrow_lower_left: "โ๏ธ", arrow_lower_right: "โ๏ธ",
|
|
248
|
-
left_right_arrow: "โ๏ธ", arrow_up_down: "โ๏ธ",
|
|
249
|
-
arrows_counterclockwise: "๐", arrows_clockwise: "๐",
|
|
250
|
-
rewind: "โช", fast_forward: "โฉ", play_or_pause_button: "โฏ๏ธ",
|
|
251
|
-
pause_button: "โธ๏ธ", stop_button: "โน๏ธ", record_button: "โบ๏ธ",
|
|
252
|
-
|
|
253
|
-
// numbers
|
|
254
|
-
zero: "0๏ธโฃ", one: "1๏ธโฃ", two: "2๏ธโฃ", three: "3๏ธโฃ", four: "4๏ธโฃ",
|
|
255
|
-
five: "5๏ธโฃ", six: "6๏ธโฃ", seven: "7๏ธโฃ", eight: "8๏ธโฃ", nine: "9๏ธโฃ", keycap_ten: "๐",
|
|
256
|
-
};
|
|
257
|
-
|
|
258
|
-
export function shortcodeToEmoji(shortcode: string): string {
|
|
259
|
-
return EMOJI_MAP[shortcode] ?? `:${shortcode}:`;
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
export function formatReactions(reactions: { emoji: string; count: number }[]): string {
|
|
263
|
-
if (reactions.length === 0) return "";
|
|
264
|
-
return reactions.map((r) => {
|
|
265
|
-
const emoji = shortcodeToEmoji(r.emoji);
|
|
266
|
-
return `${emoji}${r.count > 1 ? r.count : ""}`;
|
|
267
|
-
}).join(" ");
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
export function wrapText(text: string, width: number, indent: string): string[] {
|
|
271
|
-
const lines: string[] = [];
|
|
272
|
-
const paragraphs = text.split(/\n/);
|
|
273
|
-
|
|
274
|
-
for (const paragraph of paragraphs) {
|
|
275
|
-
if (paragraph.trim() === "") {
|
|
276
|
-
lines.push("");
|
|
277
|
-
continue;
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
const words = paragraph.split(/\s+/);
|
|
281
|
-
let currentLine = "";
|
|
282
|
-
|
|
283
|
-
for (const word of words) {
|
|
284
|
-
if (currentLine.length + word.length + 1 <= width) {
|
|
285
|
-
currentLine += (currentLine ? " " : "") + word;
|
|
286
|
-
} else {
|
|
287
|
-
if (currentLine) lines.push(indent + currentLine);
|
|
288
|
-
currentLine = word;
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
if (currentLine) lines.push(indent + currentLine);
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
return lines;
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
function getActorName(comment: Comment): string {
|
|
298
|
-
return comment.externalUser ?? comment.user ?? comment.botActor ?? "unknown";
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
function getSourceLabel(comment: Comment): string {
|
|
302
|
-
const sync = comment.syncedWith[0];
|
|
303
|
-
if (!sync) return "";
|
|
304
|
-
const serviceName = sync.service.charAt(0).toUpperCase() + sync.service.slice(1).toLowerCase();
|
|
305
|
-
return ` via ${serviceName}`;
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
function getSyncChannelName(comment: Comment): string | undefined {
|
|
309
|
-
const sync = comment.syncedWith[0];
|
|
310
|
-
if (!sync) return undefined;
|
|
311
|
-
|
|
312
|
-
if (sync.meta.type === "slack") {
|
|
313
|
-
return sync.meta.channelName;
|
|
314
|
-
}
|
|
315
|
-
if (sync.meta.type === "github" && sync.meta.repo) {
|
|
316
|
-
return sync.meta.owner ? `${sync.meta.owner}/${sync.meta.repo}` : sync.meta.repo;
|
|
317
|
-
}
|
|
318
|
-
if (sync.meta.type === "jira" && sync.meta.issueKey) {
|
|
319
|
-
return sync.meta.issueKey;
|
|
320
|
-
}
|
|
321
|
-
return undefined;
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
function formatCommentHeader(
|
|
325
|
-
comment: Comment,
|
|
326
|
-
isThreadRoot: boolean,
|
|
327
|
-
replyCount?: number,
|
|
328
|
-
threadUrl?: string
|
|
329
|
-
): string {
|
|
330
|
-
const sync = comment.syncedWith[0];
|
|
331
|
-
const time = formatRelativeTime(comment.createdAt);
|
|
332
|
-
|
|
333
|
-
if (isThreadRoot && sync) {
|
|
334
|
-
const channelName = getSyncChannelName(comment);
|
|
335
|
-
const channelPart = channelName ? ` in #${chalk.white(channelName)}` : "";
|
|
336
|
-
const serviceName = sync.service.charAt(0).toUpperCase() + sync.service.slice(1).toLowerCase();
|
|
337
|
-
let header = `${chalk.white(serviceName)} thread connected${channelPart} ${chalk.dim(time)}`;
|
|
338
|
-
|
|
339
|
-
if (replyCount && replyCount > 3 && threadUrl) {
|
|
340
|
-
header += `\nโ ${chalk.dim(`${replyCount - 3} previous replies,`)} [view all](${threadUrl})`;
|
|
341
|
-
}
|
|
342
|
-
return header;
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
const actor = chalk.white(`@${getActorName(comment)}`);
|
|
346
|
-
const source = chalk.dim(getSourceLabel(comment));
|
|
347
|
-
return `${actor} ${chalk.dim(time)}${source}`;
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
function outputSingleComment(comment: Comment, indent: string): void {
|
|
351
|
-
const bodyLines = wrapText(comment.body.trim(), 60, indent + "โ ");
|
|
352
|
-
for (const line of bodyLines) {
|
|
353
|
-
console.log(line);
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
const reactions = formatReactions(comment.reactions);
|
|
357
|
-
if (reactions) {
|
|
358
|
-
console.log(`${indent}โ ${chalk.dim(`[${reactions}]`)}`);
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
function renderCommentRecursive(
|
|
363
|
-
comment: Comment,
|
|
364
|
-
childMap: Map<string | null, Comment[]>,
|
|
365
|
-
depth: number,
|
|
366
|
-
maxRepliesPerLevel: number
|
|
367
|
-
): void {
|
|
368
|
-
const indent = " ".repeat(depth);
|
|
369
|
-
const header = formatCommentHeader(comment, false);
|
|
370
|
-
console.log(`${indent}โ ${header}`);
|
|
371
|
-
outputSingleComment(comment, indent + " ");
|
|
372
|
-
|
|
373
|
-
const children = childMap.get(comment.id) ?? [];
|
|
374
|
-
const recentChildren = children.slice(-maxRepliesPerLevel);
|
|
375
|
-
|
|
376
|
-
for (const child of recentChildren) {
|
|
377
|
-
renderCommentRecursive(child, childMap, depth + 1, maxRepliesPerLevel);
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
export function outputCommentThreads(comments: Comment[], maxThreads = 3): void {
|
|
382
|
-
if (comments.length === 0) {
|
|
383
|
-
console.log(chalk.dim("no comments"));
|
|
384
|
-
return;
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
const childMap = buildChildMap(comments);
|
|
388
|
-
const rootComments = childMap.get(null) ?? [];
|
|
389
|
-
const recentRoots = rootComments.slice(-maxThreads);
|
|
390
|
-
|
|
391
|
-
for (let i = 0; i < recentRoots.length; i++) {
|
|
392
|
-
const root = recentRoots[i];
|
|
393
|
-
if (!root) continue;
|
|
394
|
-
|
|
395
|
-
const children = childMap.get(root.id) ?? [];
|
|
396
|
-
const totalReplies = children.length;
|
|
397
|
-
const threadUrl = root.url;
|
|
398
|
-
const hasSync = root.syncedWith.length > 0;
|
|
399
|
-
|
|
400
|
-
console.log(formatCommentHeader(root, true, totalReplies, threadUrl));
|
|
401
|
-
|
|
402
|
-
if (!hasSync) {
|
|
403
|
-
outputSingleComment(root, "");
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
const recentChildren = children.slice(-3);
|
|
407
|
-
for (const child of recentChildren) {
|
|
408
|
-
renderCommentRecursive(child, childMap, 0, 3);
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
if (i < recentRoots.length - 1) {
|
|
412
|
-
console.log();
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
}
|
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
import type { Comment } from "@bdsqqq/lnr-core";
|
|
3
|
+
import { formatRelativeTime } from "../output";
|
|
4
|
+
|
|
5
|
+
export function buildChildMap(comments: Comment[]): Map<string | null, Comment[]> {
|
|
6
|
+
const childMap = new Map<string | null, Comment[]>();
|
|
7
|
+
|
|
8
|
+
for (const c of comments) {
|
|
9
|
+
const parentKey = c.parentId ?? null;
|
|
10
|
+
const existing = childMap.get(parentKey) ?? [];
|
|
11
|
+
existing.push(c);
|
|
12
|
+
childMap.set(parentKey, existing);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
for (const children of Array.from(childMap.values())) {
|
|
16
|
+
children.sort((a, b) => a.createdAt.getTime() - b.createdAt.getTime());
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return childMap;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const EMOJI_MAP: Record<string, string> = {
|
|
23
|
+
// gestures
|
|
24
|
+
"+1": "๐", thumbsup: "๐", "-1": "๐", thumbsdown: "๐",
|
|
25
|
+
wave: "๐", raised_back_of_hand: "๐ค", raised_hand: "โ", hand: "โ",
|
|
26
|
+
vulcan_salute: "๐", ok_hand: "๐", pinched_fingers: "๐ค", pinching_hand: "๐ค",
|
|
27
|
+
v: "โ๏ธ", crossed_fingers: "๐ค", love_you_gesture: "๐ค", metal: "๐ค",
|
|
28
|
+
call_me_hand: "๐ค", point_left: "๐", point_right: "๐", point_up_2: "๐",
|
|
29
|
+
point_down: "๐", point_up: "โ๏ธ", fist: "โ", fist_raised: "โ",
|
|
30
|
+
facepunch: "๐", punch: "๐", fist_oncoming: "๐", fist_left: "๐ค", fist_right: "๐ค",
|
|
31
|
+
clap: "๐", raised_hands: "๐", open_hands: "๐", palms_up_together: "๐คฒ",
|
|
32
|
+
handshake: "๐ค", pray: "๐", writing_hand: "โ๏ธ", nail_care: "๐
",
|
|
33
|
+
selfie: "๐คณ", muscle: "๐ช", mechanical_arm: "๐ฆพ",
|
|
34
|
+
eyes: "๐", eye: "๐๏ธ", tongue: "๐
", lips: "๐",
|
|
35
|
+
|
|
36
|
+
// smileys
|
|
37
|
+
grinning: "๐", smile: "๐", grin: "๐", joy: "๐", rofl: "๐คฃ",
|
|
38
|
+
smiley: "๐", sweat_smile: "๐
", laughing: "๐", laugh: "๐",
|
|
39
|
+
wink: "๐", blush: "๐", yum: "๐", sunglasses: "๐", heart_eyes: "๐",
|
|
40
|
+
kissing_heart: "๐", kissing: "๐", relaxed: "โบ๏ธ",
|
|
41
|
+
stuck_out_tongue: "๐", stuck_out_tongue_winking_eye: "๐", stuck_out_tongue_closed_eyes: "๐",
|
|
42
|
+
disappointed: "๐", worried: "๐", angry: "๐ ", rage: "๐ก", pout: "๐ก",
|
|
43
|
+
cry: "๐ข", persevere: "๐ฃ", triumph: "๐ค", disappointed_relieved: "๐ฅ",
|
|
44
|
+
frowning: "๐ฆ", anguished: "๐ง", fearful: "๐จ", weary: "๐ฉ",
|
|
45
|
+
sleepy: "๐ช", tired_face: "๐ซ", grimacing: "๐ฌ", sob: "๐ญ",
|
|
46
|
+
open_mouth: "๐ฎ", hushed: "๐ฏ", cold_sweat: "๐ฐ", scream: "๐ฑ",
|
|
47
|
+
astonished: "๐ฒ", flushed: "๐ณ", sleeping: "๐ด", dizzy_face: "๐ต",
|
|
48
|
+
no_mouth: "๐ถ", mask: "๐ท", neutral_face: "๐", expressionless: "๐",
|
|
49
|
+
unamused: "๐", sweat: "๐", pensive: "๐", confused: "๐", confounded: "๐",
|
|
50
|
+
upside_down_face: "๐", money_mouth_face: "๐ค", thinking_face: "๐ค", thinking: "๐ค",
|
|
51
|
+
zipper_mouth_face: "๐ค", nerd_face: "๐ค", hugs: "๐ค", rolling_eyes: "๐",
|
|
52
|
+
smirk: "๐", drooling_face: "๐คค", lying_face: "๐คฅ",
|
|
53
|
+
face_with_raised_eyebrow: "๐คจ", shushing_face: "๐คซ", face_with_hand_over_mouth: "๐คญ",
|
|
54
|
+
face_vomiting: "๐คฎ", exploding_head: "๐คฏ", cowboy_hat_face: "๐ค ",
|
|
55
|
+
partying_face: "๐ฅณ", disguised_face: "๐ฅธ", pleading_face: "๐ฅบ",
|
|
56
|
+
skull: "๐", skull_and_crossbones: "โ ๏ธ", ghost: "๐ป", alien: "๐ฝ",
|
|
57
|
+
robot: "๐ค", poop: "๐ฉ", hankey: "๐ฉ", clown_face: "๐คก",
|
|
58
|
+
|
|
59
|
+
// hearts
|
|
60
|
+
heart: "โค๏ธ", red_heart: "โค๏ธ", orange_heart: "๐งก", yellow_heart: "๐",
|
|
61
|
+
green_heart: "๐", blue_heart: "๐", purple_heart: "๐", black_heart: "๐ค",
|
|
62
|
+
white_heart: "๐ค", brown_heart: "๐ค", broken_heart: "๐", heart_exclamation: "โฃ๏ธ",
|
|
63
|
+
two_hearts: "๐", revolving_hearts: "๐", heartbeat: "๐", heartpulse: "๐",
|
|
64
|
+
sparkling_heart: "๐", cupid: "๐", gift_heart: "๐", heart_decoration: "๐",
|
|
65
|
+
|
|
66
|
+
// celebration
|
|
67
|
+
tada: "๐", confetti_ball: "๐", balloon: "๐", birthday: "๐", gift: "๐",
|
|
68
|
+
trophy: "๐", medal_military: "๐๏ธ", medal_sports: "๐
",
|
|
69
|
+
first_place_medal: "๐ฅ", second_place_medal: "๐ฅ", third_place_medal: "๐ฅ",
|
|
70
|
+
|
|
71
|
+
// symbols
|
|
72
|
+
fire: "๐ฅ", sparkles: "โจ", star: "โญ", star2: "๐", dizzy: "๐ซ",
|
|
73
|
+
boom: "๐ฅ", collision: "๐ฅ", zap: "โก", lightning: "โก",
|
|
74
|
+
snowflake: "โ๏ธ", cloud: "โ๏ธ", sunny: "โ๏ธ", rainbow: "๐",
|
|
75
|
+
rocket: "๐", airplane: "โ๏ธ", 100: "๐ฏ",
|
|
76
|
+
check: "โ
", white_check_mark: "โ
", ballot_box_with_check: "โ๏ธ", heavy_check_mark: "โ๏ธ",
|
|
77
|
+
x: "โ", cross_mark: "โ", negative_squared_cross_mark: "โ",
|
|
78
|
+
warning: "โ ๏ธ", exclamation: "โ", question: "โ",
|
|
79
|
+
grey_exclamation: "โ", grey_question: "โ", bangbang: "โผ๏ธ", interrobang: "โ๏ธ",
|
|
80
|
+
bulb: "๐ก", memo: "๐", pencil: "โ๏ธ", pencil2: "โ๏ธ", pen: "๐๏ธ",
|
|
81
|
+
lock: "๐", unlock: "๐", key: "๐", bell: "๐", no_bell: "๐",
|
|
82
|
+
bookmark: "๐", link: "๐", paperclip: "๐", pushpin: "๐", scissors: "โ๏ธ",
|
|
83
|
+
file_folder: "๐", open_file_folder: "๐", page_facing_up: "๐", page_with_curl: "๐",
|
|
84
|
+
calendar: "๐
", date: "๐
", clipboard: "๐",
|
|
85
|
+
chart_with_upwards_trend: "๐", chart_with_downwards_trend: "๐", bar_chart: "๐",
|
|
86
|
+
email: "๐ง", envelope: "โ๏ธ", inbox_tray: "๐ฅ", outbox_tray: "๐ค",
|
|
87
|
+
package: "๐ฆ", mailbox: "๐ซ", speech_balloon: "๐ฌ", thought_balloon: "๐ญ",
|
|
88
|
+
mag: "๐", mag_right: "๐", gear: "โ๏ธ", wrench: "๐ง", hammer: "๐จ",
|
|
89
|
+
hammer_and_wrench: "๐ ๏ธ", tools: "๐ ๏ธ", nut_and_bolt: "๐ฉ", shield: "๐ก๏ธ",
|
|
90
|
+
hourglass: "โ", hourglass_flowing_sand: "โณ", watch: "โ", alarm_clock: "โฐ",
|
|
91
|
+
stopwatch: "โฑ๏ธ", timer_clock: "โฒ๏ธ",
|
|
92
|
+
|
|
93
|
+
// animals
|
|
94
|
+
see_no_evil: "๐", hear_no_evil: "๐", speak_no_evil: "๐",
|
|
95
|
+
monkey: "๐", monkey_face: "๐ต", dog: "๐", dog2: "๐", cat: "๐", cat2: "๐",
|
|
96
|
+
tiger: "๐
", tiger2: "๐
", lion: "๐ฆ", horse: "๐ด", unicorn: "๐ฆ",
|
|
97
|
+
cow: "๐", cow2: "๐", pig: "๐ท", pig2: "๐ท", chicken: "๐", penguin: "๐ง",
|
|
98
|
+
bird: "๐ฆ", eagle: "๐ฆ
", duck: "๐ฆ", owl: "๐ฆ", bat: "๐ฆ", wolf: "๐บ",
|
|
99
|
+
fox_face: "๐ฆ", bear: "๐ป", panda_face: "๐ผ", koala: "๐จ",
|
|
100
|
+
rabbit: "๐ฐ", rabbit2: "๐", mouse: "๐ญ", mouse2: "๐", rat: "๐", hamster: "๐น",
|
|
101
|
+
frog: "๐ธ", snake: "๐", turtle: "๐ข", lizard: "๐ฆ", dragon: "๐", dragon_face: "๐ฒ",
|
|
102
|
+
whale: "๐", whale2: "๐", dolphin: "๐ฌ", fish: "๐", tropical_fish: "๐ ",
|
|
103
|
+
blowfish: "๐ก", shark: "๐ฆ", octopus: "๐", crab: "๐ฆ", lobster: "๐ฆ",
|
|
104
|
+
shrimp: "๐ฆ", squid: "๐ฆ", snail: "๐", butterfly: "๐ฆ", bug: "๐",
|
|
105
|
+
ant: "๐", bee: "๐", honeybee: "๐", spider: "๐ท๏ธ", spider_web: "๐ธ๏ธ",
|
|
106
|
+
|
|
107
|
+
// food & drink
|
|
108
|
+
apple: "๐", green_apple: "๐", pear: "๐", tangerine: "๐", orange: "๐",
|
|
109
|
+
lemon: "๐", banana: "๐", watermelon: "๐", grapes: "๐", strawberry: "๐",
|
|
110
|
+
peach: "๐", cherries: "๐", pizza: "๐", hamburger: "๐", fries: "๐",
|
|
111
|
+
hotdog: "๐ญ", sandwich: "๐ฅช", taco: "๐ฎ", burrito: "๐ฏ", egg: "๐ฅ", cooking: "๐ณ",
|
|
112
|
+
cake: "๐ฐ", cookie: "๐ช", chocolate_bar: "๐ซ", candy: "๐ฌ", lollipop: "๐ญ",
|
|
113
|
+
ice_cream: "๐จ", icecream: "๐ฆ", doughnut: "๐ฉ",
|
|
114
|
+
coffee: "โ", tea: "๐ต", beer: "๐บ", beers: "๐ป", wine_glass: "๐ท",
|
|
115
|
+
cocktail: "๐ธ", tropical_drink: "๐น", champagne: "๐พ",
|
|
116
|
+
|
|
117
|
+
// objects
|
|
118
|
+
computer: "๐ป", keyboard: "โจ๏ธ", desktop_computer: "๐ฅ๏ธ", printer: "๐จ๏ธ",
|
|
119
|
+
mouse_three_button: "๐ฑ๏ธ", trackball: "๐ฒ๏ธ", joystick: "๐น๏ธ", video_game: "๐ฎ",
|
|
120
|
+
phone: "๐ฑ", iphone: "๐ฑ", telephone: "โ๏ธ", telephone_receiver: "๐",
|
|
121
|
+
battery: "๐", electric_plug: "๐", camera: "๐ท", camera_flash: "๐ธ",
|
|
122
|
+
video_camera: "๐น", movie_camera: "๐ฅ", film_projector: "๐ฝ๏ธ", tv: "๐บ",
|
|
123
|
+
radio: "๐ป", microphone: "๐ค", headphones: "๐ง", musical_note: "๐ต", notes: "๐ถ",
|
|
124
|
+
art: "๐จ", performing_arts: "๐ญ", tickets: "๐๏ธ", clapper: "๐ฌ",
|
|
125
|
+
books: "๐", book: "๐", notebook: "๐", newspaper: "๐ฐ", scroll: "๐",
|
|
126
|
+
moneybag: "๐ฐ", dollar: "๐ต", credit_card: "๐ณ", gem: "๐", ring: "๐",
|
|
127
|
+
crown: "๐", tophat: "๐ฉ", necktie: "๐", shirt: "๐", jeans: "๐",
|
|
128
|
+
dress: "๐", lipstick: "๐", kiss: "๐", footprints: "๐ฃ",
|
|
129
|
+
|
|
130
|
+
// arrows
|
|
131
|
+
arrow_up: "โฌ๏ธ", arrow_down: "โฌ๏ธ", arrow_left: "โฌ
๏ธ", arrow_right: "โก๏ธ",
|
|
132
|
+
arrow_upper_left: "โ๏ธ", arrow_upper_right: "โ๏ธ", arrow_lower_left: "โ๏ธ", arrow_lower_right: "โ๏ธ",
|
|
133
|
+
left_right_arrow: "โ๏ธ", arrow_up_down: "โ๏ธ",
|
|
134
|
+
arrows_counterclockwise: "๐", arrows_clockwise: "๐",
|
|
135
|
+
rewind: "โช", fast_forward: "โฉ", play_or_pause_button: "โฏ๏ธ",
|
|
136
|
+
pause_button: "โธ๏ธ", stop_button: "โน๏ธ", record_button: "โบ๏ธ",
|
|
137
|
+
|
|
138
|
+
// numbers
|
|
139
|
+
zero: "0๏ธโฃ", one: "1๏ธโฃ", two: "2๏ธโฃ", three: "3๏ธโฃ", four: "4๏ธโฃ",
|
|
140
|
+
five: "5๏ธโฃ", six: "6๏ธโฃ", seven: "7๏ธโฃ", eight: "8๏ธโฃ", nine: "9๏ธโฃ", keycap_ten: "๐",
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
export function shortcodeToEmoji(shortcode: string): string {
|
|
144
|
+
return EMOJI_MAP[shortcode] ?? `:${shortcode}:`;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export function formatReactions(reactions: { emoji: string; count: number }[]): string {
|
|
148
|
+
if (reactions.length === 0) return "";
|
|
149
|
+
return reactions.map((r) => {
|
|
150
|
+
const emoji = shortcodeToEmoji(r.emoji);
|
|
151
|
+
return `${emoji}${r.count > 1 ? r.count : ""}`;
|
|
152
|
+
}).join(" ");
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export function wrapText(text: string, width: number, indent: string): string[] {
|
|
156
|
+
const lines: string[] = [];
|
|
157
|
+
const paragraphs = text.split(/\n/);
|
|
158
|
+
|
|
159
|
+
for (const paragraph of paragraphs) {
|
|
160
|
+
if (paragraph.trim() === "") {
|
|
161
|
+
lines.push("");
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const words = paragraph.split(/\s+/);
|
|
166
|
+
let currentLine = "";
|
|
167
|
+
|
|
168
|
+
for (const word of words) {
|
|
169
|
+
if (currentLine.length + word.length + 1 <= width) {
|
|
170
|
+
currentLine += (currentLine ? " " : "") + word;
|
|
171
|
+
} else {
|
|
172
|
+
if (currentLine) lines.push(indent + currentLine);
|
|
173
|
+
currentLine = word;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
if (currentLine) lines.push(indent + currentLine);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
return lines;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function getActorName(comment: Comment): string {
|
|
183
|
+
return comment.externalUser ?? comment.user ?? comment.botActor ?? "unknown";
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function getSourceLabel(comment: Comment): string {
|
|
187
|
+
const sync = comment.syncedWith[0];
|
|
188
|
+
if (!sync) return "";
|
|
189
|
+
const serviceName = sync.service.charAt(0).toUpperCase() + sync.service.slice(1).toLowerCase();
|
|
190
|
+
return ` via ${serviceName}`;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
function getSyncChannelName(comment: Comment): string | undefined {
|
|
194
|
+
const sync = comment.syncedWith[0];
|
|
195
|
+
if (!sync) return undefined;
|
|
196
|
+
|
|
197
|
+
if (sync.meta.type === "slack") {
|
|
198
|
+
return sync.meta.channelName;
|
|
199
|
+
}
|
|
200
|
+
if (sync.meta.type === "github" && sync.meta.repo) {
|
|
201
|
+
return sync.meta.owner ? `${sync.meta.owner}/${sync.meta.repo}` : sync.meta.repo;
|
|
202
|
+
}
|
|
203
|
+
if (sync.meta.type === "jira" && sync.meta.issueKey) {
|
|
204
|
+
return sync.meta.issueKey;
|
|
205
|
+
}
|
|
206
|
+
return undefined;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function formatCommentHeader(
|
|
210
|
+
comment: Comment,
|
|
211
|
+
isThreadRoot: boolean,
|
|
212
|
+
replyCount?: number,
|
|
213
|
+
threadUrl?: string
|
|
214
|
+
): string {
|
|
215
|
+
const sync = comment.syncedWith[0];
|
|
216
|
+
const time = formatRelativeTime(comment.createdAt);
|
|
217
|
+
|
|
218
|
+
if (isThreadRoot && sync) {
|
|
219
|
+
const channelName = getSyncChannelName(comment);
|
|
220
|
+
const channelPart = channelName ? ` in #${chalk.white(channelName)}` : "";
|
|
221
|
+
const serviceName = sync.service.charAt(0).toUpperCase() + sync.service.slice(1).toLowerCase();
|
|
222
|
+
let header = `${chalk.white(serviceName)} thread connected${channelPart} ${chalk.dim(time)}`;
|
|
223
|
+
|
|
224
|
+
if (replyCount && replyCount > 3 && threadUrl) {
|
|
225
|
+
header += `\nโ ${chalk.dim(`${replyCount - 3} previous replies,`)} [view all](${threadUrl})`;
|
|
226
|
+
}
|
|
227
|
+
return header;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
const actor = chalk.white(`@${getActorName(comment)}`);
|
|
231
|
+
const source = chalk.dim(getSourceLabel(comment));
|
|
232
|
+
return `${actor} ${chalk.dim(time)}${source}`;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
function outputSingleComment(comment: Comment, indent: string): void {
|
|
236
|
+
const bodyLines = wrapText(comment.body.trim(), 60, indent + "โ ");
|
|
237
|
+
for (const line of bodyLines) {
|
|
238
|
+
console.log(line);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
const reactions = formatReactions(comment.reactions);
|
|
242
|
+
if (reactions) {
|
|
243
|
+
console.log(`${indent}โ ${chalk.dim(`[${reactions}]`)}`);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
function renderCommentRecursive(
|
|
248
|
+
comment: Comment,
|
|
249
|
+
childMap: Map<string | null, Comment[]>,
|
|
250
|
+
depth: number,
|
|
251
|
+
maxRepliesPerLevel: number
|
|
252
|
+
): void {
|
|
253
|
+
const indent = " ".repeat(depth);
|
|
254
|
+
const header = formatCommentHeader(comment, false);
|
|
255
|
+
console.log(`${indent}โ ${header}`);
|
|
256
|
+
outputSingleComment(comment, indent + " ");
|
|
257
|
+
|
|
258
|
+
const children = childMap.get(comment.id) ?? [];
|
|
259
|
+
const recentChildren = children.slice(-maxRepliesPerLevel);
|
|
260
|
+
|
|
261
|
+
for (const child of recentChildren) {
|
|
262
|
+
renderCommentRecursive(child, childMap, depth + 1, maxRepliesPerLevel);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
export function outputCommentThreads(comments: Comment[], maxThreads = 3): void {
|
|
267
|
+
if (comments.length === 0) {
|
|
268
|
+
console.log(chalk.dim("no comments"));
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
const childMap = buildChildMap(comments);
|
|
273
|
+
const rootComments = childMap.get(null) ?? [];
|
|
274
|
+
const recentRoots = rootComments.slice(-maxThreads);
|
|
275
|
+
|
|
276
|
+
for (let i = 0; i < recentRoots.length; i++) {
|
|
277
|
+
const root = recentRoots[i];
|
|
278
|
+
if (!root) continue;
|
|
279
|
+
|
|
280
|
+
const children = childMap.get(root.id) ?? [];
|
|
281
|
+
const totalReplies = children.length;
|
|
282
|
+
const threadUrl = root.url;
|
|
283
|
+
const hasSync = root.syncedWith.length > 0;
|
|
284
|
+
|
|
285
|
+
console.log(formatCommentHeader(root, true, totalReplies, threadUrl));
|
|
286
|
+
|
|
287
|
+
if (!hasSync) {
|
|
288
|
+
outputSingleComment(root, "");
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
const recentChildren = children.slice(-3);
|
|
292
|
+
for (const child of recentChildren) {
|
|
293
|
+
renderCommentRecursive(child, childMap, 0, 3);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
if (i < recentRoots.length - 1) {
|
|
297
|
+
console.log();
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
|
|
3
|
+
export interface HeaderSection {
|
|
4
|
+
type: "header";
|
|
5
|
+
title: string;
|
|
6
|
+
subtitle?: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface FieldsSection {
|
|
10
|
+
type: "fields";
|
|
11
|
+
fields: { label: string; value: string }[];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface TextSection {
|
|
15
|
+
type: "text";
|
|
16
|
+
body: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface DividerSection {
|
|
20
|
+
type: "divider";
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export type DetailSection =
|
|
24
|
+
| HeaderSection
|
|
25
|
+
| FieldsSection
|
|
26
|
+
| TextSection
|
|
27
|
+
| DividerSection;
|
|
28
|
+
|
|
29
|
+
export function outputDetail(sections: DetailSection[]): void {
|
|
30
|
+
for (const section of sections) {
|
|
31
|
+
switch (section.type) {
|
|
32
|
+
case "header": {
|
|
33
|
+
console.log(section.title);
|
|
34
|
+
if (section.subtitle) {
|
|
35
|
+
console.log(section.subtitle);
|
|
36
|
+
}
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
case "fields": {
|
|
40
|
+
const maxLabelWidth = Math.max(
|
|
41
|
+
...section.fields.map((f) => f.label.length)
|
|
42
|
+
);
|
|
43
|
+
console.log();
|
|
44
|
+
for (const field of section.fields) {
|
|
45
|
+
const paddedLabel = field.label.padEnd(maxLabelWidth);
|
|
46
|
+
console.log(`${paddedLabel} ${field.value}`);
|
|
47
|
+
}
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
case "text": {
|
|
51
|
+
console.log();
|
|
52
|
+
console.log(section.body);
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
case "divider": {
|
|
56
|
+
console.log(chalk.dim("โ".repeat(40)));
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|