-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.ts
39 lines (32 loc) · 1.04 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
import * as core from '@actions/core'
import * as github from '@actions/github'
type StatusState = 'error' | 'failure' | 'pending' | 'success'
const getRequiredInput = (name: string): string =>
core.getInput(name, { required: true })
;(async () => {
let githubToken = process.env.GITHUB_TOKEN
if (!githubToken) {
core.setFailed(
'Please add the `GITHUB_TOKEN` to the report commit status action.',
)
return
}
const octokit = new github.GitHub(githubToken)
const sha = core.getInput('sha') || github.context.sha
const state = getRequiredInput('state') as StatusState
const description = getRequiredInput('description')
const context = getRequiredInput('context')
const targetUrl = core.getInput('target_url')
await octokit.repos.createStatus({
...github.context.repo,
sha,
state,
description,
context,
...(targetUrl && { target_url: targetUrl }),
})
console.log('Successfully posted a GitHub commit status.')
})().catch(error => {
console.error(error)
core.setFailed(error.message)
})