Skip to content

🧹 Replace hardcoded dummy logic in get_repo_info#172

Open
abhimehro wants to merge 1 commit into
mainfrom
bolt-fix-get-repo-info-14172787027687589562
Open

🧹 Replace hardcoded dummy logic in get_repo_info#172
abhimehro wants to merge 1 commit into
mainfrom
bolt-fix-get-repo-info-14172787027687589562

Conversation

@abhimehro
Copy link
Copy Markdown
Owner

@abhimehro abhimehro commented May 14, 2026

🎯 What: Replaced the dummy get_repo_info function with actual logic that retrieves the repository account, project name, and current commit hash using git commands.

💡 Why: Returning hardcoded values indicates incomplete logic and hinders the scanner's ability to provide accurate repository context. Implementing actual retrieval improves the maintainability and accuracy of the tool.

Verification: Added comprehensive unit tests in tests/test_code_health_scanner.py using mocks to verify parsing of various git URL formats (HTTPS, SSH) and proper error handling. All 12 tests passed successfully.

Result: get_repo_info now dynamically retrieves repository information from the environment, making the code health scanner more robust and ready for real-world use.

═════ ELIR ═════
PURPOSE: Implements actual git repository info retrieval in get_repo_info using subprocess and re.
SECURITY: Strips GH_TOKEN from environment before calling git and logs only exception types to prevent info disclosure.
FAILS IF: git is not installed or the directory is not a git repo (returns "unknown" values).
VERIFY: Run pytest tests/test_code_health_scanner.py.
MAINTAIN: Regex handles standard GitHub HTTPS/SSH URL formats.


PR created automatically by Jules for task 14172787027687589562 started by @abhimehro


Open in Devin Review

Co-authored-by: abhimehro <84992105+abhimehro@users.noreply.github.com>
@google-labs-jules
Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Copilot AI review requested due to automatic review settings May 14, 2026 13:00
@trunk-io
Copy link
Copy Markdown

trunk-io Bot commented May 14, 2026

Merging to main in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here

@cursor
Copy link
Copy Markdown

cursor Bot commented May 14, 2026

PR Summary

Medium Risk
Introduces subprocess-based git calls and URL parsing, which can fail in non-git environments and may behave differently across remote URL formats; test coverage mitigates most regressions.

Overview
get_repo_info is replaced with real implementation that shells out to git to read the origin remote URL and HEAD commit, parses account/project via regex, strips GH_TOKEN from the subprocess environment, and falls back to "unknown" values on errors.

Tests are updated to mock subprocess.check_output and verify HTTPS/SSH/no-.git URL parsing plus secure failure behavior.

Reviewed by Cursor Bugbot for commit e123015. Configure here.

Copy link
Copy Markdown

@codescene-delta-analysis codescene-delta-analysis Bot left a comment

Choose a reason for hiding this comment

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

Gates Failed
Enforce advisory code health rules (1 file with Code Duplication)

Gates Passed
5 Quality Gates Passed

See analysis details in CodeScene

Reason for failure
Enforce advisory code health rules Violations Code Health Impact
test_code_health_scanner.py 1 advisory rule 10.00 → 9.39 Suppress

Quality Gate Profile: Pay Down Tech Debt
Install CodeScene MCP: safeguard and uplift AI-generated code. Catch issues early with our IDE extension and CLI tool.

Comment on lines +7 to +16
def test_get_repo_info_https():
with patch("subprocess.check_output") as mock_run:
mock_run.side_effect = [
"https://github.com/account/project.git\n",
"hash\n"
]
account, project, commit_hash = get_repo_info()
assert account == "account"
assert project == "project"
assert commit_hash == "hash"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

❌ New issue: Code Duplication
The module contains 3 functions with similar structure: test_get_repo_info_https,test_get_repo_info_no_dot_git,test_get_repo_info_ssh

Suppress

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

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

Devin Review found 4 potential issues.

Open in Devin Review

Comment thread code_health_scanner.py
# Matches formats:
# https://github.com/account/project.git
# git@github.com:account/project.git
match = re.search(r"[:/]([^/:]+)/([^/:]+?)(?:\.git)?$", origin_url)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

📝 Info: Lazy quantifier in regex is safe due to $ anchor

The regex r"[:/]([^/:]+)/([^/:]+?)(?:\.git)?$" at code_health_scanner.py:29 uses a lazy quantifier +? for the project capture group. This might appear risky since a lazy match combined with an optional (?:\.git)? group could theoretically under-match. However, the $ anchor forces the engine to backtrack until the entire remaining string is consumed, so ([^/:]+?) always expands to capture the full project name (minus the optional .git suffix). Verified empirically with URLs like https://github.com/account/project.git, git@github.com:account/project.git, https://github.com/account/project, and edge cases like account/my.gitproject.git — all produce correct results.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Comment thread code_health_scanner.py
Comment on lines +14 to +15
env = os.environ.copy()
env.pop("GH_TOKEN", None)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🚩 Only GH_TOKEN is stripped from subprocess environment

The security hardening at code_health_scanner.py:14-15 strips only GH_TOKEN from the environment before invoking git subprocesses. Other potentially sensitive variables (e.g., GITHUB_TOKEN, AWS_SECRET_ACCESS_KEY, GITLAB_TOKEN) remain in the child process environment. The comment says this prevents exfiltration "if subprocess is compromised," but a compromised subprocess could still access other secrets. This is a defense-in-depth measure and the risk is low (the subprocess is just git with hardcoded arguments), but it may be worth considering a more restrictive allowlist approach if the threat model warrants it.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

assert project == "project"
assert commit_hash == "hash"
def test_get_repo_info_https():
with patch("subprocess.check_output") as mock_run:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

📝 Info: Test mock patches subprocess at module level — correct for this import style

The tests use patch("subprocess.check_output") rather than patch("code_health_scanner.subprocess.check_output"). This works correctly because code_health_scanner.py uses import subprocess (importing the module) and calls subprocess.check_output(...) at runtime, so the attribute lookup on the module object picks up the mock. If the import style were ever changed to from subprocess import check_output, these tests would silently stop mocking and could start making real git calls.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

import os
import subprocess
from unittest.mock import patch
import pytest
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

📝 Info: Unused pytest import in test file

The import pytest at line 4 is not used anywhere in the test file — no pytest.raises, pytest.mark, or other pytest APIs are referenced. This is a minor style issue that a linter would catch.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants