forked from Andarist/create-commit-status-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
32 lines (29 loc) · 1.05 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
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 () => {
const sha = core.getInput('sha') || github.context.sha
const state = getRequiredInput('state') as StatusState
const description = core.getInput('description')
const contextInput = getRequiredInput('context')
const context = contextInput.trim().split('\n')
const targetUrl = core.getInput('target_url')
const githubToken = core.getInput('github_token')
const octokit = new github.GitHub(githubToken)
for (const contextElement of context) {
await octokit.repos.createStatus({
...github.context.repo,
sha,
state,
description,
context: contextElement,
...(targetUrl && { target_url: targetUrl })
})
console.log(`Successfully posted a GitHub commit status for ${contextElement}.`)
}
})().catch(error => {
console.error(error)
core.setFailed(error.message)
})