Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions actions/setup/js/add_reviewer.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,24 @@ const { COPILOT_REVIEWER_BOT } = require("./constants.cjs");
* @type {HandlerFactoryFunction}
*/
async function main(config = {}) {
// Extract configuration
const allowedReviewers = config.allowed || [];
const maxCount = config.max || 10;
const allowedReviewers = config.allowed ?? [];
const maxCount = config.max ?? 10;
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maxCount now uses config.max ?? 10, which changes behavior when config.max is 0: the handler will immediately start skipping all messages because processedCount >= 0 is true on the first call. Elsewhere in this codebase, max values are treated as positive integers and 0 is commonly either rejected or treated as “unset” (e.g., safe_output_type_validator.cjs only honors truthy config.max). Consider either validating config.max to be a positive integer here (and failing fast on 0/negatives) or preserving the previous defaulting behavior so a misconfigured 0 doesn’t silently disable the handler.

Suggested change
const maxCount = config.max ?? 10;
const maxCount = Number.isInteger(config.max) && config.max > 0 ? config.max : 10;

Copilot uses AI. Check for mistakes.
const githubClient = await createAuthenticatedGitHubClient(config);

// Check if we're in staged mode
const isStaged = isStagedMode(config);

core.info(`Add reviewer configuration: max=${maxCount}`);
if (allowedReviewers.length > 0) {
core.info(`Allowed reviewers: ${allowedReviewers.join(", ")}`);
}

// Track how many items we've processed for max limit
let processedCount = 0;

/**
* Message handler function that processes a single add_reviewer message
* @param {Object} message - The add_reviewer message to process
* @param {Object} resolvedTemporaryIds - Map of temporary IDs to {repo, number}
* @returns {Promise<Object>} Result with success/error status
*/
return async function handleAddReviewer(message, resolvedTemporaryIds) {
// Check if we've hit the max limit
if (processedCount >= maxCount) {
core.warning(`Skipping add_reviewer: max count of ${maxCount} reached`);
return {
Expand All @@ -53,7 +47,6 @@ async function main(config = {}) {

processedCount++;

// Determine PR number using helper
const { prNumber, error } = getPullRequestNumber(message, context);

if (error) {
Expand All @@ -64,7 +57,7 @@ async function main(config = {}) {
};
}

const requestedReviewers = message.reviewers || [];
const requestedReviewers = message.reviewers ?? [];
core.info(`Requested reviewers: ${JSON.stringify(requestedReviewers)}`);

// Use shared helper to filter, sanitize, dedupe, and limit
Expand Down
Loading