-
-
Notifications
You must be signed in to change notification settings - Fork 57
/
handler.ts
56 lines (43 loc) 路 1.51 KB
/
handler.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
import { Context } from 'probot'
import { PullRequest } from './pull_request'
import { chooseUsers, includesSkipKeywords } from './util'
interface AppConfig {
addReviewers: boolean,
addAssignees: boolean,
reviewers: string[],
assignees?: string[],
numberOfAssignees?: number,
numberOfReviewers: number,
skipKeywords?: string[]
}
export async function handlePullRequest (context: Context): Promise<void> {
let config: AppConfig | null
config = await context.config<AppConfig | null>('auto_assign.yml')
if (!config) {
throw new Error('the configuration file failed to load')
}
const payload = context.payload
const prNumber = payload.number
const repo = payload.repository.name
const owner = payload.repository.owner.login
const title = payload.pull_request.title
if (config.skipKeywords && includesSkipKeywords(title, config.skipKeywords)) {
context.log('skips adding reviewers')
return
}
const reviewers = chooseUsers(owner, config.reviewers, config.numberOfReviewers)
const pullRequest = new PullRequest(context)
let result: Promise<any>
if (config.addReviewers) {
result = await pullRequest.addReviewers(owner, repo, prNumber, reviewers)
context.log(result)
}
if (config.addAssignees) {
const assignees: string[] = config.assignees ?
chooseUsers(owner, config.assignees, config.numberOfAssignees || config.numberOfReviewers)
:
reviewers
result = await pullRequest.addAssignees(owner, repo, prNumber, assignees)
context.log(result)
}
}