-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.mjs
executable file
·85 lines (67 loc) · 1.81 KB
/
index.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env node
import clipboard from "clipboardy";
import inquirer from "inquirer";
import { fetchMyIssues } from "./fetch.mjs";
const possibleAgrs = {
copyToClipboard: '--copy-to-clipboard',
}
const prompt = inquirer.createPromptModule({ output: process.stderr })
const args = process.argv.slice(2);
const firstArg = args[0];
if (firstArg) {
if (!Object.values(possibleAgrs).includes(firstArg)) {
console.warn("Unknown argument", args[0]);
process.exit(1);
}
}
const { storyType } = await prompt([
{
type: "list",
name: "storyType",
message: "Choose Story Type",
choices: ["feature", "bugfix", "hotfix", "optimization"],
},
]);
const fetchedIssues = await fetchMyIssues();
// mapped to name value for the select
const issues = fetchedIssues.map((issue) => ({
name: issue.key + ": " + issue.title,
value: issue,
}));
const { selectedIssue } = await prompt([
{
type: "list",
name: "selectedIssue",
message: "Choose Issue",
choices: issues,
},
]);
const passedTitle = selectedIssue.title
.toLowerCase()
.replace(" - ", " ")
.replace(/\s/g, "-")
.replace(/[^a-z0-9\-]/gi, "");
let branchName = `${storyType}/${selectedIssue.key}-${passedTitle}`;
const questions = [
{
type: "editor",
name: "editedBranchname",
message: "Edit Branchname",
default: branchName,
waitUserInput: true,
},
];
// ask to shorten name until short enough
while (branchName.length > 54) {
console.error("Branchname too long ", branchName.length);
branchName = await prompt(questions).then((answers) => {
return answers?.editedBranchname?.trim();
});
}
branchName.toLowerCase();
if (firstArg === possibleAgrs.copyToClipboard) {
clipboard.writeSync(branchName);
console.log("copied -", branchName, "- to clipboard");
process.exit(0);
}
console.log(branchName);