Skip to content

refactor(tools): centralize code-host unavailable payload for code-host tools#1037

Merged
muddlebee merged 3 commits intoTracer-Cloud:mainfrom
7vignesh:issue/896-code-host-unavailable-helper
Apr 28, 2026
Merged

refactor(tools): centralize code-host unavailable payload for code-host tools#1037
muddlebee merged 3 commits intoTracer-Cloud:mainfrom
7vignesh:issue/896-code-host-unavailable-helper

Conversation

@7vignesh
Copy link
Copy Markdown
Contributor

Fixes #896

Added a shared helper for the integration-not-configured response used by code-host tools, and migrated only the scoped tools from the issue.

This PR covers:

  • Added shared helper: code_host_unavailable.py
  • Migrated these tools to use it:
    • GitHubSearchCodeTool
    • GitHubFileContentsTool
    • BitbucketSearchCodeTool
    • GitLabFileTool
  • Kept provider-specific success responses unchanged
  • Preserved tool-specific empty-result keys:
    • matches for GitHub search
    • file for GitHub file contents
    • results for Bitbucket search
    • file for GitLab file contents

Test updates:

  • Extended:
    • test_github_search_code_tool.py
    • test_github_file_contents_tool.py
    • test_gitlab_file_tool.py
  • Added:
    • test_bitbucket_search_code_tool.py
    • test_code_host_unavailable.py (locks exact helper payload shape)

Demo/Screenshot for feature changes and bug fixes -

Validation output:

  • Focused tool tests passed
  • Ruff check passed
  • Ruff format check passed
  • Mypy passed

Code Understanding and AI Usage

Did you use AI assistance (ChatGPT, Claude, Copilot, etc.) to write any part of this code?

  • Yes, I used AI assistance (continue below)

If you used AI assistance:

  • I have reviewed every single line of the AI-generated code
  • I can explain the purpose and logic of each function/component I added
  • I have tested edge cases and understand how the code handles them
  • I have modified the AI output to follow this project's coding standards and conventions

Explain your implementation approach:

I extracted a single helper to remove duplicated unavailable payload logic across code-host tools while keeping behavior stable and scoped. I intentionally migrated only the four tools listed in the issue and did not touch provider-specific API behavior. I then added tests to verify exact unavailable payload shape and to guard each tool's required empty-result key to prevent regressions.


Checklist before requesting a review

  • I have added proper PR title and linked to the issue
  • I have performed a self-review of my code
  • I can explain the purpose of every function, class, and logic block I added
  • I understand why my changes work and have tested them thoroughly
  • I have considered potential edge cases and how my code handles them
  • If it is a core feature, I have added thorough tests
  • My code follows the project's style guidelines and conventions

Copilot AI review requested due to automatic review settings April 28, 2026 12:20
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 28, 2026

Greptile Summary

This PR extracts a shared code_host_unavailable_payload helper to eliminate four near-identical inline dictionaries across GitHubSearchCodeTool, GitHubFileContentsTool, BitbucketSearchCodeTool, and GitLabFileTool. The refactor is well-scoped, all tool-specific empty-result keys are preserved, and the new tests lock exact payload shapes to prevent regressions.

Confidence Score: 5/5

Safe to merge — pure refactor with no logic changes, comprehensive tests, and only P2 findings.

All findings are P2 (comment grouping in __all__ and an undocumented casing fix in the GitLab error string). No logic, API, or behavioral regressions are introduced, and the new tests lock exact payload shapes across all four tools.

app/tools/utils/init.py (wrong comment group for code_host_unavailable_payload in __all__) and app/tools/GitLabFileTool/init.py (silent error message casing change).

Important Files Changed

Filename Overview
app/tools/utils/code_host_unavailable.py New shared helper using keyword-only args to produce standardized unavailable payloads; clean implementation with correct typing.
app/tools/utils/init.py Exports new helper correctly, but code_host_unavailable_payload is grouped under the # Database warnings comment in __all__, which is misleading.
app/tools/GitHubSearchCodeTool/init.py Inline unavailable payload replaced with code_host_unavailable_payload; behavior preserved exactly.
app/tools/GitHubFileContentsTool/init.py Migrated to shared helper; source, error message, and file empty key all preserved correctly.
app/tools/BitbucketSearchCodeTool/init.py Migrated to shared helper; results: [] empty key preserved correctly.
app/tools/GitLabFileTool/init.py Migrated to shared helper with a silent casing fix: "gitlab""GitLab" in the error message string.
tests/tools/test_bitbucket_search_code_tool.py New test file covering availability, parameter extraction, unavailable path, and happy path — thorough coverage.
tests/tools/test_code_host_unavailable.py Locks exact helper payload shape; minimal and correct.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Tool called] --> B{config is None?}
    B -- Yes --> C[code_host_unavailable_payload helper]
    C --> D[Standardized unavailable dict returned]
    B -- No --> E[Call integration API]
    E --> F[Provider-specific response returned]

    G[GitHubSearchCodeTool] --> B
    H[GitHubFileContentsTool] --> B
    I[BitbucketSearchCodeTool] --> B
    J[GitLabFileTool] --> B
