Skip to content

Fix CLI not working with monorepos#273

Open
jai-deepsource wants to merge 1 commit intomasterfrom
fix/monorepo-cli-resolution
Open

Fix CLI not working with monorepos#273
jai-deepsource wants to merge 1 commit intomasterfrom
fix/monorepo-cli-resolution

Conversation

@jai-deepsource
Copy link
Contributor

Summary

  • Auto-detect sub-repo path from CWD relative to git root and append it to the repo name sent to the API
  • Progressively strip path segments on 404 to find the matching sub-project
  • Show a friendly error when a monorepo is detected without --repo
  • Include analyzer name/shortcode in PR issues GraphQL response

Context

Plain ticket #6884175 — CLI commands fail with "Repository does not exist" when run inside a monorepo sub-directory. Now the CLI detects the relative path, converts / to :, and appends it as a sub-repo suffix.

Companion PR: DeepSourceCorp/asgard (same branch)

Test plan

  • Run deepsource issues from a monorepo sub-directory and verify auto-detection works
  • Run from root of a monorepo without --repo and verify friendly error
  • Verify PR issues include analyzer metadata

- Detect CWD relative to git root and append colon-delimited sub-repo
  suffix to the repo name sent to the API
- Progressively strip path segments on 404 to find the right sub-project
- Show friendly error when monorepo is detected without --repo
- Include analyzer name/shortcode in PR issues GraphQL response
@deepsource-io
Copy link

deepsource-io bot commented Mar 4, 2026

DeepSource Code Review

We reviewed changes in fccfbea...b42dfdd on this pull request. Below is the summary for the review, and you can see the individual issues we found as inline review comments.

See full review on DeepSource ↗

Important

Some issues found as part of this review are outside of the diff in this pull request and aren't shown in the inline review comments due to GitHub's API limitations. You can see those issues on the DeepSource dashboard.

PR Report Card

Overall Grade  

Focus Area: Reliability
Security  

Reliability  

Complexity  

Hygiene  

Coverage  

Code Review Summary

Analyzer Status Updated (UTC) Details
Go Mar 4, 2026 7:12p.m. Review ↗
Secrets Mar 4, 2026 7:12p.m. Review ↗
Test coverage Mar 4, 2026 7:12p.m. Review ↗

Code Coverage Summary

Language Line Coverage (New Code) Line Coverage (Overall)
Aggregate
0%
[⤫ below threshold]
19.1%
[▼ down 0.1% from master]
Go
0%
[⤫ below threshold]
19.1%
[▼ down 0.1% from master]
[✓ above threshold]

➟ Additional coverage metrics may have been reported. See full coverage report ↗

Comment on lines +143 to +160
cwd, err := runCmd("pwd", nil)
if err != nil {
return ""
}
cwd = strings.TrimSpace(cwd)

if cwd == toplevel {
return ""
}

rel := strings.TrimPrefix(cwd, toplevel+"/")
if rel == cwd {
// cwd is not under toplevel (shouldn't happen)
return ""
}

debug.Log("git: sub-repo relative path %q", rel)
return strings.ReplaceAll(rel, "/", ":")
Copy link

Choose a reason for hiding this comment

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

Use of `pwd` command and `/` path separator is not portable and insecure


The use of the pwd command makes this function non-portable to Windows and introduces a security risk via PATH manipulation. Additionally, the hardcoded / path separator will cause incorrect behavior on Windows.

Replace runCmd("pwd", nil) with the platform-agnostic and secure os.Getwd(). Use filepath.Rel(toplevel, cwd) to calculate the relative path, and replace os.PathSeparator to handle different operating systems correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants