refactor(tools): centralize code-host unavailable payload for code-host tools#1037
Conversation
Greptile SummaryThis PR extracts a shared Confidence Score: 5/5Safe to merge — pure refactor with no logic changes, comprehensive tests, and only P2 findings. All findings are P2 (comment grouping in app/tools/utils/init.py (wrong comment group for Important Files Changed
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
Reviews (1): Last reviewed commit: "refactor(tools): share code-host unavail..." | Re-trigger Greptile |
| __all__ = [ | ||
| # Database warnings | ||
| "default_db_warning", | ||
| "code_host_unavailable_payload", | ||
| # Data validation |
There was a problem hiding this comment.
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).
| __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 |
| """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={}, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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_payloadhelper underapp/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.
|
@muddlebee |
muddlebee
left a comment
There was a problem hiding this comment.
Submitted with one inline note on package documentation.
| @@ -1,5 +1,6 @@ | |||
| """Tool utilities - data validation, evidence compaction, and log deduplication.""" | |||
There was a problem hiding this comment.
Update the package docstring so it reflects code-host helpers, not only validation, compaction, and deduplication.
|
@muddlebee Done with the doc update. |
|
✨ Shipped. Thank you @7vignesh — this PR is merged and helps everyone using OpenSRE. 💬 Community: Discord — OpenSRE ( |

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:
code_host_unavailable.pyGitHubSearchCodeToolGitHubFileContentsToolBitbucketSearchCodeToolGitLabFileToolmatchesfor GitHub searchfilefor GitHub file contentsresultsfor Bitbucket searchfilefor GitLab file contentsTest updates:
test_github_search_code_tool.pytest_github_file_contents_tool.pytest_gitlab_file_tool.pytest_bitbucket_search_code_tool.pytest_code_host_unavailable.py(locks exact helper payload shape)Demo/Screenshot for feature changes and bug fixes -
Validation output:
Code Understanding and AI Usage
Did you use AI assistance (ChatGPT, Claude, Copilot, etc.) to write any part of this code?
If you used AI assistance:
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