@shortcut-cli/shortcut-cli 3.4.0 → 3.5.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/README.md +25 -0
- package/build/_virtual/rolldown_runtime.js +25 -0
- package/build/bin/short-api.js +78 -0
- package/build/bin/short-create.js +52 -573
- package/build/bin/short-epics.js +31 -160
- package/build/bin/short-find.js +4 -588
- package/build/bin/short-install.js +37 -135
- package/build/bin/short-members.js +28 -134
- package/build/bin/short-projects.js +28 -136
- package/build/bin/short-search.js +46 -597
- package/build/bin/short-story.js +201 -737
- package/build/bin/short-workflows.js +27 -133
- package/build/bin/short-workspace.js +62 -648
- package/build/bin/short.js +7 -33
- package/build/lib/client.js +10 -103
- package/build/lib/configure.js +93 -126
- package/build/lib/spinner.js +14 -31
- package/build/lib/stories.js +295 -462
- package/build/package.js +18 -0
- package/package.json +15 -15
package/build/bin/short-story.js
CHANGED
|
@@ -1,742 +1,206 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
};
|
|
16
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
17
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
18
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
19
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
20
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
-
mod
|
|
23
|
-
));
|
|
24
|
-
|
|
25
|
-
// src/bin/short-story.ts
|
|
26
|
-
var import_child_process2 = require("child_process");
|
|
27
|
-
var import_os2 = __toESM(require("os"));
|
|
28
|
-
var import_path2 = __toESM(require("path"));
|
|
29
|
-
var import_fs2 = __toESM(require("fs"));
|
|
30
|
-
var import_https = __toESM(require("https"));
|
|
31
|
-
var import_commander = __toESM(require("commander"));
|
|
32
|
-
var import_chalk2 = __toESM(require("chalk"));
|
|
33
|
-
var import_debug2 = __toESM(require("debug"));
|
|
34
|
-
|
|
35
|
-
// src/lib/client.ts
|
|
36
|
-
var import_client = require("@shortcut/client");
|
|
37
|
-
|
|
38
|
-
// src/lib/configure.ts
|
|
39
|
-
var import_path = __toESM(require("path"));
|
|
40
|
-
var import_fs = __toESM(require("fs"));
|
|
41
|
-
var import_os = __toESM(require("os"));
|
|
42
|
-
function getConfigDir(suffix) {
|
|
43
|
-
const configBaseDir = process.env.XDG_CONFIG_HOME || import_path.default.resolve(process.env.XDG_DATA_HOME || import_os.default.homedir(), ".config");
|
|
44
|
-
return import_path.default.resolve(configBaseDir, suffix);
|
|
45
|
-
}
|
|
46
|
-
var configDir = getConfigDir("shortcut-cli");
|
|
47
|
-
var configFile = import_path.default.resolve(configDir, "config.json");
|
|
48
|
-
var legacyConfigDirs = [
|
|
49
|
-
getConfigDir("clubhouse-cli"),
|
|
50
|
-
import_path.default.resolve(import_os.default.homedir(), ".clubhouse-cli")
|
|
51
|
-
];
|
|
52
|
-
var CONFIG_CACHE = null;
|
|
53
|
-
var loadConfig = () => {
|
|
54
|
-
const config4 = loadCachedConfig();
|
|
55
|
-
if (!config4 || config4 === {} || !config4.token) {
|
|
56
|
-
console.error("Please run 'short install' to configure Shortcut API access.");
|
|
57
|
-
process.exit(11);
|
|
58
|
-
}
|
|
59
|
-
if (!config4.urlSlug) {
|
|
60
|
-
console.error(
|
|
61
|
-
"Your config must be updated with data from Shortcut. Please run 'short install --refresh'."
|
|
62
|
-
);
|
|
63
|
-
process.exit(12);
|
|
64
|
-
}
|
|
65
|
-
return config4;
|
|
66
|
-
};
|
|
67
|
-
var loadCachedConfig = () => {
|
|
68
|
-
if (CONFIG_CACHE) {
|
|
69
|
-
return { ...CONFIG_CACHE };
|
|
70
|
-
}
|
|
71
|
-
let config4 = {};
|
|
72
|
-
const token = process.env.SHORTCUT_API_TOKEN || process.env.CLUBHOUSE_API_TOKEN;
|
|
73
|
-
legacyConfigDirs.forEach((dir) => {
|
|
74
|
-
if (import_fs.default.existsSync(dir)) {
|
|
75
|
-
createConfigDir();
|
|
76
|
-
import_fs.default.renameSync(dir, configDir);
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
if (import_fs.default.existsSync(configFile)) {
|
|
80
|
-
try {
|
|
81
|
-
config4 = JSON.parse(import_fs.default.readFileSync(configFile, "utf8"));
|
|
82
|
-
} catch (e) {
|
|
83
|
-
console.error(e);
|
|
84
|
-
process.exit(10);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
if (token) {
|
|
88
|
-
config4 = { token, ...config4 };
|
|
89
|
-
}
|
|
90
|
-
CONFIG_CACHE = { ...config4 };
|
|
91
|
-
return config4;
|
|
92
|
-
};
|
|
93
|
-
var createConfigDir = () => {
|
|
94
|
-
const dir = import_path.default.dirname(configDir);
|
|
95
|
-
if (!import_fs.default.existsSync(dir)) {
|
|
96
|
-
import_fs.default.mkdirSync(dir);
|
|
97
|
-
}
|
|
98
|
-
if (!import_fs.default.existsSync(configDir)) {
|
|
99
|
-
import_fs.default.mkdirSync(configDir);
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
// src/lib/client.ts
|
|
104
|
-
var config = loadConfig();
|
|
105
|
-
var client = new import_client.ShortcutClient(config.token);
|
|
106
|
-
var client_default = client;
|
|
2
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.js');
|
|
3
|
+
const require_lib_spinner = require('../lib/spinner.js');
|
|
4
|
+
const require_lib_configure = require('../lib/configure.js');
|
|
5
|
+
const require_lib_client = require('../lib/client.js');
|
|
6
|
+
const require_lib_stories = require('../lib/stories.js');
|
|
7
|
+
const commander = require_rolldown_runtime.__toESM(require("commander"));
|
|
8
|
+
const debug = require_rolldown_runtime.__toESM(require("debug"));
|
|
9
|
+
const path = require_rolldown_runtime.__toESM(require("path"));
|
|
10
|
+
const fs = require_rolldown_runtime.__toESM(require("fs"));
|
|
11
|
+
const os = require_rolldown_runtime.__toESM(require("os"));
|
|
12
|
+
const child_process = require_rolldown_runtime.__toESM(require("child_process"));
|
|
13
|
+
const chalk = require_rolldown_runtime.__toESM(require("chalk"));
|
|
14
|
+
const https = require_rolldown_runtime.__toESM(require("https"));
|
|
107
15
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
async
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
return (a, b) => {
|
|
291
|
-
return fields.reduce((acc, field) => {
|
|
292
|
-
if (acc !== 0) return acc;
|
|
293
|
-
const ap = field[0].reduce(pluck, a);
|
|
294
|
-
const bp = field[0].reduce(pluck, b);
|
|
295
|
-
if (ap === bp) return 0;
|
|
296
|
-
const direction = (field[1] || [""])[0].match(/des/i) ? 1 : -1;
|
|
297
|
-
if (ap > bp) {
|
|
298
|
-
if (direction > 0) return -1;
|
|
299
|
-
} else {
|
|
300
|
-
if (direction < 0) return -1;
|
|
301
|
-
}
|
|
302
|
-
return 1;
|
|
303
|
-
}, 0);
|
|
304
|
-
};
|
|
305
|
-
};
|
|
306
|
-
var printFormattedStory = (program2) => {
|
|
307
|
-
return (story) => {
|
|
308
|
-
const defaultFormat = `#%id %t
|
|
309
|
-
Type: %y/%e
|
|
310
|
-
Team: %T
|
|
311
|
-
Project: %p
|
|
312
|
-
Epic: %epic
|
|
313
|
-
Iteration: %i
|
|
314
|
-
Requester: %r
|
|
315
|
-
Owners: %o
|
|
316
|
-
State: %s
|
|
317
|
-
Labels: %l
|
|
318
|
-
URL: %u
|
|
319
|
-
Created: %c
|
|
320
|
-
Updated: %updated
|
|
321
|
-
Archived: %a
|
|
322
|
-
`;
|
|
323
|
-
const format = program2.format || defaultFormat;
|
|
324
|
-
const labels = story.labels.map((l) => `${l.name} (#${l.id})`);
|
|
325
|
-
const owners = story.owners.map(
|
|
326
|
-
(o) => `${o.profile.name} (${o.profile.mention_name})`
|
|
327
|
-
);
|
|
328
|
-
const url = `https://app.shortcut.com/story/${story.id}`;
|
|
329
|
-
const project = story.project ? `${story.project.name} (#${story.project.id})` : "None";
|
|
330
|
-
log(
|
|
331
|
-
format.replace(/%j/, JSON.stringify({ ...story, url }, null, 2)).replace(/%id/, import_chalk.default.blue.bold(`${story.id}`)).replace(/%t/, import_chalk.default.blue(`${story.name}`)).replace(/%d/, story.description || "").replace(/%y/, story.story_type).replace(/%l/, labels.join(", ") || "_").replace(
|
|
332
|
-
/%epic/,
|
|
333
|
-
story.epic_id ? `${(story.epic || {}).name} (#${story.epic_id})` : "_"
|
|
334
|
-
).replace(/%e/, `${story.estimate || "_"}`).replace(
|
|
335
|
-
/%i/,
|
|
336
|
-
story.iteration_id ? `${(story.iteration || {}).name} (#${story.iteration_id})` : "_"
|
|
337
|
-
).replace(/%p/, project).replace(/%T/, story.group?.name || "_").replace(/%o/, owners.join(", ") || "_").replace(
|
|
338
|
-
/%r/,
|
|
339
|
-
// eslint-disable-next-line no-constant-binary-expression
|
|
340
|
-
`${story.requester.profile.name} (${story.requester.profile.mention_name})` || "_"
|
|
341
|
-
).replace(
|
|
342
|
-
/%s/,
|
|
343
|
-
`${(story.state || {}).name} (#${story.workflow_state_id})`
|
|
344
|
-
).replace(/%c/, `${story.created_at}`).replace(
|
|
345
|
-
/%updated/,
|
|
346
|
-
`${story.updated_at !== story.created_at ? story.updated_at : "_"}`
|
|
347
|
-
).replace(/%u/, url).replace(/%a/, `${story.archived}`).replace(
|
|
348
|
-
/%gbs/,
|
|
349
|
-
`${buildStoryBranch(story, `${config2.mentionName}/sc-${story.id}/`)}`
|
|
350
|
-
).replace(/%gb/, `${buildStoryBranch(story)}`)
|
|
351
|
-
);
|
|
352
|
-
return story;
|
|
353
|
-
};
|
|
354
|
-
};
|
|
355
|
-
var buildURL = (...segments) => {
|
|
356
|
-
return [
|
|
357
|
-
"https://app.shortcut.com",
|
|
358
|
-
config2.urlSlug,
|
|
359
|
-
...segments.map((item) => item.toString())
|
|
360
|
-
].join("/");
|
|
361
|
-
};
|
|
362
|
-
var storyURL = (story) => buildURL("story", story.id);
|
|
363
|
-
var printDetailedStory = (story, entities = {}) => {
|
|
364
|
-
const labels = story.labels.map((l) => {
|
|
365
|
-
return import_chalk.default.bold(`#${l.id}`) + ` ${l.name}`;
|
|
366
|
-
});
|
|
367
|
-
const owners = story.owners.map((o) => {
|
|
368
|
-
const mentionName = import_chalk.default.bold(`${o.profile.mention_name}`);
|
|
369
|
-
return `${o.profile.name} (${mentionName})`;
|
|
370
|
-
});
|
|
371
|
-
log(import_chalk.default.blue.bold(`#${story.id}`) + import_chalk.default.blue(` ${story.name}`));
|
|
372
|
-
log(import_chalk.default.bold("Desc:") + ` ${formatLong(story.description || "_")}`);
|
|
373
|
-
log(import_chalk.default.bold("Team:") + ` ${story.group?.name || "_"}`);
|
|
374
|
-
log(import_chalk.default.bold("Owners:") + ` ${owners.join(", ") || "_"}`);
|
|
375
|
-
log(
|
|
376
|
-
import_chalk.default.bold("Requester:") + ` ${story.requester.profile.name} (${story.requester.profile.mention_name})`
|
|
377
|
-
);
|
|
378
|
-
log(import_chalk.default.bold("Type:") + ` ${story.story_type}/${story.estimate || "_"}`);
|
|
379
|
-
log(import_chalk.default.bold("Label:") + ` ${labels.join(", ") || "_"}`);
|
|
380
|
-
if (story.project) {
|
|
381
|
-
log(import_chalk.default.bold("Project:") + import_chalk.default.bold(` #${story.project_id} `) + story.project.name);
|
|
382
|
-
}
|
|
383
|
-
if (story.group) {
|
|
384
|
-
log(import_chalk.default.bold("Team:") + import_chalk.default.bold(` #${story.group_id} `) + story.group.name);
|
|
385
|
-
}
|
|
386
|
-
if (story.epic) {
|
|
387
|
-
log(import_chalk.default.bold("Epic:") + import_chalk.default.bold(` #${story.epic_id} `) + story.epic.name);
|
|
388
|
-
} else {
|
|
389
|
-
log(import_chalk.default.bold("Epic:") + " _");
|
|
390
|
-
}
|
|
391
|
-
if (story.iteration) {
|
|
392
|
-
log(
|
|
393
|
-
import_chalk.default.bold("Iteration:") + import_chalk.default.bold(` #${story.iteration_id} `) + story.iteration.name
|
|
394
|
-
);
|
|
395
|
-
} else {
|
|
396
|
-
log(import_chalk.default.bold("Iteration:") + " _");
|
|
397
|
-
}
|
|
398
|
-
log(import_chalk.default.bold("State:") + import_chalk.default.bold(` #${story.workflow_state_id} `) + story.state.name);
|
|
399
|
-
log(import_chalk.default.bold("Created:") + ` ${story.created_at}`);
|
|
400
|
-
if (story.created_at !== story.updated_at) {
|
|
401
|
-
log(import_chalk.default.bold("Updated:") + ` ${story.updated_at}`);
|
|
402
|
-
}
|
|
403
|
-
log(import_chalk.default.bold("URL:") + ` ${storyURL(story)}`);
|
|
404
|
-
if (story.archived) {
|
|
405
|
-
log(import_chalk.default.bold("Archived: ") + import_chalk.default.bold(`${story.archived}`));
|
|
406
|
-
}
|
|
407
|
-
if (story.completed) {
|
|
408
|
-
log(import_chalk.default.bold("Completed: ") + import_chalk.default.bold(`${story.completed_at}`));
|
|
409
|
-
}
|
|
410
|
-
story.tasks.map((c) => {
|
|
411
|
-
log(
|
|
412
|
-
import_chalk.default.bold("Task: ") + (c.complete ? "[X]" : "[ ]") + " " + formatLong(c.description)
|
|
413
|
-
);
|
|
414
|
-
return c;
|
|
415
|
-
});
|
|
416
|
-
story.comments.filter((comment) => !comment.deleted).map((c) => {
|
|
417
|
-
const author = entities.membersById.get(c.author_id);
|
|
418
|
-
log(import_chalk.default.bold("Comment:") + ` ${formatLong(c.text)}`);
|
|
419
|
-
log(` ${author.profile.name} ` + import_chalk.default.bold("at:") + ` ${c.updated_at}`);
|
|
420
|
-
return c;
|
|
421
|
-
});
|
|
422
|
-
story.files.map((file) => {
|
|
423
|
-
log(import_chalk.default.bold("File:") + ` ${file.name}`);
|
|
424
|
-
log(` ${file.url}`);
|
|
425
|
-
return file;
|
|
426
|
-
});
|
|
427
|
-
log();
|
|
428
|
-
};
|
|
429
|
-
var formatLong = (str) => str.split("\n").join("\n ");
|
|
430
|
-
var parseDateComparator = (arg) => {
|
|
431
|
-
const match = arg.match(/[0-9].*/) || { index: 0, "0": { length: 30 } };
|
|
432
|
-
const parsedDate = new Date(arg.slice(match.index));
|
|
433
|
-
const comparator = arg.slice(0, match.index);
|
|
434
|
-
return (date) => {
|
|
435
|
-
switch (comparator) {
|
|
436
|
-
case "<":
|
|
437
|
-
return new Date(date) < parsedDate;
|
|
438
|
-
case ">":
|
|
439
|
-
return new Date(date) > parsedDate;
|
|
440
|
-
case "=":
|
|
441
|
-
default:
|
|
442
|
-
return new Date(date.slice(0, match[0].length)).getTime() === parsedDate.getTime();
|
|
443
|
-
}
|
|
444
|
-
};
|
|
445
|
-
};
|
|
446
|
-
var parseNumberComparator = (arg) => {
|
|
447
|
-
const match = arg.match(/[0-9].*/) || { index: 0, "0": { length: 30 } };
|
|
448
|
-
const parsedNumber = Number(arg.slice(match.index));
|
|
449
|
-
const comparator = arg.slice(0, match.index).trimRight();
|
|
450
|
-
return (n) => {
|
|
451
|
-
switch (comparator) {
|
|
452
|
-
case "<":
|
|
453
|
-
return Number(n) < parsedNumber;
|
|
454
|
-
case ">":
|
|
455
|
-
return Number(n) > parsedNumber;
|
|
456
|
-
case "=":
|
|
457
|
-
default:
|
|
458
|
-
return Number(n) === parsedNumber;
|
|
459
|
-
}
|
|
460
|
-
};
|
|
461
|
-
};
|
|
462
|
-
var buildStoryBranch = (story, prefix = "") => {
|
|
463
|
-
prefix = prefix || `${config2.mentionName}/sc-${story.id}/${story.story_type}-`;
|
|
464
|
-
const slug = story.name.toLowerCase().replace(/\W/g, "-").replace(/[^a-z0-9-]/g, "").slice(0, 30).replace(/-$/, "");
|
|
465
|
-
return `${prefix}${slug}`;
|
|
466
|
-
};
|
|
467
|
-
var checkoutStoryBranch = (story, prefix = "") => {
|
|
468
|
-
const branch = buildStoryBranch(story, prefix);
|
|
469
|
-
debug("checking out git branch: " + branch);
|
|
470
|
-
(0, import_child_process.execSync)(`git checkout ${branch} 2> /dev/null || git checkout -b ${branch}`);
|
|
471
|
-
};
|
|
472
|
-
var fileURL = (file) => `${file.url}?token=${config2.token}`;
|
|
473
|
-
var stories_default = {
|
|
474
|
-
listStories,
|
|
475
|
-
printFormattedStory,
|
|
476
|
-
printDetailedStory,
|
|
477
|
-
checkoutStoryBranch,
|
|
478
|
-
fetchEntities,
|
|
479
|
-
hydrateStory,
|
|
480
|
-
findProject,
|
|
481
|
-
findGroup,
|
|
482
|
-
findState,
|
|
483
|
-
findEpic,
|
|
484
|
-
findIteration,
|
|
485
|
-
findOwnerIds,
|
|
486
|
-
findLabelNames,
|
|
487
|
-
fileURL,
|
|
488
|
-
storyURL,
|
|
489
|
-
buildURL
|
|
490
|
-
};
|
|
491
|
-
|
|
492
|
-
// src/lib/spinner.ts
|
|
493
|
-
var import_cli_spinner = require("cli-spinner");
|
|
494
|
-
var spinner = (text = "") => {
|
|
495
|
-
const spin2 = new import_cli_spinner.Spinner({
|
|
496
|
-
text: text ? text : "Loading... %s ",
|
|
497
|
-
stream: process.stderr
|
|
498
|
-
});
|
|
499
|
-
spin2.setSpinnerString(27);
|
|
500
|
-
return spin2;
|
|
501
|
-
};
|
|
502
|
-
var spinner_default = spinner;
|
|
503
|
-
|
|
504
|
-
// src/bin/short-story.ts
|
|
505
|
-
var config3 = loadConfig();
|
|
506
|
-
var spin = spinner_default();
|
|
507
|
-
var log2 = console.log;
|
|
508
|
-
var logError = console.error;
|
|
509
|
-
var debug2 = (0, import_debug2.default)("short");
|
|
510
|
-
var program = import_commander.default.usage("[options] <id>").description("Update and/or display story details").option("-a, --archived", "Update story as archived").option("-c, --comment [text]", "Add comment to story", "").option("-d, --description [text]", "Update description of story", "").option("-D, --download", "Download all attached files", "").option("--download-dir [path]", "Directory to download files to", ".").option("-e, --estimate [number]", "Update estimate of story", "").option("--epic [id|name]", "Set epic of story").option("-i, --iteration [id|name]", "Set iteration of story").option("-f, --format [template]", "Format the story output by template", "").option("--from-git", "Fetch story parsed by ID from current git branch").option(
|
|
511
|
-
"--git-branch",
|
|
512
|
-
"Checkout git branch from story slug <mention-name>/ch<id>/<type>-<title>\n as required by the Git integration: https://bit.ly/2RKO1FF"
|
|
513
|
-
).option(
|
|
514
|
-
"--git-branch-short",
|
|
515
|
-
"Checkout git branch from story slug <mention-name>/ch<id>/<title>"
|
|
516
|
-
).option("-I, --idonly", "Print only ID of story results", "").option("-l, --label [id|name]", "Stories with label id/name, by regex", "").option("--move-after [id]", "Move story to position below story ID").option("--move-before [id]", "Move story to position above story ID").option("--move-down [n]", "Move story position downward by n stories").option("--move-up [n]", "Move story position upward by n stories").option("-o, --owners [id|name]", "Update owners of story, comma-separated", "").option("-O, --open", "Open story in browser").option("--oe, --open-epic", "Open story's epic in browser").option("--oi, --open-iteration", "Open story's iteration in browser").option("--op, --open-project", "Open story's project in browser").option("-q, --quiet", "Print only story output, no loading dialog", "").option("-s, --state [id|name]", "Update workflow state of story", "").option("-t, --title [text]", "Update title/name of story", "").option("--task [text]", "Create new task on story").option("--task-complete [text]", "Toggle completion of task on story matching text").option("-y, --type [name]", "Update type of story", "").parse(process.argv);
|
|
517
|
-
var main = async () => {
|
|
518
|
-
const entities = await stories_default.fetchEntities();
|
|
519
|
-
if (!(program.idonly || program.quiet)) spin.start();
|
|
520
|
-
debug2("constructing story update");
|
|
521
|
-
const update = {};
|
|
522
|
-
if (program.archived) {
|
|
523
|
-
update.archived = true;
|
|
524
|
-
}
|
|
525
|
-
if (program.state) {
|
|
526
|
-
update.workflow_state_id = (stories_default.findState(entities, program.state) || {}).id;
|
|
527
|
-
}
|
|
528
|
-
if (program.estimate) {
|
|
529
|
-
update.estimate = parseInt(program.estimate, 10);
|
|
530
|
-
}
|
|
531
|
-
if (program.title) {
|
|
532
|
-
update.name = program.title;
|
|
533
|
-
}
|
|
534
|
-
if (program.description) {
|
|
535
|
-
update.description = `${program.description}`;
|
|
536
|
-
}
|
|
537
|
-
if (program.type) {
|
|
538
|
-
const typeMatch = new RegExp(program.type, "i");
|
|
539
|
-
update.story_type = ["feature", "bug", "chore"].filter(
|
|
540
|
-
(t) => !!t.match(typeMatch)
|
|
541
|
-
)[0];
|
|
542
|
-
}
|
|
543
|
-
if (program.owners) {
|
|
544
|
-
update.owner_ids = stories_default.findOwnerIds(entities, program.owners);
|
|
545
|
-
}
|
|
546
|
-
if (program.epic) {
|
|
547
|
-
update.epic_id = (stories_default.findEpic(entities, program.epic) || {}).id;
|
|
548
|
-
}
|
|
549
|
-
if (program.iteration) {
|
|
550
|
-
update.iteration_id = (stories_default.findIteration(entities, program.iteration) || {}).id;
|
|
551
|
-
}
|
|
552
|
-
if (program.label) {
|
|
553
|
-
update.labels = stories_default.findLabelNames(entities, program.label);
|
|
554
|
-
}
|
|
555
|
-
const hasPositionUpdate = program.moveAfter !== void 0 || program.moveBefore !== void 0 || program.moveDown !== void 0 || program.moveUp !== void 0;
|
|
556
|
-
const hasUpdate = Object.keys(update).length > 0 || hasPositionUpdate;
|
|
557
|
-
debug2("constructed story update", update);
|
|
558
|
-
const gitID = [];
|
|
559
|
-
if (program.fromGit || !program.args.length) {
|
|
560
|
-
debug2("fetching story ID from git");
|
|
561
|
-
let branch = "";
|
|
562
|
-
try {
|
|
563
|
-
branch = (0, import_child_process2.execSync)("git branch").toString("utf-8");
|
|
564
|
-
} catch (e) {
|
|
565
|
-
debug2(e);
|
|
566
|
-
}
|
|
567
|
-
if (branch.match(/\*.*[0-9]+/)) {
|
|
568
|
-
debug2("parsing story ID from git branch:", branch);
|
|
569
|
-
const id = parseInt(branch.match(/\*.*/)[0].match(/\/(ch|sc-)([0-9]+)/)[2], 10);
|
|
570
|
-
debug2("parsed story ID from git branch:", id);
|
|
571
|
-
if (id) {
|
|
572
|
-
gitID.push(id.toString());
|
|
573
|
-
}
|
|
574
|
-
} else {
|
|
575
|
-
stopSpinner();
|
|
576
|
-
logError("No story ID argument present or found in git branch");
|
|
577
|
-
process.exit(2);
|
|
578
|
-
}
|
|
579
|
-
}
|
|
580
|
-
const argIDs = program.args.map((a) => (a.match(/\d+/) || [])[0]);
|
|
581
|
-
argIDs.concat(gitID).map(async (_id) => {
|
|
582
|
-
const id = parseInt(_id, 10);
|
|
583
|
-
let story;
|
|
584
|
-
try {
|
|
585
|
-
if (program.comment) {
|
|
586
|
-
debug2("request comment create");
|
|
587
|
-
await client_default.createStoryComment(id, program.comment);
|
|
588
|
-
debug2("response comment create");
|
|
589
|
-
}
|
|
590
|
-
} catch (e) {
|
|
591
|
-
stopSpinner();
|
|
592
|
-
log2("Error creating comment", id);
|
|
593
|
-
process.exit(3);
|
|
594
|
-
}
|
|
595
|
-
try {
|
|
596
|
-
if (program.task) {
|
|
597
|
-
debug2("request task create");
|
|
598
|
-
await client_default.createTask(id, { description: program.task });
|
|
599
|
-
debug2("response task create");
|
|
600
|
-
}
|
|
601
|
-
} catch (e) {
|
|
602
|
-
stopSpinner();
|
|
603
|
-
log2("Error creating task", id);
|
|
604
|
-
process.exit(3);
|
|
605
|
-
}
|
|
606
|
-
try {
|
|
607
|
-
debug2("request story");
|
|
608
|
-
story = await client_default.getStory(id).then((r) => r.data);
|
|
609
|
-
debug2("response story");
|
|
610
|
-
} catch (e) {
|
|
611
|
-
stopSpinner();
|
|
612
|
-
logError("Error fetching story", id);
|
|
613
|
-
process.exit(4);
|
|
614
|
-
}
|
|
615
|
-
try {
|
|
616
|
-
if (program.taskComplete) {
|
|
617
|
-
debug2("calculating task(s) to complete");
|
|
618
|
-
const descMatch = new RegExp(program.taskComplete, "i");
|
|
619
|
-
const tasks = story.tasks.filter((t) => t.description.match(descMatch));
|
|
620
|
-
const updatedTaskIds = tasks.map((t) => t.id);
|
|
621
|
-
debug2("request tasks complete", updatedTaskIds);
|
|
622
|
-
await Promise.all(
|
|
623
|
-
tasks.map((t) => client_default.updateTask(id, t.id, { complete: !t.complete }))
|
|
624
|
-
);
|
|
625
|
-
debug2("response tasks complete");
|
|
626
|
-
story.tasks = story.tasks.map((t) => {
|
|
627
|
-
if (updatedTaskIds.indexOf(t.id) > -1) t.complete = !t.complete;
|
|
628
|
-
return t;
|
|
629
|
-
});
|
|
630
|
-
}
|
|
631
|
-
} catch (e) {
|
|
632
|
-
stopSpinner();
|
|
633
|
-
log2("Error updating tasks", e);
|
|
634
|
-
process.exit(3);
|
|
635
|
-
}
|
|
636
|
-
try {
|
|
637
|
-
if (hasUpdate) {
|
|
638
|
-
if (hasPositionUpdate) {
|
|
639
|
-
debug2("calculating move up/down");
|
|
640
|
-
const siblings = await stories_default.listStories({
|
|
641
|
-
state: story.workflow_state_id.toString(),
|
|
642
|
-
sort: "state.position:asc,position:asc"
|
|
643
|
-
});
|
|
644
|
-
const siblingIds = siblings.map((s) => s.id);
|
|
645
|
-
const storyIndex = siblingIds.indexOf(~~id);
|
|
646
|
-
if (program.moveAfter) {
|
|
647
|
-
update.after_id = ~~program.moveAfter;
|
|
648
|
-
} else if (program.moveBefore) {
|
|
649
|
-
update.before_id = ~~program.moveBefore;
|
|
650
|
-
} else if (program.moveUp) {
|
|
651
|
-
update.before_id = siblingIds[Math.max(0, storyIndex - (~~program.moveUp || 1))];
|
|
652
|
-
} else if (program.moveDown) {
|
|
653
|
-
update.after_id = siblingIds[Math.min(
|
|
654
|
-
siblings.length - 1,
|
|
655
|
-
storyIndex + (~~program.moveDown || 1)
|
|
656
|
-
)];
|
|
657
|
-
}
|
|
658
|
-
debug2("constructed story position update", update);
|
|
659
|
-
}
|
|
660
|
-
debug2("request story update");
|
|
661
|
-
const changed = await client_default.updateStory(id, update);
|
|
662
|
-
debug2("response story update");
|
|
663
|
-
story = Object.assign({}, story, changed);
|
|
664
|
-
}
|
|
665
|
-
} catch (e) {
|
|
666
|
-
stopSpinner();
|
|
667
|
-
logError("Error updating story", id);
|
|
668
|
-
process.exit(5);
|
|
669
|
-
}
|
|
670
|
-
if (story) {
|
|
671
|
-
story = stories_default.hydrateStory(entities, story);
|
|
672
|
-
}
|
|
673
|
-
if (!program.idonly) spin.stop(true);
|
|
674
|
-
if (story) {
|
|
675
|
-
printStory(story, entities);
|
|
676
|
-
if (program.open) {
|
|
677
|
-
openURL(stories_default.storyURL(story));
|
|
678
|
-
}
|
|
679
|
-
if (program.openEpic) {
|
|
680
|
-
if (!story.epic_id) {
|
|
681
|
-
logError("This story is not part of an epic.");
|
|
682
|
-
process.exit(21);
|
|
683
|
-
}
|
|
684
|
-
openURL(stories_default.buildURL("epic", story.epic_id));
|
|
685
|
-
}
|
|
686
|
-
if (program.openIteration) {
|
|
687
|
-
if (!story.iteration_id) {
|
|
688
|
-
logError("This story is not part of an iteration.");
|
|
689
|
-
process.exit(22);
|
|
690
|
-
}
|
|
691
|
-
openURL(stories_default.buildURL("iteration", story.iteration_id));
|
|
692
|
-
}
|
|
693
|
-
if (program.openProject) {
|
|
694
|
-
openURL(stories_default.buildURL("project", story.project_id));
|
|
695
|
-
}
|
|
696
|
-
}
|
|
697
|
-
if (program.download) {
|
|
698
|
-
downloadFiles(story);
|
|
699
|
-
}
|
|
700
|
-
if (story && program.gitBranch) {
|
|
701
|
-
if (!config3.mentionName) {
|
|
702
|
-
stopSpinner();
|
|
703
|
-
stories_default.checkoutStoryBranch(story, `${story.story_type}-${story.id}-`);
|
|
704
|
-
logError("Error creating story branch in Shortcut format");
|
|
705
|
-
logError(
|
|
706
|
-
'Please run: "short install --force" to add your mention name to the config.'
|
|
707
|
-
);
|
|
708
|
-
process.exit(10);
|
|
709
|
-
}
|
|
710
|
-
stories_default.checkoutStoryBranch(story);
|
|
711
|
-
} else if (story && program.gitBranchShort) {
|
|
712
|
-
stories_default.checkoutStoryBranch(story, `${config3.mentionName}/sc-${story.id}/`);
|
|
713
|
-
}
|
|
714
|
-
});
|
|
715
|
-
stopSpinner();
|
|
716
|
-
};
|
|
717
|
-
var openURL = (url) => {
|
|
718
|
-
const open = import_os2.default.platform() === "darwin" ? "open" : "xdg-open";
|
|
719
|
-
(0, import_child_process2.execSync)(`${open} '${url}'`);
|
|
720
|
-
};
|
|
721
|
-
var stopSpinner = () => {
|
|
722
|
-
if (!(program.idonly || program.quiet)) spin.stop(true);
|
|
723
|
-
};
|
|
724
|
-
var downloadFiles = (story) => story.files.map((file) => {
|
|
725
|
-
import_https.default.get(stories_default.fileURL(file), (res) => {
|
|
726
|
-
const filePath = import_path2.default.join(program.downloadDir, file.name);
|
|
727
|
-
log2(import_chalk2.default.bold("Downloading file to: ") + filePath);
|
|
728
|
-
const stream = import_fs2.default.createWriteStream(filePath);
|
|
729
|
-
res.pipe(stream);
|
|
730
|
-
stream.on("finish", () => stream.close());
|
|
731
|
-
});
|
|
16
|
+
//#region src/bin/short-story.ts
|
|
17
|
+
const config = require_lib_configure.loadConfig();
|
|
18
|
+
const spin = require_lib_spinner.default();
|
|
19
|
+
const log = console.log;
|
|
20
|
+
const logError = console.error;
|
|
21
|
+
const debug$1 = (0, debug.default)("short");
|
|
22
|
+
const program = commander.default.usage("[options] <id>").description("Update and/or display story details").option("-a, --archived", "Update story as archived").option("-c, --comment [text]", "Add comment to story", "").option("-d, --description [text]", "Update description of story", "").option("-D, --download", "Download all attached files", "").option("--download-dir [path]", "Directory to download files to", ".").option("-e, --estimate [number]", "Update estimate of story", "").option("--epic [id|name]", "Set epic of story").option("-i, --iteration [id|name]", "Set iteration of story").option("-f, --format [template]", "Format the story output by template", "").option("--from-git", "Fetch story parsed by ID from current git branch").option("--git-branch", "Checkout git branch from story slug <mention-name>/ch<id>/<type>-<title>\n as required by the Git integration: https://bit.ly/2RKO1FF").option("--git-branch-short", "Checkout git branch from story slug <mention-name>/ch<id>/<title>").option("-I, --idonly", "Print only ID of story results", "").option("-l, --label [id|name]", "Stories with label id/name, by regex", "").option("--move-after [id]", "Move story to position below story ID").option("--move-before [id]", "Move story to position above story ID").option("--move-down [n]", "Move story position downward by n stories").option("--move-up [n]", "Move story position upward by n stories").option("-o, --owners [id|name]", "Update owners of story, comma-separated", "").option("-O, --open", "Open story in browser").option("--oe, --open-epic", "Open story's epic in browser").option("--oi, --open-iteration", "Open story's iteration in browser").option("--op, --open-project", "Open story's project in browser").option("-q, --quiet", "Print only story output, no loading dialog", "").option("-s, --state [id|name]", "Update workflow state of story", "").option("-t, --title [text]", "Update title/name of story", "").option("--task [text]", "Create new task on story").option("--task-complete [text]", "Toggle completion of task on story matching text").option("-y, --type [name]", "Update type of story", "").parse(process.argv);
|
|
23
|
+
const main = async () => {
|
|
24
|
+
const entities = await require_lib_stories.default.fetchEntities();
|
|
25
|
+
if (!(program.idonly || program.quiet)) spin.start();
|
|
26
|
+
debug$1("constructing story update");
|
|
27
|
+
const update = {};
|
|
28
|
+
if (program.archived) update.archived = true;
|
|
29
|
+
if (program.state) update.workflow_state_id = (require_lib_stories.default.findState(entities, program.state) || {}).id;
|
|
30
|
+
if (program.estimate) update.estimate = parseInt(program.estimate, 10);
|
|
31
|
+
if (program.title) update.name = program.title;
|
|
32
|
+
if (program.description) update.description = `${program.description}`;
|
|
33
|
+
if (program.type) {
|
|
34
|
+
const typeMatch = new RegExp(program.type, "i");
|
|
35
|
+
update.story_type = [
|
|
36
|
+
"feature",
|
|
37
|
+
"bug",
|
|
38
|
+
"chore"
|
|
39
|
+
].filter((t) => !!t.match(typeMatch))[0];
|
|
40
|
+
}
|
|
41
|
+
if (program.owners) update.owner_ids = require_lib_stories.default.findOwnerIds(entities, program.owners);
|
|
42
|
+
if (program.epic) update.epic_id = (require_lib_stories.default.findEpic(entities, program.epic) || {}).id;
|
|
43
|
+
if (program.iteration) update.iteration_id = (require_lib_stories.default.findIteration(entities, program.iteration) || {}).id;
|
|
44
|
+
if (program.label) update.labels = require_lib_stories.default.findLabelNames(entities, program.label);
|
|
45
|
+
const hasPositionUpdate = program.moveAfter !== void 0 || program.moveBefore !== void 0 || program.moveDown !== void 0 || program.moveUp !== void 0;
|
|
46
|
+
const hasUpdate = Object.keys(update).length > 0 || hasPositionUpdate;
|
|
47
|
+
debug$1("constructed story update", update);
|
|
48
|
+
const gitID = [];
|
|
49
|
+
if (program.fromGit || !program.args.length) {
|
|
50
|
+
debug$1("fetching story ID from git");
|
|
51
|
+
let branch = "";
|
|
52
|
+
try {
|
|
53
|
+
branch = (0, child_process.execSync)("git branch").toString("utf-8");
|
|
54
|
+
} catch (e) {
|
|
55
|
+
debug$1(e);
|
|
56
|
+
}
|
|
57
|
+
if (branch.match(/\*.*[0-9]+/)) {
|
|
58
|
+
debug$1("parsing story ID from git branch:", branch);
|
|
59
|
+
const id = parseInt(branch.match(/\*.*/)[0].match(/\/(ch|sc-)([0-9]+)/)[2], 10);
|
|
60
|
+
debug$1("parsed story ID from git branch:", id);
|
|
61
|
+
if (id) gitID.push(id.toString());
|
|
62
|
+
} else {
|
|
63
|
+
stopSpinner();
|
|
64
|
+
logError("No story ID argument present or found in git branch");
|
|
65
|
+
process.exit(2);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
const argIDs = program.args.map((a) => (a.match(/\d+/) || [])[0]);
|
|
69
|
+
argIDs.concat(gitID).map(async (_id) => {
|
|
70
|
+
const id = parseInt(_id, 10);
|
|
71
|
+
let story;
|
|
72
|
+
try {
|
|
73
|
+
if (program.comment) {
|
|
74
|
+
debug$1("request comment create");
|
|
75
|
+
await require_lib_client.default.createStoryComment(id, program.comment);
|
|
76
|
+
debug$1("response comment create");
|
|
77
|
+
}
|
|
78
|
+
} catch (e) {
|
|
79
|
+
stopSpinner();
|
|
80
|
+
log("Error creating comment", id);
|
|
81
|
+
process.exit(3);
|
|
82
|
+
}
|
|
83
|
+
try {
|
|
84
|
+
if (program.task) {
|
|
85
|
+
debug$1("request task create");
|
|
86
|
+
await require_lib_client.default.createTask(id, { description: program.task });
|
|
87
|
+
debug$1("response task create");
|
|
88
|
+
}
|
|
89
|
+
} catch (e) {
|
|
90
|
+
stopSpinner();
|
|
91
|
+
log("Error creating task", id);
|
|
92
|
+
process.exit(3);
|
|
93
|
+
}
|
|
94
|
+
try {
|
|
95
|
+
debug$1("request story");
|
|
96
|
+
story = await require_lib_client.default.getStory(id).then((r) => r.data);
|
|
97
|
+
debug$1("response story");
|
|
98
|
+
} catch (e) {
|
|
99
|
+
stopSpinner();
|
|
100
|
+
logError("Error fetching story", id);
|
|
101
|
+
process.exit(4);
|
|
102
|
+
}
|
|
103
|
+
try {
|
|
104
|
+
if (program.taskComplete) {
|
|
105
|
+
debug$1("calculating task(s) to complete");
|
|
106
|
+
const descMatch = new RegExp(program.taskComplete, "i");
|
|
107
|
+
const tasks = story.tasks.filter((t) => t.description.match(descMatch));
|
|
108
|
+
const updatedTaskIds = tasks.map((t) => t.id);
|
|
109
|
+
debug$1("request tasks complete", updatedTaskIds);
|
|
110
|
+
await Promise.all(tasks.map((t) => require_lib_client.default.updateTask(id, t.id, { complete: !t.complete })));
|
|
111
|
+
debug$1("response tasks complete");
|
|
112
|
+
story.tasks = story.tasks.map((t) => {
|
|
113
|
+
if (updatedTaskIds.indexOf(t.id) > -1) t.complete = !t.complete;
|
|
114
|
+
return t;
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
} catch (e) {
|
|
118
|
+
stopSpinner();
|
|
119
|
+
log("Error updating tasks", e);
|
|
120
|
+
process.exit(3);
|
|
121
|
+
}
|
|
122
|
+
try {
|
|
123
|
+
if (hasUpdate) {
|
|
124
|
+
if (hasPositionUpdate) {
|
|
125
|
+
debug$1("calculating move up/down");
|
|
126
|
+
const siblings = await require_lib_stories.default.listStories({
|
|
127
|
+
state: story.workflow_state_id.toString(),
|
|
128
|
+
sort: "state.position:asc,position:asc"
|
|
129
|
+
});
|
|
130
|
+
const siblingIds = siblings.map((s) => s.id);
|
|
131
|
+
const storyIndex = siblingIds.indexOf(~~id);
|
|
132
|
+
if (program.moveAfter) update.after_id = ~~program.moveAfter;
|
|
133
|
+
else if (program.moveBefore) update.before_id = ~~program.moveBefore;
|
|
134
|
+
else if (program.moveUp) update.before_id = siblingIds[Math.max(0, storyIndex - (~~program.moveUp || 1))];
|
|
135
|
+
else if (program.moveDown) update.after_id = siblingIds[Math.min(siblings.length - 1, storyIndex + (~~program.moveDown || 1))];
|
|
136
|
+
debug$1("constructed story position update", update);
|
|
137
|
+
}
|
|
138
|
+
debug$1("request story update");
|
|
139
|
+
const changed = await require_lib_client.default.updateStory(id, update);
|
|
140
|
+
debug$1("response story update");
|
|
141
|
+
story = Object.assign({}, story, changed);
|
|
142
|
+
}
|
|
143
|
+
} catch (e) {
|
|
144
|
+
stopSpinner();
|
|
145
|
+
logError("Error updating story", id);
|
|
146
|
+
process.exit(5);
|
|
147
|
+
}
|
|
148
|
+
if (story) story = require_lib_stories.default.hydrateStory(entities, story);
|
|
149
|
+
if (!program.idonly) spin.stop(true);
|
|
150
|
+
if (story) {
|
|
151
|
+
printStory(story, entities);
|
|
152
|
+
if (program.open) openURL(require_lib_stories.default.storyURL(story));
|
|
153
|
+
if (program.openEpic) {
|
|
154
|
+
if (!story.epic_id) {
|
|
155
|
+
logError("This story is not part of an epic.");
|
|
156
|
+
process.exit(21);
|
|
157
|
+
}
|
|
158
|
+
openURL(require_lib_stories.default.buildURL("epic", story.epic_id));
|
|
159
|
+
}
|
|
160
|
+
if (program.openIteration) {
|
|
161
|
+
if (!story.iteration_id) {
|
|
162
|
+
logError("This story is not part of an iteration.");
|
|
163
|
+
process.exit(22);
|
|
164
|
+
}
|
|
165
|
+
openURL(require_lib_stories.default.buildURL("iteration", story.iteration_id));
|
|
166
|
+
}
|
|
167
|
+
if (program.openProject) openURL(require_lib_stories.default.buildURL("project", story.project_id));
|
|
168
|
+
}
|
|
169
|
+
if (program.download) downloadFiles(story);
|
|
170
|
+
if (story && program.gitBranch) {
|
|
171
|
+
if (!config.mentionName) {
|
|
172
|
+
stopSpinner();
|
|
173
|
+
require_lib_stories.default.checkoutStoryBranch(story, `${story.story_type}-${story.id}-`);
|
|
174
|
+
logError("Error creating story branch in Shortcut format");
|
|
175
|
+
logError("Please run: \"short install --force\" to add your mention name to the config.");
|
|
176
|
+
process.exit(10);
|
|
177
|
+
}
|
|
178
|
+
require_lib_stories.default.checkoutStoryBranch(story);
|
|
179
|
+
} else if (story && program.gitBranchShort) require_lib_stories.default.checkoutStoryBranch(story, `${config.mentionName}/sc-${story.id}/`);
|
|
180
|
+
});
|
|
181
|
+
stopSpinner();
|
|
182
|
+
};
|
|
183
|
+
const openURL = (url) => {
|
|
184
|
+
const open = os.default.platform() === "darwin" ? "open" : "xdg-open";
|
|
185
|
+
(0, child_process.execSync)(`${open} '${url}'`);
|
|
186
|
+
};
|
|
187
|
+
const stopSpinner = () => {
|
|
188
|
+
if (!(program.idonly || program.quiet)) spin.stop(true);
|
|
189
|
+
};
|
|
190
|
+
const downloadFiles = (story) => story.files.map((file) => {
|
|
191
|
+
https.default.get(require_lib_stories.default.fileURL(file), (res) => {
|
|
192
|
+
const filePath = path.default.join(program.downloadDir, file.name);
|
|
193
|
+
log(chalk.default.bold("Downloading file to: ") + filePath);
|
|
194
|
+
const stream = fs.default.createWriteStream(filePath);
|
|
195
|
+
res.pipe(stream);
|
|
196
|
+
stream.on("finish", () => stream.close());
|
|
197
|
+
});
|
|
732
198
|
});
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
if (program.format) {
|
|
738
|
-
return stories_default.printFormattedStory(program)(story);
|
|
739
|
-
}
|
|
740
|
-
stories_default.printDetailedStory(story, entities);
|
|
199
|
+
const printStory = (story, entities) => {
|
|
200
|
+
if (program.idonly) return log(story.id);
|
|
201
|
+
if (program.format) return require_lib_stories.default.printFormattedStory(program)(story);
|
|
202
|
+
require_lib_stories.default.printDetailedStory(story, entities);
|
|
741
203
|
};
|
|
742
204
|
main();
|
|
205
|
+
|
|
206
|
+
//#endregion
|