-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
82 lines (78 loc) · 2.51 KB
/
main.js
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import * as core from '@actions/core'
import * as github from '@actions/github'
import parseJson from 'parse-json'
import * as fs from 'fs'
async function run() {
try {
var context = github.context
// payload-based values
var owner = context.repo.owner ?? context.payload.repository.owner
var repo = context.repo.repo ?? context.payload.repository.name
var head_sha = (context.payload.pull_request && context.payload.pull_request.head.sha) ?? context.sha
// input values
var name = core.getInput("name")
var status = core.getInput("status")
var conclusion = core.getInput("conclusion")
var outputTitle = core.getInput("output_title")
var outputSummary = core.getInput("output_summary")
var outputText = ""
if (core.getInput("output_text") != "") {
outputText = core.getInput("output_text")
} else if (core.getInput("output_source_file") != "") {
outputText = fs.readFileSync(core.getInput("output_source_file"), 'utf8')
}
var outputAnnotations = core.getInput("output_annotations")
if (outputAnnotations != "") {
outputAnnotations = parseJson(core.getInput("output_annotations"))
} else {
outputAnnotations = []
}
var outputImages = core.getInput("output_annotations")
if (outputImages != "") {
outputImages = parseJson(core.getInput("output_images"))
} else {
outputImages = []
}
var res
// Create or update check run
if (core.getInput("check_run_id")) {
// update check run
res = await github.getOctokit(core.getInput("token")).rest.checks.update({
owner: owner,
repo: repo,
check_run_id: core.getInput("check_run_id"),
name: name,
status: status,
conclusion: conclusion,
output: {
title: outputTitle,
summary: outputSummary,
text: outputText,
annotations: outputAnnotations,
images: outputImages
},
})
} else {
// create check run
res = await github.getOctokit(core.getInput("token")).rest.checks.create({
owner: owner,
repo: repo,
head_sha: head_sha,
name: name,
status: status,
conclusion: conclusion,
output: {
title: outputTitle,
summary: outputSummary,
text: outputText,
annotations: outputAnnotations,
images: outputImages
},
})
}
core.setOutput("check_run_id", res.data.id)
} catch (error) {
core.setFailed(error.message);
}
}
run()