2525
2626from tools .specfile import AddChangelogEntryTool , BumpReleaseTool
2727from tools .text import CreateTool , InsertTool , StrReplaceTool , ViewTool
28- from tools .wicked_git import GitPatchCreationTool
28+ from tools .wicked_git import GitLogSearchTool , GitPatchCreationTool
2929from constants import COMMIT_PREFIX , BRANCH_PREFIX
3030from observability import setup_observability
3131from tools .commands import RunShellCommandTool
@@ -39,15 +39,8 @@ class InputSchema(BaseModel):
3939 package : str = Field (description = "Package to update" )
4040 upstream_fix : str = Field (description = "Link to an upstream fix for the issue" )
4141 jira_issue : str = Field (description = "Jira issue to reference as resolved" )
42+ cve_id : str = Field (default = "" , description = "CVE ID if the jira issue is a CVE" )
4243 dist_git_branch : str = Field (description = "Git branch in dist-git to be updated" )
43- gitlab_user : str = Field (
44- description = "Name of the GitLab user" ,
45- default = os .getenv ("GITLAB_USER" , "rhel-packaging-agent" ),
46- )
47- git_url : str = Field (
48- description = "URL of the git repository" ,
49- default = "https://gitlab.com/redhat/centos-stream/rpms" ,
50- )
5144 git_repo_basepath : str = Field (
5245 description = "Base path for cloned git repos" ,
5346 default = os .getenv ("GIT_REPO_BASEPATH" ),
@@ -68,8 +61,12 @@ class OutputSchema(BaseModel):
6861def render_prompt (input : InputSchema ) -> str :
6962 template = (
7063 'Work inside the repository cloned at "{{ git_repo_basepath }}/{{ package }}"\n '
64+ "Use the `git_log_search` tool to check if the jira issue ({{ jira_issue }}) or CVE ({{ cve_id }}) is already resolved.\n "
65+ "If the issue or the cve are already resolved, exit the backporting process with success=True and status=\" Backport already applied\" \n "
7166 "Download the upstream fix from {{ upstream_fix }}\n "
7267 'Store the patch file as "{{ jira_issue }}.patch" in the repository root\n '
68+ "If directory {{ unpacked_sources }} is not a git repository, run `git init` in it "
69+ "and create an initial commit\n "
7370 "Navigate to the directory {{ unpacked_sources }} and use `git am --reject` "
7471 "command to apply the patch {{ jira_issue }}.patch\n "
7572 "Resolve all conflicts inside {{ unpacked_sources }} directory and "
@@ -89,7 +86,6 @@ def backport_git_steps(data):
8986 commit_title = f"{ COMMIT_PREFIX } backport { input_data .jira_issue } " ,
9087 files_to_commit = f"*.spec and { input_data .jira_issue } .patch" ,
9188 branch_name = f"{ BRANCH_PREFIX } -{ input_data .jira_issue } " ,
92- git_url = input_data .git_url ,
9389 dist_git_branch = input_data .dist_git_branch ,
9490 )
9591
@@ -142,6 +138,7 @@ async def main() -> None:
142138 logging .basicConfig (level = logging .INFO )
143139
144140 setup_observability (os .getenv ("COLLECTOR_ENDPOINT" ))
141+ cve_id = os .getenv ("CVE_ID" , "" )
145142
146143 async with mcp_tools (os .getenv ("MCP_GATEWAY_URL" )) as gateway_tools :
147144 agent = RequirementAgent (
@@ -155,6 +152,7 @@ async def main() -> None:
155152 InsertTool (),
156153 StrReplaceTool (),
157154 GitPatchCreationTool (),
155+ GitLogSearchTool (),
158156 BumpReleaseTool (),
159157 AddChangelogEntryTool (),
160158 ]
@@ -206,6 +204,7 @@ async def run(input):
206204 upstream_fix = upstream_fix ,
207205 jira_issue = jira_issue ,
208206 dist_git_branch = branch ,
207+ cve_id = cve_id ,
209208 )
210209 unpacked_sources , local_clone = prepare_package (package , jira_issue , branch , input )
211210 input .unpacked_sources = str (unpacked_sources )
@@ -251,10 +250,12 @@ class Task(BaseModel):
251250 upstream_fix = backport_data .patch_url ,
252251 jira_issue = backport_data .jira_issue ,
253252 dist_git_branch = backport_data .branch ,
253+ cve_id = backport_data .cve_id ,
254254 )
255- input . unpacked_sources , local_clone = prepare_package (
255+ unpacked_sources , local_clone = prepare_package (
256256 backport_data .package , backport_data .jira_issue , backport_data .branch , input
257257 )
258+ input .unpacked_sources = str (unpacked_sources )
258259
259260 async def retry (task , error ):
260261 task .attempts += 1
0 commit comments