forked from ebram-va/sdelements-advsync
-
Notifications
You must be signed in to change notification settings - Fork 0
/
runner.js
104 lines (95 loc) · 3.21 KB
/
runner.js
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/env node
const commandLineArgs = require('command-line-args');
const commandLineUsage = require('command-line-usage');
const SDElements = require('./sdelements');
const cmdOptions = [
{ name: 'url', alias: 'u', type: String },
{ name: 'apitoken', alias: 't', type: String },
{ name: 'project', alias: 'p', type: String },
{ name: 'title', type: String },
{ name: 'tags', type: String },
{ name: 'help', alias: 'h', type: Boolean }
]
const sections = [
{
header: 'SD Elements Runner',
content: 'Run actions against your project in SD Elements'
},
{
header: 'Options',
optionList: [
{
name: 'url',
typeLabel: '{underline url}',
description: 'The base URL for your SD Elements account'
},
{
name: 'apitoken',
typeLabel: '{underline apitoken}',
description: 'The api token from your SD Elements Account'
},
{
name: 'project',
typeLabel: '{underline project}',
description: 'The project ID you want to use'
},
{
name: 'title',
typeLabel: '{underline title}',
description: 'The title of a task'
},
{
name: 'tags',
typeLabel: '{underline title}',
description: 'The tags to add to a task'
},
{
name: 'help',
description: 'Print this usage guide'
}
]
}
]
async function run() {
try {
const options = commandLineArgs(cmdOptions)
if(options.help) {
const usage = commandLineUsage(sections)
console.log(usage)
} else {
if(!(options.url)) {
console.error("--url is a required argument");
return;
}
if(!(options.apitoken)) {
console.error("--apitoken is a required argument");
return;
}
if(!(options.project)) {
console.error("--project is a required argument");
return;
}
const sdelements = new SDElements(options.url, options.apitoken, options.project);
if(options.title) {
console.log("Getting task from title");
const task = await sdelements.findTaskFromIssueTitle(options.title);
console.log(task);
if(options.tags) {
console.log("Adding tags to task")
const tags = options.tags.split(',')
await sdelements.assignTagsToTask(task.id, tags)
}
} else {
console.log("Getting tasks");
const tasks = await sdelements.getTasks();
console.log(`Found ${tasks.length} tasks`);
console.log("Getting random task");
const singleTask = await sdelements.getTask(tasks[0].task_id);
console.log(singleTask);
}
}
} catch(e) {
console.error(e);
}
}
run();