-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate-task-in-height.ts
More file actions
executable file
·70 lines (58 loc) · 2.06 KB
/
Copy pathcreate-task-in-height.ts
File metadata and controls
executable file
·70 lines (58 loc) · 2.06 KB
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
#!/usr/bin/env -S deno run --allow-read=.env,.env.defaults --allow-env --allow-net
// Required parameters:
// @raycast.schemaVersion 1
// @raycast.title Create todo in Height app
// @raycast.mode compact
// Optional parameters:
// @raycast.icon ✅
// @raycast.argument1 { "type": "text", "placeholder": "name" }
// @raycast.argument2 { "type": "text", "placeholder": "effort", "optional": true }
// @raycast.argument3 { "type": "text", "placeholder": "priority", "optional": true }
// Documentation:
// @raycast.author @atenni
// @raycast.authorURL https://github.com/atenni/raycast-scripts
// @raycast.description Create a todo in the Height app, with an optional effort and priority.
import { config as loadConfig } from "https://deno.land/std@0.157.0/dotenv/mod.ts";
const config = await loadConfig();
async function main() {
const [name, effort, priority] = Deno.args; // `effort` and `priority` are empty strings if not provided
let feedback = "Success!";
// Create fields array
const fields = [];
// Map effort to its UUID
if (["1", "2", "3"].includes(effort)) {
fields.push({
fieldTemplateId: config["HEIGHT_EFFORT_FIELD_TEMPLATE_UUID"],
value: config[`HEIGHT_EFFORT_${effort}_UUID`],
});
} else if (effort) {
feedback = `${feedback} Effort ignored - must be 1, 2, or 3.`;
}
// Map priority to its UUID
if (["1", "2", "3"].includes(priority)) {
fields.push({
fieldTemplateId: config["HEIGHT_PRIORITY_FIELD_TEMPLATE_UUID"],
value: config[`HEIGHT_PRIORITY_${priority}_UUID`],
});
} else if (priority) {
feedback = `${feedback} Priority ignored - must be 1, 2, or 3.`;
}
// Add the task to the default list
await fetch(`${config["HEIGHT_BASE_URL"]}/tasks`, {
method: "POST",
headers: {
"Authorization": `api-key ${config["HEIGHT_SECRET_KEY"]}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
name,
listIds: [config["HEIGHT_DEFAULT_LIST_UUID"]],
fields,
}),
});
console.log(feedback);
}
main().catch((err) => {
console.error(err);
Deno.exit(1);
});