forked from bbarry/github-markdown-builder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction-handler.ts
More file actions
46 lines (38 loc) · 1.41 KB
/
action-handler.ts
File metadata and controls
46 lines (38 loc) · 1.41 KB
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
import * as core from '@actions/core'
import { readTemplate, readJsonFile } from '../utils/file-utils'
import { generateMarkdown } from '../utils/markdown-utils'
import { getAllGitHubContext } from 'src/utils/github-utils'
import { addCommentToPullRequest } from 'src/client/github'
import { context } from '@actions/github'
export async function runAction(): Promise<void> {
try {
const templatePath = core.getInput('template-file-path', {
required: true
})
const jsonFilePath = core.getInput('json-file-path')
const summary = core.getBooleanInput('summary')
const pullRequest = core.getBooleanInput('pull-request')
const templateSource = readTemplate(templatePath)
const jsonData = jsonFilePath ? readJsonFile(jsonFilePath) : {}
const markdown = generateMarkdown(templateSource, jsonData)
if (pullRequest && context.eventName === 'pull_request') {
await addCommentToPullRequest(
context.repo.owner,
context.repo.repo,
context.issue.number,
markdown
)
}
console.log('Generated Markdown:')
console.log(markdown)
if (summary) core.summary.addRaw(markdown).write()
getAllGitHubContext()
core.setOutput('markdown', markdown)
} catch (error) {
if (error instanceof Error) {
core.setFailed(`Action failed with error: ${error.message}`)
} else {
core.setFailed('Action failed with an unknown error')
}
}
}