-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathindex.js
More file actions
85 lines (64 loc) · 2.7 KB
/
Copy pathindex.js
File metadata and controls
85 lines (64 loc) · 2.7 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
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
83
84
85
'use strict';
const core = require('@actions/core');
const { LOCAL_FILE_MISSING } = require('./constants');
const github = require('./github'); // Don't destructure this object to stub with sinon in tests
const {
fetch_other_group_members,
identify_reviewers_by_changed_files,
identify_reviewers_by_author,
should_request_review,
fetch_default_reviewers,
randomly_pick_reviewers,
} = require('./reviewer');
async function run() {
core.info('Fetching configuration file from the source branch');
let config;
try {
config = await github.fetch_config();
} catch (error) {
if (error.status === 404) {
core.warning('No configuration file is found in the base branch; terminating the process');
return;
}
if (error.message === LOCAL_FILE_MISSING) {
core.warning('No configuration file is found locally; terminating the process');
return;
}
throw error;
}
const { title, is_draft, author } = github.get_pull_request();
if (!should_request_review({ title, is_draft, config })) {
core.info('Matched the ignoring rules; terminating the process');
return;
}
core.info('Fetching changed files in the pull request');
const changed_files = await github.fetch_changed_files();
core.info('Identifying reviewers based on the changed files');
const reviewers_based_on_files = identify_reviewers_by_changed_files({ config, changed_files, excludes: [ author ] });
core.info('Identifying reviewers based on the author');
const reviewers_based_on_author = await identify_reviewers_by_author({ config, author });
core.info('Adding other group members to reviewers if group assignment feature is on');
const reviewers_from_same_teams = fetch_other_group_members({ config, author });
let reviewers = [ ...new Set([ ...reviewers_based_on_files, ...reviewers_based_on_author, ...reviewers_from_same_teams ]) ];
if (reviewers.length === 0) {
core.info('Matched no reviewers');
const default_reviewers = fetch_default_reviewers({ config, excludes: [ author ] });
if (default_reviewers.length === 0) {
core.info('No default reviewers are matched; terminating the process');
return;
}
core.info('Falling back to the default reviewers');
reviewers.push(...default_reviewers);
}
core.info('Randomly picking reviewers if the number of reviewers is set');
reviewers = randomly_pick_reviewers({ reviewers, config });
core.info(`Requesting review to ${reviewers.join(', ')}`);
await github.assign_reviewers(reviewers);
}
module.exports = {
run,
};
// Run the action if it's not running in an automated testing environment
if (process.env.NODE_ENV !== 'automated-testing') {
run().catch((error) => core.setFailed(error));
}