Skip to content

Commit 5429dc1

Browse files
committed
[fix] Bot detection of GitHub-reward script
1 parent 45348dc commit 5429dc1

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

.github/scripts/share-reward.ts

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,41 @@ const { author, assignees }: PRMeta = await (
3939
await $`gh pr view ${PR_URL} --json author,assignees`
4040
).json();
4141

42-
const users = [author.login, ...assignees.map(({ login }) => login)];
42+
// Function to check if a user is a Copilot/bot user
43+
function isCopilotUser(login: string): boolean {
44+
const lowerLogin = login.toLowerCase();
45+
return (
46+
lowerLogin.includes('copilot') ||
47+
lowerLogin.includes('[bot]') ||
48+
lowerLogin === 'github-actions[bot]' ||
49+
lowerLogin.endsWith('[bot]')
50+
);
51+
}
52+
53+
// Filter out Copilot and bot users from the list
54+
const allUsers = [author.login, ...assignees.map(({ login }) => login)];
55+
const users = allUsers.filter((login) => !isCopilotUser(login));
56+
57+
console.log(`All users: ${allUsers.join(', ')}`);
58+
console.log(`Filtered users (excluding bots/copilot): ${users.join(', ')}`);
59+
60+
// Handle case where all users are bots/copilot
61+
if (users.length === 0) {
62+
console.log(
63+
'No real users found (all users are bots/copilot). Skipping reward distribution.',
64+
);
65+
console.log(`Filtered users: ${allUsers.join(', ')}`);
66+
process.exit(0);
67+
}
68+
69+
const rewardNumber = parseFloat(reward);
70+
71+
if (isNaN(rewardNumber) || rewardNumber <= 0)
72+
throw new RangeError(
73+
`Reward amount is not a valid number, can not proceed with reward distribution. Received reward value: ${reward}`,
74+
);
4375

44-
const averageReward = (parseFloat(reward) / users.length).toFixed(2);
76+
const averageReward = (rewardNumber / users.length).toFixed(2);
4577

4678
const list: Reward[] = users.map((login) => ({
4779
issue: `#${issueNumber}`,

0 commit comments

Comments
 (0)