/
main.ts
60 lines (52 loc) · 2.11 KB
/
main.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import * as core from '@actions/core'
import * as github from '@actions/github'
import { RequestError } from '@octokit/request-error'
import * as verifiedCommits from './dependabot/verified_commits'
import * as updateMetadata from './dependabot/update_metadata'
import * as output from './dependabot/output'
import * as util from './dependabot/util'
export async function run (): Promise<void> {
const token = core.getInput('github-token')
if (!token) {
/* eslint-disable no-template-curly-in-string */
core.setFailed(
'github-token is not set! Please add \'github-token: "${{ secrets.GITHUB_TOKEN }}"\' to your workflow file.'
)
/* eslint-enable no-template-curly-in-string */
return
}
try {
const githubClient = github.getOctokit(token)
// Validate the job
const commitMessage = await verifiedCommits.getMessage(githubClient, github.context, core.getBooleanInput('skip-commit-verification'))
const branchNames = util.getBranchNames(github.context)
let alertLookup: updateMetadata.alertLookup | undefined
if (core.getInput('alert-lookup')) {
alertLookup = (name, version, directory) => verifiedCommits.getAlert(name, version, directory, githubClient, github.context)
}
const scoreLookup = core.getInput('compat-lookup') ? verifiedCommits.getCompatibility : undefined
if (commitMessage) {
// Parse metadata
core.info('Parsing Dependabot metadata')
const updatedDependencies = await updateMetadata.parse(commitMessage, branchNames.headName, branchNames.baseName, alertLookup, scoreLookup)
if (updatedDependencies.length > 0) {
output.set(updatedDependencies)
} else {
core.setFailed('PR does not contain metadata, nothing to do.')
}
} else {
core.setFailed('PR is not from Dependabot, nothing to do.')
}
} catch (error) {
if (error instanceof RequestError) {
core.setFailed(`Api Error: (${error.status}) ${error.message}`)
return
}
if (error instanceof Error) {
core.setFailed(error.message)
} else {
core.setFailed('There was an unexpected error.')
}
}
}
run()