@bussolabs/closeyourit-cli 0.0.10 → 0.0.11

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.
@@ -6,10 +6,10 @@ const core_1 = require("@oclif/core");
6
6
  const base_1 = require("../../base");
7
7
  class TicketsAttachmentDownload extends base_1.BaseCommand {
8
8
  static args = {
9
- id: core_1.Args.string({ description: 'Ticket id', required: true }),
10
- attachment: core_1.Args.string({ description: 'Attachment id', required: true }),
9
+ id: core_1.Args.string({ description: 'Ticket id or code (e.g. DRFL-3)', required: true }),
10
+ attachment: core_1.Args.string({ description: 'Attachment id (ticket attachment or comment file)', required: true }),
11
11
  };
12
- static description = 'Download a ticket attachment to disk';
12
+ static description = 'Download a ticket binary to disk: works for ticket attachments AND files attached to its comments';
13
13
  static examples = [
14
14
  '<%= config.bin %> tickets attachment-download <ticket-id> <attachment-id> --project acme-api',
15
15
  '<%= config.bin %> tickets attachment-download <ticket-id> <attachment-id> -p acme-api --out ./downloads',
@@ -2,11 +2,12 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const core_1 = require("@oclif/core");
4
4
  const base_1 = require("../../base");
5
+ const output_1 = require("../../lib/output");
5
6
  class TicketsComments extends base_1.BaseCommand {
6
7
  static args = {
7
- id: core_1.Args.string({ description: 'Ticket id', required: true }),
8
+ id: core_1.Args.string({ description: 'Ticket id or code (e.g. DRFL-3)', required: true }),
8
9
  };
9
- static description = 'List all comments of a ticket (oldest first)';
10
+ static description = 'List all comments of a ticket (oldest first), including attached files — download them with tickets attachment-download';
10
11
  static examples = [
11
12
  '<%= config.bin %> tickets comments <ticket-id> --project acme-api',
12
13
  '<%= config.bin %> tickets comments <ticket-id> -p acme-api --json',
@@ -33,8 +34,12 @@ class TicketsComments extends base_1.BaseCommand {
33
34
  }
34
35
  else {
35
36
  for (const comment of all) {
36
- this.log(`\n── ${String(comment.author ?? '?')} · ${String(comment.created_at ?? '')} · ${String(comment.id ?? '')}`);
37
- this.log(String(comment.body ?? ''));
37
+ this.log(`\n── ${(0, output_1.sanitize)(comment.author ?? '?')} · ${(0, output_1.sanitize)(comment.created_at ?? '')} · ${(0, output_1.sanitize)(comment.id ?? '')}`);
38
+ this.log((0, output_1.sanitizeMultiline)(comment.body ?? ''));
39
+ const files = Array.isArray(comment.files) ? comment.files : [];
40
+ for (const file of files) {
41
+ this.log(` [file] ${(0, output_1.sanitize)(file.id)} · ${(0, output_1.sanitize)(file.filename)} · ${(0, output_1.sanitize)(file.content_type)} · ${(0, output_1.sanitize)(file.byte_size)} bytes`);
42
+ }
38
43
  }
39
44
  }
40
45
  }
@@ -9,4 +9,9 @@ export default class TicketsShow extends BaseCommand {
9
9
  project: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
10
10
  };
11
11
  run(): Promise<unknown>;
12
+ /** Read every page of a collection endpoint: the discussion must be complete, not just page 1. */
13
+ private fetchAllPages;
14
+ private renderAttachments;
15
+ private renderComments;
16
+ private renderTicket;
12
17
  }
@@ -4,20 +4,104 @@ const core_1 = require("@oclif/core");
4
4
  const base_1 = require("../../base");
5
5
  const output_1 = require("../../lib/output");
6
6
  class TicketsShow extends base_1.BaseCommand {
7
- static description = 'Show a single ticket';
8
- static examples = ['<%= config.bin %> tickets show <ticket-id> --project acme-api'];
7
+ static description = 'Show a single ticket in full: body (description + Given/When/Then/Expected), comments (with their files) and attachments';
8
+ static examples = [
9
+ '<%= config.bin %> tickets show <ticket-id> --project acme-api',
10
+ '<%= config.bin %> tickets show DRFL-3 --project driverone-flutter',
11
+ '<%= config.bin %> tickets show DRFL-3 -p driverone-flutter --json',
12
+ ];
9
13
  static args = {
10
- id: core_1.Args.string({ description: 'Ticket id or code', required: true }),
14
+ id: core_1.Args.string({ description: 'Ticket id or code (e.g. DRFL-3)', required: true }),
11
15
  };
12
16
  static flags = { ...base_1.projectFlag };
13
17
  async run() {
14
18
  const { args, flags } = await this.parse(TicketsShow);
15
19
  const projectId = await this.resolveProjectId(flags.project);
16
- const res = await this.api.get(`/cli/v1/projects/${projectId}/tickets/${args.id}`);
20
+ const base = `/cli/v1/projects/${encodeURIComponent(projectId)}/tickets/${encodeURIComponent(args.id)}`;
21
+ // The show is the analysis entry point: always the WHOLE ticket in one command
22
+ // (fields + full discussion + attachments), so nothing stays hidden behind extra calls.
23
+ const res = await this.api.get(base);
24
+ const ticket = res.data ?? {};
25
+ const comments = await this.fetchAllPages(`${base}/comments`);
26
+ const attachments = await this.fetchAllPages(`${base}/attachments`);
17
27
  if (!this.jsonEnabled()) {
18
- this.log((0, output_1.renderRecord)(res.data ?? {}));
28
+ this.renderTicket(ticket);
29
+ this.renderComments(comments);
30
+ this.renderAttachments(attachments);
31
+ }
32
+ return { data: { ...ticket, comments, attachments } };
33
+ }
34
+ /** Read every page of a collection endpoint: the discussion must be complete, not just page 1. */
35
+ async fetchAllPages(path) {
36
+ const all = [];
37
+ let page = 1;
38
+ let totalPages = 1;
39
+ do {
40
+ // eslint-disable-next-line no-await-in-loop
41
+ const res = await this.api.get(`${path}?page=${page}&per=100`);
42
+ all.push(...(Array.isArray(res.data) ? res.data : []));
43
+ totalPages = Number(res.meta?.total_pages ?? 1);
44
+ page += 1;
45
+ } while (page <= totalPages);
46
+ return all;
47
+ }
48
+ renderAttachments(attachments) {
49
+ this.log(`\nAttachments (${attachments.length})`);
50
+ if (attachments.length === 0)
51
+ return;
52
+ this.log((0, output_1.renderTable)(['ID', 'FILENAME', 'CONTENT_TYPE', 'BYTE_SIZE', 'CREATED_AT'], attachments.map((attachment) => [
53
+ String(attachment.id ?? ''),
54
+ String(attachment.filename ?? ''),
55
+ String(attachment.content_type ?? ''),
56
+ String(attachment.byte_size ?? ''),
57
+ String(attachment.created_at ?? ''),
58
+ ])));
59
+ }
60
+ renderComments(comments) {
61
+ this.log(`\nComments (${comments.length})`);
62
+ for (const comment of comments) {
63
+ this.log(`\n── ${(0, output_1.sanitize)(comment.author ?? '?')} · ${(0, output_1.sanitize)(comment.created_at ?? '')} · ${(0, output_1.sanitize)(comment.id ?? '')}`);
64
+ this.log((0, output_1.sanitizeMultiline)(comment.body ?? ''));
65
+ const files = Array.isArray(comment.files) ? comment.files : [];
66
+ for (const file of files) {
67
+ this.log(` [file] ${(0, output_1.sanitize)(file.id)} · ${(0, output_1.sanitize)(file.filename)} · ${(0, output_1.sanitize)(file.content_type)} · ${(0, output_1.sanitize)(file.byte_size)} bytes`);
68
+ }
69
+ }
70
+ }
71
+ renderTicket(ticket) {
72
+ const platforms = Array.isArray(ticket.platforms) ? ticket.platforms.map(String).join(', ') : null;
73
+ this.log((0, output_1.renderRecord)({
74
+ id: ticket.id,
75
+ code: ticket.code,
76
+ title: ticket.title,
77
+ kind: ticket.kind,
78
+ status: ticket.status,
79
+ priority: ticket.priority,
80
+ weight: ticket.weight,
81
+ votes_count: ticket.votes_count,
82
+ assignee: ticket.assignee,
83
+ reporter: ticket.reporter,
84
+ reviewer: ticket.reviewer,
85
+ milestone: ticket.milestone,
86
+ platforms: platforms || null,
87
+ project_id: ticket.project_id,
88
+ created_at: ticket.created_at,
89
+ updated_at: ticket.updated_at,
90
+ }));
91
+ // Multi-line body blocks: description first, then the 4 BDD clauses (only those present).
92
+ const blocks = [
93
+ ['Description', ticket.description],
94
+ ['Given', ticket.step_given],
95
+ ['When', ticket.step_when],
96
+ ['Then', ticket.step_then],
97
+ ['Expected', ticket.step_expected],
98
+ ];
99
+ for (const [label, value] of blocks) {
100
+ if (value === null || value === undefined || String(value).trim() === '')
101
+ continue;
102
+ this.log(`\n${label}\n${'-'.repeat(label.length)}`);
103
+ this.log((0, output_1.sanitizeMultiline)(value));
19
104
  }
20
- return res;
21
105
  }
22
106
  }
23
107
  exports.default = TicketsShow;
@@ -1,3 +1,16 @@
1
+ /**
2
+ * Neutralize terminal control sequences (CWE-150) in server-supplied strings.
3
+ * Log/error/ticket text is attacker-influenceable; printing raw ESC (0x1B) & co.
4
+ * to a TTY allows cursor/color/title injection. Replace every C0/C1 control char
5
+ * (0x00–0x1F, 0x7F–0x9F) with a space — ANSI is defused, width is preserved.
6
+ */
7
+ export declare function sanitize(value: unknown): string;
8
+ /**
9
+ * Like `sanitize`, but preserves line breaks: for multi-line bodies (ticket description,
10
+ * BDD clauses, comment text) where collapsing `\n` to spaces would destroy readability.
11
+ * Every other C0/C1 control char is still defused per line.
12
+ */
13
+ export declare function sanitizeMultiline(value: unknown): string;
1
14
  /** Minimal dependency-free table renderer for human output. */
2
15
  export declare function renderTable(headers: string[], rows: string[][]): string;
3
16
  /** Pretty-print the scalar fields of a record as `key: value` lines. */
@@ -1,5 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sanitize = sanitize;
4
+ exports.sanitizeMultiline = sanitizeMultiline;
3
5
  exports.renderTable = renderTable;
4
6
  exports.renderRecord = renderRecord;
5
7
  /**
@@ -16,6 +18,17 @@ function sanitize(value) {
16
18
  }
17
19
  return out;
18
20
  }
21
+ /**
22
+ * Like `sanitize`, but preserves line breaks: for multi-line bodies (ticket description,
23
+ * BDD clauses, comment text) where collapsing `\n` to spaces would destroy readability.
24
+ * Every other C0/C1 control char is still defused per line.
25
+ */
26
+ function sanitizeMultiline(value) {
27
+ return String(value ?? '')
28
+ .split('\n')
29
+ .map((line) => sanitize(line))
30
+ .join('\n');
31
+ }
19
32
  /** Minimal dependency-free table renderer for human output. */
20
33
  function renderTable(headers, rows) {
21
34
  const safeHeaders = headers.map(sanitize);