Loading

Reviews (1): Last reviewed commit: "refactor(tools): share code-host unavail..." | Re-trigger Greptile

Comment on lines 29 to 33
__all__ = [
# Database warnings
"default_db_warning",
"code_host_unavailable_payload",
# Data validation
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.

P2 code_host_unavailable_payload grouped under wrong comment section

code_host_unavailable_payload is listed immediately under the # Database warnings comment, making it look like a DB-warning utility. It belongs in its own section (e.g., # Code-host utilities).

Suggested change
__all__ = [
# Database warnings
"default_db_warning",
"code_host_unavailable_payload",
# Data validation
__all__ = [
# Database warnings
"default_db_warning",
# Code-host utilities
"code_host_unavailable_payload",
# Data validation

Comment on lines 64 to +71
"""Read the contents of a specific file from a GitLab repository."""
config = _resolve_config(gitlab_url, gitlab_token)
if config is None:
return {
"source": "gitlab",
"available": False,
"error": "gitlab integration is not configured.",
"file": {},
}
return code_host_unavailable_payload(
source="gitlab",
integration_name="GitLab",
empty_key="file",
empty_value={},
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.

P2 Silent error-message casing change for GitLab

The original error was "gitlab integration is not configured." (lowercase g). The new helper produces "GitLab integration is not configured." (uppercase G). If any downstream consumer or test outside this PR does a case-sensitive match on the old string, it will silently diverge. The change itself is an improvement, but it's worth explicitly documenting as a behavior change in the PR description so future readers understand it was intentional.

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.

Pull request overview

This PR centralizes the “integration not configured / unavailable” response payload used by code-host investigation tools (GitHub, GitLab, Bitbucket), and updates the scoped tools and their tests to use a shared helper while preserving provider-specific success payloads and per-tool empty-result keys.

Changes:

  • Added code_host_unavailable_payload helper under app/tools/utils/ for standardized unavailable responses.
  • Migrated four scoped tools (GitHub search, GitHub file contents, Bitbucket search, GitLab file contents) to use the helper.
  • Tightened/added tests to lock the exact unavailable payload shape and each tool’s empty-result key.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated no comments.

Show a summary per file
File Description
app/tools/utils/code_host_unavailable.py Introduces shared helper to build standardized unavailable payloads.
app/tools/utils/init.py Re-exports helper from the utils package.
app/tools/GitHubSearchCodeTool/init.py Uses shared helper for the “no config” return payload (keeps matches).
app/tools/GitHubFileContentsTool/init.py Uses shared helper for the “no config” return payload (keeps file).
app/tools/BitbucketSearchCodeTool/init.py Uses shared helper for the “no config” return payload (keeps results).
app/tools/GitLabFileTool/init.py Uses shared helper for the “no config” return payload (keeps file).
tests/tools/test_code_host_unavailable.py Adds unit test locking the helper’s exact payload shape.
tests/tools/test_github_search_code_tool.py Strengthens unavailable-case assertion to exact payload equality.
tests/tools/test_github_file_contents_tool.py Strengthens unavailable-case assertion to exact payload equality.
tests/tools/test_bitbucket_search_code_tool.py Adds new contract + behavior tests, including unavailable payload shape.
tests/tools/test_gitlab_file_tool.py Strengthens unavailable-case assertion to exact payload equality.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@7vignesh
Copy link
Copy Markdown
Contributor Author

@muddlebee
Addressed the bot review comments in the second commit and pushed the updates. Ready for review.

Copy link
Copy Markdown
Collaborator

@muddlebee muddlebee left a comment

Choose a reason for hiding this comment

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

Submitted with one inline note on package documentation.

Comment thread app/tools/utils/__init__.py Outdated
@@ -1,5 +1,6 @@
"""Tool utilities - data validation, evidence compaction, and log deduplication."""
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Update the package docstring so it reflects code-host helpers, not only validation, compaction, and deduplication.

@7vignesh
Copy link
Copy Markdown
Contributor Author

@muddlebee Done with the doc update.

@muddlebee muddlebee merged commit 6fb8301 into Tracer-Cloud:main Apr 28, 2026
7 checks passed
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 28, 2026

Shipped. Thank you @7vignesh — this PR is merged and helps everyone using OpenSRE.


💬 Community: Discord — OpenSRE (#contribute) — questions, coordination, and roadmap chatter welcome anytime.

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.

Extract a shared "integration not configured" helper for code-host tools

3 participants