25
25
26
26
from tools .specfile import AddChangelogEntryTool , BumpReleaseTool
27
27
from tools .text import CreateTool , InsertTool , StrReplaceTool , ViewTool
28
- from tools .wicked_git import GitPatchCreationTool
28
+ from tools .wicked_git import GitLogSearchTool , GitPatchCreationTool
29
29
from constants import COMMIT_PREFIX , BRANCH_PREFIX
30
30
from observability import setup_observability
31
31
from tools .commands import RunShellCommandTool
@@ -39,15 +39,8 @@ class InputSchema(BaseModel):
39
39
package : str = Field (description = "Package to update" )
40
40
upstream_fix : str = Field (description = "Link to an upstream fix for the issue" )
41
41
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" )
42
43
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
- )
51
44
git_repo_basepath : str = Field (
52
45
description = "Base path for cloned git repos" ,
53
46
default = os .getenv ("GIT_REPO_BASEPATH" ),
@@ -68,8 +61,12 @@ class OutputSchema(BaseModel):
68
61
def render_prompt (input : InputSchema ) -> str :
69
62
template = (
70
63
'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 "
71
66
"Download the upstream fix from {{ upstream_fix }}\n "
72
67
'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 "
73
70
"Navigate to the directory {{ unpacked_sources }} and use `git am --reject` "
74
71
"command to apply the patch {{ jira_issue }}.patch\n "
75
72
"Resolve all conflicts inside {{ unpacked_sources }} directory and "
@@ -89,7 +86,6 @@ def backport_git_steps(data):
89
86
commit_title = f"{ COMMIT_PREFIX } backport { input_data .jira_issue } " ,
90
87
files_to_commit = f"*.spec and { input_data .jira_issue } .patch" ,
91
88
branch_name = f"{ BRANCH_PREFIX } -{ input_data .jira_issue } " ,
92
- git_url = input_data .git_url ,
93
89
dist_git_branch = input_data .dist_git_branch ,
94
90
)
95
91
@@ -142,6 +138,7 @@ async def main() -> None:
142
138
logging .basicConfig (level = logging .INFO )
143
139
144
140
setup_observability (os .getenv ("COLLECTOR_ENDPOINT" ))
141
+ cve_id = os .getenv ("CVE_ID" , "" )
145
142
146
143
async with mcp_tools (os .getenv ("MCP_GATEWAY_URL" )) as gateway_tools :
147
144
agent = RequirementAgent (
@@ -155,6 +152,7 @@ async def main() -> None:
155
152
InsertTool (),
156
153
StrReplaceTool (),
157
154
GitPatchCreationTool (),
155
+ GitLogSearchTool (),
158
156
BumpReleaseTool (),
159
157
AddChangelogEntryTool (),
160
158
]
@@ -206,6 +204,7 @@ async def run(input):
206
204
upstream_fix = upstream_fix ,
207
205
jira_issue = jira_issue ,
208
206
dist_git_branch = branch ,
207
+ cve_id = cve_id ,
209
208
)
210
209
unpacked_sources , local_clone = prepare_package (package , jira_issue , branch , input )
211
210
input .unpacked_sources = str (unpacked_sources )
@@ -251,10 +250,12 @@ class Task(BaseModel):
251
250
upstream_fix = backport_data .patch_url ,
252
251
jira_issue = backport_data .jira_issue ,
253
252
dist_git_branch = backport_data .branch ,
253
+ cve_id = backport_data .cve_id ,
254
254
)
255
- input . unpacked_sources , local_clone = prepare_package (
255
+ unpacked_sources , local_clone = prepare_package (
256
256
backport_data .package , backport_data .jira_issue , backport_data .branch , input
257
257
)
258
+ input .unpacked_sources = str (unpacked_sources )
258
259
259
260
async def retry (task , error ):
260
261
task .attempts += 1
0 commit comments