@@ -40,75 +40,79 @@ jobs:
40
40
retries : 5 # retry GitHub API requests up to 5 times, with exponential backoff
41
41
retry-exempt-status-codes : 403
42
42
script : |
43
- if (context.payload.pull_request.assignees.length === 0) {
44
- const prAuthor = context.payload.pull_request.user.login;
43
+ const prAssignees = context.payload.pull_request.assignees
44
+ console.log('prAssignees: ', prAssignees);
45
+ if (prAssignees.length >= 1) {
46
+ console.log('Pull request already has at least one assignee. Will not assign any new assignees.');
47
+ return;
48
+ }
49
+ const prAuthor = context.payload.pull_request.user.login;
45
50
46
- // Check if the PR is opened by a collaborator on the repo (aka a committer)
47
- // We use the /repos/{owner}/{repo}/collaborators/{username} endpoint to avoid
48
- // neeing org scope permissions
49
- // TODO: Uncomment the following lines:
50
- // const { data: isCollaborator } = await github.rest.repos.checkCollaborator({
51
- // owner: context.repo.owner,
52
- // repo: context.repo.repo,
53
- // username: prAuthor,
54
- // });
55
- const isCollaborator = false; // TODO: Delete this line
51
+ // Check if the PR is opened by a collaborator on the repo (aka a committer)
52
+ // We use the /repos/{owner}/{repo}/collaborators/{username} endpoint to avoid
53
+ // neeing org scope permissions
54
+ // TODO: Uncomment the following lines:
55
+ // const { data: isCollaborator } = await github.rest.repos.checkCollaborator({
56
+ // owner: context.repo.owner,
57
+ // repo: context.repo.repo,
58
+ // username: prAuthor,
59
+ // });
60
+ const isCollaborator = false; // TODO: Delete this line
56
61
57
- console.log('prAuthor: ', prAuthor);
58
- console.log('isCollaborator: ', isCollaborator);
62
+ console.log('prAuthor: ', prAuthor);
63
+ console.log('isCollaborator: ', isCollaborator);
59
64
60
- // Load the list of assignable reviewres the JuliaLang/pr-assignment repo
61
- // at https://github.com/JuliaLang/pr-assignment/blob/main/users.txt
62
- // NOTE to reviewers: If you want to be assigned to new PRs, please add your
63
- // GitHub username to that file
65
+ // Load the list of assignable reviewres the JuliaLang/pr-assignment repo
66
+ // at https://github.com/JuliaLang/pr-assignment/blob/main/users.txt
67
+ // NOTE to reviewers: If you want to be assigned to new PRs, please add your
68
+ // GitHub username to that file
64
69
65
- // Load file contents
66
- const { data: fileContentsObj } = await github.rest.repos.getContent({
67
- owner: 'JuliaLang',
68
- repo: 'pr-assignment',
69
- path: 'users.txt',
70
- ref: 'main',
71
- });
70
+ // Load file contents
71
+ const { data: fileContentsObj } = await github.rest.repos.getContent({
72
+ owner: 'JuliaLang',
73
+ repo: 'pr-assignment',
74
+ path: 'users.txt',
75
+ ref: 'main',
76
+ });
72
77
73
- const fileContentsBufferObj = Buffer.from(fileContentsObj.content, "base64");
74
- const fileContentsText = fileContentsBufferObj.toString("utf8");
78
+ const fileContentsBufferObj = Buffer.from(fileContentsObj.content, "base64");
79
+ const fileContentsText = fileContentsBufferObj.toString("utf8");
75
80
76
- // Find lines that match ^(@[a-zA-Z0-9]+)(\s*#.*)?\n$ and extract the usernames
77
- // const regex = /^(@[a-zA-Z0-9]+)(\s*#.*)?\n$/; // TODO: Fix this regex.
78
- const regex = /^(.*?)$/;
79
- const reviewer_candidates = fileContentsText
80
- .split('\n')
81
- .map(line => line.trim())
82
- .map(line => line.match(regex))
83
- .filter(match => match !== null)
84
- .map(match => match[1].substring(1)); // Remove the @ symbol
85
- console.log('reviewer_candidates: ', reviewer_candidates);
81
+ // Find lines that match ^(@[a-zA-Z0-9]+)(\s*#.*)?\n$ and extract the usernames
82
+ // const regex = /^(@[a-zA-Z0-9]+)(\s*#.*)?\n$/; // TODO: Fix this regex.
83
+ const regex = /^(.*?)$/;
84
+ const reviewer_candidates = fileContentsText
85
+ .split('\n')
86
+ .map(line => line.trim())
87
+ .map(line => line.match(regex))
88
+ .filter(match => match !== null)
89
+ .map(match => match[1].substring(1)); // Remove the @ symbol
90
+ console.log('reviewer_candidates: ', reviewer_candidates);
86
91
87
- if (reviewer_candidates.length < 1) {
88
- const error_msg = 'ERROR: Could not find any reviewer_candidates';
89
- console.error(error_msg);
90
- throw new Error(error_msg);
91
- }
92
+ if (reviewer_candidates.length < 1) {
93
+ const error_msg = 'ERROR: Could not find any reviewer_candidates';
94
+ console.error(error_msg);
95
+ throw new Error(error_msg);
96
+ }
92
97
93
- if (isCollaborator) {
94
- // The PR author is a committer, so we skip assigning them
95
- console.log('Skipping PR authored by committer: ', prAuthor);
96
- return;
97
- }
98
+ if (isCollaborator) {
99
+ // The PR author is a committer, so we skip assigning them
100
+ console.log('Skipping PR authored by committer: ', prAuthor);
101
+ return;
102
+ }
98
103
99
- // Assign random committer
100
- await github.rest.issues.addAssignees({
101
- owner: context.repo.owner,
102
- repo: context.repo.repo,
103
- issue_number: context.payload.pull_request.number,
104
- assignees: reviewer_candidates[Math.floor(Math.random()*reviewer_candidates.length)],
105
- });
104
+ // Assign random committer
105
+ await github.rest.issues.addAssignees({
106
+ owner: context.repo.owner,
107
+ repo: context.repo.repo,
108
+ issue_number: context.payload.pull_request.number,
109
+ assignees: reviewer_candidates[Math.floor(Math.random()*reviewer_candidates.length)],
110
+ });
106
111
107
- // Add the "pr review" label
108
- await github.rest.issues.addLabels({
109
- owner: context.repo.owner,
110
- repo: context.repo.repo,
111
- issue_number: context.payload.pull_request.number,
112
- labels: ['status: waiting for PR reviewer'],
113
- });
114
- }
112
+ // Add the "pr review" label
113
+ await github.rest.issues.addLabels({
114
+ owner: context.repo.owner,
115
+ repo: context.repo.repo,
116
+ issue_number: context.payload.pull_request.number,
117
+ labels: ['status: waiting for PR reviewer'],
118
+ });
0 commit comments