Skip to content

Commit 2d7c9dd

Browse files
committed
fix
1 parent 4d5973f commit 2d7c9dd

File tree

3 files changed

+91
-4
lines changed

3 files changed

+91
-4
lines changed

packages/gg_api_core/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ dependencies = [
1212
"mcp[cli]>=1.9.0",
1313
"python-dotenv>=1.0.0",
1414
"pydantic-settings>=2.0.0",
15+
"jinja2>=3.1.0",
1516
]
1617

1718
[build-system]

packages/gg_api_core/src/gg_api_core/tools/remediate_secret_incidents.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from typing import Any
33
import logging
44

5+
from jinja2 import Template
56
from pydantic import BaseModel, Field, model_validator
67

78
from gg_api_core.client import TagNames
@@ -11,7 +12,7 @@
1112

1213
logger = logging.getLogger(__name__)
1314

14-
REMEDIATION_PROMPT_PATH = Path("remediation_prompt.md")
15+
REMEDIATION_PROMPT_PATH = Path(__file__).parent / "remediation_prompt.md"
1516

1617

1718
class ListRepoOccurrencesParamsForRemediate(ListRepoOccurrencesParams):
@@ -25,6 +26,15 @@ class ListRepoOccurrencesParamsForRemediate(ListRepoOccurrencesParams):
2526

2627
class RemediateSecretIncidentsParams(BaseModel):
2728
"""Parameters for remediating secret incidents."""
29+
repository_name: str | None = Field(
30+
default=None,
31+
description="The full repository name. For example, for https://github.com/GitGuardian/ggmcp.git the full name is GitGuardian/ggmcp. Pass the current repository name if not provided.",
32+
)
33+
source_id: str | int | None = Field(
34+
default=None,
35+
description="The source ID of the repository. Pass the current repository source ID if not provided.",
36+
)
37+
get_all: bool = Field(default=True, description="Whether to get all occurrences or just the first page")
2838
mine: bool = Field(
2939
default=False,
3040
description="If True, fetch only incidents assigned to the current user. Set to False to get all incidents.",
@@ -48,6 +58,13 @@ class RemediateSecretIncidentsParams(BaseModel):
4858
description="Parameters for listing repository occurrences",
4959
)
5060

61+
@model_validator(mode="after")
62+
def validate_source_or_repository(self) -> "RemediateSecretIncidentsParams":
63+
"""Validate that either source_id or repository_name is provided."""
64+
if not self.source_id and not self.repository_name:
65+
raise ValueError("Either 'source_id' or 'repository_name' must be provided")
66+
return self
67+
5168

5269
class RemediateSecretIncidentsResult(BaseModel):
5370
"""Result from remediating secret incidents."""
@@ -108,17 +125,20 @@ async def remediate_secret_incidents(
108125

109126
occurrences = occurrences_result.occurrences
110127
if params.mine:
111-
occurrences = filter_mine(occurrences)
128+
occurrences = await filter_mine(occurrences)
112129
occurrences_count = len(occurrences)
113130
occurrences_result.occurrences = await trim_occurrences_for_remediation(occurrences)
114131

115132
if not occurrences:
116133
remediation_instructions = ("No secret occurrences found for this repository that match the criteria. "
117134
"Adjust 'list_repo_occurrences_params' to modify filtering.")
118135
else:
119-
remediation_instructions = REMEDIATION_PROMPT_PATH.format(
136+
# Load and render the Jinja2 template
137+
template_content = REMEDIATION_PROMPT_PATH.read_text()
138+
template = Template(template_content)
139+
remediation_instructions = template.render(
120140
add_to_env=params.add_to_env,
121-
create_env_example=params.create_env_example,
141+
env_example=params.create_env_example,
122142
git_commands=params.git_commands,
123143
)
124144
return RemediateSecretIncidentsResult(

uv.lock

Lines changed: 66 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)