@@ -5,6 +5,7 @@ import type { ClientOptions, ClientPathsWithMethod } from "openapi-fetch";
55import { createLogger } from "@sourcebot/shared" ;
66import { measure , fetchWithRetry } from "./utils.js" ;
77import * as Sentry from "@sentry/node" ;
8+ import micromatch from "micromatch" ;
89import {
910 SchemaRepository as CloudRepository ,
1011} from "@coderabbitai/bitbucket/cloud/openapi" ;
@@ -346,23 +347,31 @@ async function cloudGetRepos(client: BitbucketClient, repoList: string[]): Promi
346347
347348function cloudShouldExcludeRepo ( repo : BitbucketRepository , config : BitbucketConnectionConfig ) : boolean {
348349 const cloudRepo = repo as CloudRepository ;
350+ let reason = '' ;
351+ const repoName = cloudRepo . full_name ! ;
349352
350353 const shouldExclude = ( ( ) => {
351- if ( config . exclude ?. repos && config . exclude . repos . includes ( cloudRepo . full_name ! ) ) {
352- return true ;
354+ if ( config . exclude ?. repos ) {
355+ if ( micromatch . isMatch ( repoName , config . exclude . repos ) ) {
356+ reason = `\`exclude.repos\` contains ${ repoName } ` ;
357+ return true ;
358+ }
353359 }
354360
355361 if ( ! ! config . exclude ?. archived ) {
356362 logger . warn ( `Exclude archived repos flag provided in config but Bitbucket Cloud does not support archived repos. Ignoring...` ) ;
357363 }
358364
359365 if ( ! ! config . exclude ?. forks && cloudRepo . parent !== undefined ) {
366+ reason = `\`exclude.forks\` is true` ;
360367 return true ;
361368 }
369+
370+ return false ;
362371 } ) ( ) ;
363372
364373 if ( shouldExclude ) {
365- logger . debug ( `Excluding repo ${ cloudRepo . full_name } because it matches the exclude pattern ` ) ;
374+ logger . debug ( `Excluding repo ${ repoName } . Reason: ${ reason } ` ) ;
366375 return true ;
367376 }
368377 return false ;
@@ -548,23 +557,32 @@ function serverShouldExcludeRepo(repo: BitbucketRepository, config: BitbucketCon
548557
549558 const projectName = serverRepo . project ! . key ;
550559 const repoSlug = serverRepo . slug ! ;
560+ const repoName = `${ projectName } /${ repoSlug } ` ;
561+ let reason = '' ;
551562
552563 const shouldExclude = ( ( ) => {
553- if ( config . exclude ?. repos && config . exclude . repos . includes ( `${ projectName } /${ repoSlug } ` ) ) {
554- return true ;
564+ if ( config . exclude ?. repos ) {
565+ if ( micromatch . isMatch ( repoName , config . exclude . repos ) ) {
566+ reason = `\`exclude.repos\` contains ${ repoName } ` ;
567+ return true ;
568+ }
555569 }
556570
557571 if ( ! ! config . exclude ?. archived && serverRepo . archived ) {
572+ reason = `\`exclude.archived\` is true` ;
558573 return true ;
559574 }
560575
561576 if ( ! ! config . exclude ?. forks && serverRepo . origin !== undefined ) {
577+ reason = `\`exclude.forks\` is true` ;
562578 return true ;
563579 }
580+
581+ return false ;
564582 } ) ( ) ;
565583
566584 if ( shouldExclude ) {
567- logger . debug ( `Excluding repo ${ projectName } / ${ repoSlug } because it matches the exclude pattern ` ) ;
585+ logger . debug ( `Excluding repo ${ repoName } . Reason: ${ reason } ` ) ;
568586 return true ;
569587 }
570588 return false ;
0 commit comments