@@ -9,7 +9,7 @@ const { getErrorMessage } = require("./error_helpers.cjs");
99const { getPRNumber } = require ( "./update_context_helpers.cjs" ) ;
1010const { logStagedPreviewInfo } = require ( "./staged_preview.cjs" ) ;
1111const { createAuthenticatedGitHubClient } = require ( "./handler_auth.cjs" ) ;
12- const { resolveTargetRepoConfig } = require ( "./repo_helpers.cjs" ) ;
12+ const { resolveTargetRepoConfig, validateTargetRepo } = require ( "./repo_helpers.cjs" ) ;
1313
1414/**
1515 * Type constant for handler identification
@@ -21,7 +21,7 @@ const HANDLER_TYPE = "resolve_pull_request_review_thread";
2121 * Used to validate the thread before resolving.
2222 * @param {any } github - GitHub GraphQL instance
2323 * @param {string } threadId - Review thread node ID (e.g., 'PRRT_kwDOABCD...')
24- * @returns {Promise<{prNumber: number, repoNameWithOwner: string}|null> } The PR number and repo, or null if not found
24+ * @returns {Promise<{prNumber: number, repoNameWithOwner: string|null }|null> } The PR number and repo, or null if not found
2525 */
2626async function getThreadPullRequestInfo ( github , threadId ) {
2727 const query = /* GraphQL */ `
@@ -92,9 +92,10 @@ async function main(config = {}) {
9292 const resolveTarget = config . target || "triggering" ;
9393 const { defaultTargetRepo, allowedRepos } = resolveTargetRepoConfig ( config ) ;
9494
95- // Normalize repo names to lowercase once for case-insensitive comparison during validation
96- const normalizedDefaultTargetRepo = defaultTargetRepo ? defaultTargetRepo . toLowerCase ( ) : null ;
97- const normalizedAllowedRepos = new Set ( Array . from ( allowedRepos ) . map ( r => r . toLowerCase ( ) ) ) ;
95+ // Whether the user explicitly configured cross-repo targeting.
96+ // defaultTargetRepo always has a value (falls back to context.repo), so we check
97+ // the raw config keys to distinguish user-configured from default.
98+ const hasExplicitTargetConfig = ! ! ( config [ "target-repo" ] || config . allowed_repos ?. length > 0 ) ;
9899
99100 const authClient = await createAuthenticatedGitHubClient ( config ) ;
100101
@@ -156,23 +157,25 @@ async function main(config = {}) {
156157
157158 const { prNumber : threadPRNumber , repoNameWithOwner : threadRepo } = threadInfo ;
158159
159- // When a target-repo or allowed-repos is configured, validate the thread's repository.
160+ // When the user explicitly configured target-repo or allowed-repos, validate the thread's
161+ // repository using validateTargetRepo (supports wildcards like "*", "org/*").
160162 // Otherwise, fall back to the legacy behavior of scoping to the triggering PR only.
161- const hasTargetRepoConfig = defaultTargetRepo || allowedRepos . size > 0 ;
162-
163- if ( hasTargetRepoConfig ) {
164- // Cross-repo mode: validate thread repo against configured repos
165- if ( threadRepo ) {
166- const normalizedThreadRepo = threadRepo . toLowerCase ( ) ;
167- const isDefaultRepo = normalizedDefaultTargetRepo && normalizedThreadRepo === normalizedDefaultTargetRepo ;
168- const isAllowedRepo = isDefaultRepo || normalizedAllowedRepos . has ( normalizedThreadRepo ) ;
169- if ( ! isAllowedRepo ) {
170- core . warning ( `Thread ${ threadId } belongs to repo ${ threadRepo } , which is not in the allowed repos` ) ;
171- return {
172- success : false ,
173- error : `Thread belongs to repo '${ threadRepo } ', but only threads in allowed repositories can be resolved. Allowed: ${ defaultTargetRepo } ${ allowedRepos . size > 0 ? ", " + Array . from ( allowedRepos ) . join ( ", " ) : "" } ` ,
174- } ;
175- }
163+ if ( hasExplicitTargetConfig ) {
164+ // Cross-repo mode: validate thread repo against configured repos (fail closed if missing)
165+ if ( ! threadRepo ) {
166+ core . warning ( `Could not determine repository for thread ${ threadId } ` ) ;
167+ return {
168+ success : false ,
169+ error : `Could not determine the repository for thread ${ threadId } ` ,
170+ } ;
171+ }
172+ const repoValidation = validateTargetRepo ( threadRepo , defaultTargetRepo , allowedRepos ) ;
173+ if ( ! repoValidation . valid ) {
174+ core . warning ( `Thread ${ threadId } belongs to repo ${ threadRepo } , which is not in the allowed repos` ) ;
175+ return {
176+ success : false ,
177+ error : repoValidation . error ,
178+ } ;
176179 }
177180
178181 // Determine target PR number based on target config
0 commit comments