forked from JulienKode/team-labeler-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.ts
49 lines (42 loc) · 1.3 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
import * as core from '@actions/core'
import {getTeamLabel} from './teams'
import {
getPrNumber,
getPrAuthor,
getLabelsConfiguration,
addLabels,
createClient
} from './github'
async function run() {
try {
const token = core.getInput('repo-token', {required: true})
const configPath = core.getInput('configuration-path', {required: true})
const teamsRepo = core.getInput('teams-repo', {required: false})
const teamsBranch = core.getInput('teams-branch', {required: false})
const prNumber = getPrNumber()
if (!prNumber) {
core.info('Could not get pull request number from context, exiting')
return
}
const author = getPrAuthor()
if (!author) {
core.info('Could not get pull request user from context, exiting')
return
}
const client = createClient(token)
const labelsConfiguration: Map<string, string[]> =
await getLabelsConfiguration(
client,
configPath,
teamsRepo !== '' ? {repo: teamsRepo, ref: teamsBranch} : undefined
)
const labels: string[] = getTeamLabel(labelsConfiguration, `@${author}`)
if (labels.length > 0) await addLabels(client, prNumber, labels)
} catch (error) {
if (error instanceof Error) {
core.error(error)
core.setFailed(error.message)
}
}
}
run()