Skip to content

Commit 9312c73

Browse files
committed
Refine mentor bot safeguards
Signed-off-by: Mounil <[email protected]>
1 parent f7c8c78 commit 9312c73

File tree

1 file changed

+5
-57
lines changed

1 file changed

+5
-57
lines changed

.github/scripts/bot-mentor-assignment.js

Lines changed: 5 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -36,69 +36,25 @@ function loadMentorRoster() {
3636
}
3737
}
3838

39-
function selectMentor(roster, mentee) {
39+
function selectMentor(roster) {
4040
if (!Array.isArray(roster) || roster.length === 0) {
4141
throw new Error('Mentor roster must contain at least one entry.');
4242
}
4343

4444
const MILLISECONDS_PER_DAY = 24 * 60 * 60 * 1000;
4545
const dayNumber = Math.floor(Date.now() / MILLISECONDS_PER_DAY); // UTC day index
46-
const baseIndex = dayNumber % roster.length;
47-
const normalizedMentee = typeof mentee === 'string' ? mentee.toLowerCase() : null;
46+
const index = dayNumber % roster.length;
4847

49-
for (let offset = 0; offset < roster.length; offset += 1) {
50-
const candidate = roster[(baseIndex + offset) % roster.length];
51-
52-
if (!normalizedMentee || candidate.toLowerCase() !== normalizedMentee) {
53-
return candidate;
54-
}
55-
}
56-
57-
return null;
48+
return roster[index];
5849
}
5950

6051
function hasGoodFirstIssueLabel(issue) {
6152
return (issue.labels || []).some((label) => {
6253
const name = typeof label === 'string' ? label : label?.name;
63-
return typeof name === 'string' && name === 'Good First Issue';
54+
return typeof name === 'string' && name.toLowerCase() === 'good first issue';
6455
});
6556
}
6657

67-
async function hasActiveMentorAssignment(github, owner, repo, mentee, currentIssueNumber) {
68-
try {
69-
const assignedIssues = await github.paginate(
70-
github.rest.issues.listForRepo,
71-
{
72-
owner,
73-
repo,
74-
assignee: mentee,
75-
state: 'open',
76-
per_page: 100,
77-
},
78-
(response) =>
79-
(response.data || []).filter((issue) => issue?.number && issue.number !== currentIssueNumber),
80-
);
81-
82-
for (const assignedIssue of assignedIssues) {
83-
const comments = await github.paginate(github.rest.issues.listComments, {
84-
owner,
85-
repo,
86-
issue_number: assignedIssue.number,
87-
per_page: 100,
88-
});
89-
90-
if (comments.some((comment) => comment.body?.includes(COMMENT_MARKER))) {
91-
return true;
92-
}
93-
}
94-
} catch (error) {
95-
const message = error instanceof Error ? error.message : String(error);
96-
console.log(`Unable to detect existing mentor assignments for ${mentee}: ${message}`);
97-
}
98-
99-
return false;
100-
}
101-
10258
async function isNewContributor(github, owner, repo, login) {
10359
const query = `repo:${owner}/${repo} type:pr state:closed is:merged author:${login}`;
10460

@@ -176,16 +132,8 @@ module.exports = async ({ github, context }) => {
176132
return console.log(`${mentee} already has merged contributions. Skipping mentor assignment.`);
177133
}
178134

179-
if (await hasActiveMentorAssignment(github, owner, repo, mentee, issue.number)) {
180-
return console.log(`${mentee} already has an active mentor assignment comment on another issue. Skipping.`);
181-
}
182-
183135
const roster = loadMentorRoster();
184-
const mentor = selectMentor(roster, mentee);
185-
186-
if (!mentor) {
187-
return console.log(`No eligible mentor (excluding mentee ${mentee}) found. Skipping mentor assignment.`);
188-
}
136+
const mentor = selectMentor(roster);
189137

190138
console.log(`Assigning mentor @${mentor} to mentee @${mentee} for issue #${issue.number}.`);
191139

0 commit comments

Comments
 (0)