@@ -252,36 +252,9 @@ func (opts *IssuesOptions) Run(ctx context.Context, cmd *cobra.Command) error {
252252 opts .client = client
253253 opts .remote = remote
254254
255- issuesList , err := opts .resolveIssues (ctx , client , remote )
255+ issuesList , err := opts .resolveIssuesWithRetry (ctx , client , remote )
256256 if err != nil {
257- // If the API says this is a monorepo, show a friendly message.
258- if strings .Contains (err .Error (), "This repository is a monorepo" ) {
259- return fmt .Errorf ("This is a monorepo. Use --repo to specify a sub-project.\n \n Hint: %s" , err .Error ())
260- }
261-
262- // If we auto-detected a sub-repo path and the exact path wasn't found,
263- // progressively strip the last segment and retry.
264- if strings .Contains (err .Error (), "Repository does not exist" ) && remote .SubRepoSuffix != "" {
265- parts := strings .Split (remote .SubRepoSuffix , ":" )
266- // Try stripping from the end: e.g. a:b:c → a:b → a
267- for len (parts ) > 1 {
268- parts = parts [:len (parts )- 1 ]
269- remote .SubRepoSuffix = strings .Join (parts , ":" )
270- baseName := strings .SplitN (remote .RepoName , ":" , 2 )[0 ]
271- remote .RepoName = baseName + ":" + remote .SubRepoSuffix
272-
273- issuesList , err = opts .resolveIssues (ctx , client , remote )
274- if err == nil {
275- break
276- }
277- if ! strings .Contains (err .Error (), "Repository does not exist" ) {
278- return err
279- }
280- }
281- }
282- if err != nil {
283- return err
284- }
257+ return err
285258 }
286259 if issuesList == nil {
287260 return nil
@@ -310,6 +283,41 @@ func (opts *IssuesOptions) Run(ctx context.Context, cmd *cobra.Command) error {
310283 return nil
311284}
312285
286+ // resolveIssuesWithRetry calls resolveIssues and, for monorepos with an
287+ // auto-detected sub-repo path, progressively strips path segments on
288+ // "Repository does not exist" errors until a match is found.
289+ func (opts * IssuesOptions ) resolveIssuesWithRetry (ctx context.Context , client * deepsource.Client , remote * vcs.RemoteData ) ([]issues.Issue , error ) {
290+ issuesList , err := opts .resolveIssues (ctx , client , remote )
291+ if err == nil {
292+ return issuesList , nil
293+ }
294+
295+ if strings .Contains (err .Error (), "This repository is a monorepo" ) {
296+ return nil , fmt .Errorf ("This is a monorepo. Use --repo to specify a sub-project.\n \n Hint: %s" , err .Error ())
297+ }
298+
299+ if ! strings .Contains (err .Error (), "Repository does not exist" ) || remote .SubRepoSuffix == "" {
300+ return nil , err
301+ }
302+
303+ parts := strings .Split (remote .SubRepoSuffix , ":" )
304+ for len (parts ) > 1 {
305+ parts = parts [:len (parts )- 1 ]
306+ remote .SubRepoSuffix = strings .Join (parts , ":" )
307+ baseName := strings .SplitN (remote .RepoName , ":" , 2 )[0 ]
308+ remote .RepoName = baseName + ":" + remote .SubRepoSuffix
309+
310+ issuesList , err = opts .resolveIssues (ctx , client , remote )
311+ if err == nil {
312+ return issuesList , nil
313+ }
314+ if ! strings .Contains (err .Error (), "Repository does not exist" ) {
315+ return nil , err
316+ }
317+ }
318+ return nil , err
319+ }
320+
313321func (opts * IssuesOptions ) resolveIssues (ctx context.Context , client * deepsource.Client , remote * vcs.RemoteData ) ([]issues.Issue , error ) {
314322 serverFilters := opts .buildServerFilters ()
315323 prFilters := opts .buildPRFilters ()
0 commit comments