Skip to content

Instantly share code, notes, and snippets.

@wtfaremyinitials
Created June 12, 2020 20:37
Show Gist options
  • Save wtfaremyinitials/cb2a8c6dd802c256f3123a20844930b6 to your computer and use it in GitHub Desktop.
Save wtfaremyinitials/cb2a8c6dd802c256f3123a20844930b6 to your computer and use it in GitHub Desktop.
#!/usr/bin/env -S deno run --allow-run --allow-write
import sh from 'https://denopkg.com/wtfaremyinitials/deno-shell-tag/mod.js'
// TODO: integrate clubhouse api for ticket titles, blockers, and today
const LOW_MINUTES_THRESHOLD = 10
const SECONDS_TO_MINUTES = 1 / (1000 * 60)
const IGNORE_TAGS = ['billable', 'pingthings', 'standup', 'work']
const TICKET_REGEX = /ch(\d{4})/
function parse_date (str) {
return Date.parse(
str.slice(0, 4) +
'-' +
str.slice(4, 6) +
'-' +
str.slice(6, 8) +
'T' +
str.slice(9, 11) +
':' +
str.slice(11, 13) +
':' +
str.slice(13, 15) +
'Z'
)
}
function format_ticket(str) {
return `[CH-${str.match(TICKET_REGEX)[1]}]`
}
async function shell(command) {
return (await Deno.run({ cmd: ['sh', '-c', command] })).status()
}
function open_editor(filepath) {
return shell(`$EDITOR ${filepath}`)
}
function copy_file_to_clipboard(filepath) {
return shell(`wl-copy < ${filepath}`)
}
let data = JSON.parse(await sh`timew export pingthings :yesterday`)
let summary = {}
for (let range of data) {
let minutes = Math.round(
(parse_date(range.end) - parse_date(range.start)) * SECONDS_TO_MINUTES
)
for (let tag of range.tags) {
if (IGNORE_TAGS.includes(tag)) continue
if (!summary[tag]) summary[tag] = 0
summary[tag] += minutes
}
}
let previously = ''
for (let tag in summary) {
if (TICKET_REGEX.test(tag)) tag = format_ticket(tag)
if (summary[tag] < LOW_MINUTES_THRESHOLD) tag += '?'
previously += `- ${tag} \n`
}
previously = previously.trim()
let doc = `*Previously*
${previously}
*Today*
-
*Blockers*
-
`
let filepath = `/tmp/standup-${Date.now()}.txt`
let file = await Deno.open(filepath, { write: true, create: true })
await Deno.writeAll(file, new TextEncoder().encode(doc))
await Deno.close(file.rid)
await open_editor(filepath)
await copy_file_to_clipboard(filepath)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment