-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
44 lines (34 loc) · 965 Bytes
/
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
import * as github from '@actions/github'
import { debug, getInput, warning } from '@actions/core'
import { exit } from 'process'
import { getForecast } from './engine'
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 lat = getInput('latitude')
const lng = getInput('longitude')
if (lat == undefined || lng == undefined) {
warning("latitude & longitude must be specified")
exit(0)
}
debug(`lat: ${lat}`)
debug(`lng: ${lng}`)
const forecast = await getForecast(lat, lng)
if (!forecast) {
warning("No forecast found ¯\_(ツ)_/¯")
exit(0)
}
let body = await octokit.rest.issues.get({ owner, repo, issue_number }).then(x => x.data.body)
body = `
${body}
### Forecast
${forecast}
`
await octokit.rest.issues.update({
owner,
repo,
issue_number,
body
})