-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
57 lines (47 loc) · 1.29 KB
/
index.ts
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
import { lexer } from 'marked'
import * as github from '@actions/github'
import { getInput } from '@actions/core'
import { exit } from 'process'
const slug = process.env.GITHUB_REPOSITORY!
const [owner, repo] = slug.split('/')
const issue_number = parseInt((getInput('today') || process.env.GTD_TODAY)!)
const token = getInput('token')!
const octokit = github.getOctokit(token)
const body = getInput('body')
const comments = await octokit.rest.issues.listComments({
owner,
repo,
issue_number
})
console.log(`creating new now-now: ${body}`)
let out = ''
for (const comment of comments.data) {
if (!comment.body) continue
//FIXME won’t work if eg. there’s a `# Right Now`
const start = comment.body.trim()
if (!start.startsWith('## Now Now') && !start.startsWith("## Right Now")) continue
//FIXME ^^ not sufficient
for (const item of lexer(comment.body)) {
if (item.type === 'heading' && item.text == 'Just Now') {
out = `${out.trim()}
- [ ] ${body.trim()}
`
}
out += item.raw
}
await octokit.rest.issues.updateComment({
owner,
repo,
comment_id: comment.id,
body: out
})
// only once thanks
exit(0)
}
// found nothing, add a new comment
await octokit.rest.issues.createComment({
owner,
repo,
issue_number,
body: `# Now Now\n${body}`
})