Skip to content

Commit e27d9ee

Browse files
committed
Refactor issue service to streamline container initialization and enhance parameter handling
1 parent 9590c6e commit e27d9ee

1 file changed

Lines changed: 22 additions & 18 deletions

File tree

prometheus/app/services/issue_service.py

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import uuid
66
from datetime import datetime
77
from pathlib import Path
8-
from typing import Any, Mapping, Optional, Sequence
8+
from typing import Mapping, Optional, Sequence
99

1010
from prometheus.app.services.base_service import BaseService
1111
from prometheus.app.services.llm_service import LLMService
@@ -89,19 +89,6 @@ async def answer_issue(
8989
- issue_response (str): Response generated for the issue.
9090
"""
9191

92-
# Construct the working directory
93-
if dockerfile_content or image_name:
94-
container = UserDefinedContainer(
95-
repository.get_working_directory(),
96-
workdir,
97-
build_commands,
98-
test_commands,
99-
dockerfile_content,
100-
image_name,
101-
)
102-
else:
103-
container = GeneralContainer(repository.get_working_directory())
104-
10592
# Initialize the issue graph with the necessary services and parameters
10693
(
10794
edit_patch,
@@ -123,9 +110,11 @@ async def answer_issue(
123110
number_of_candidate_patch=number_of_candidate_patch,
124111
knowledge_graph=knowledge_graph,
125112
repository=repository,
126-
container=container,
127113
build_commands=build_commands,
128114
test_commands=test_commands,
115+
dockerfile_content=dockerfile_content,
116+
image_name=image_name,
117+
workdir=workdir,
129118
)
130119

131120
if issue_type == IssueType.BUG:
@@ -170,10 +159,12 @@ def __answer(
170159
run_existing_test: bool,
171160
run_reproduce_test: bool,
172161
number_of_candidate_patch: int,
173-
container: GeneralContainer,
174162
build_commands: Optional[Sequence[str]],
175163
test_commands: Optional[Sequence[str]],
176-
) -> tuple[None, bool, bool, bool, None, None] | tuple[str, Any, Any, Any, str, IssueType]:
164+
dockerfile_content: Optional[str] = None,
165+
image_name: Optional[str] = None,
166+
workdir: Optional[str] = None,
167+
) -> tuple[None, bool, bool, bool, None, IssueType] | tuple[str, bool, bool, bool, str, IssueType]:
177168
# Set up a dedicated logger for this thread
178169
logger = logging.getLogger(f"thread-{threading.get_ident()}.prometheus")
179170
logger.setLevel(getattr(logging, self.logging_level))
@@ -184,6 +175,19 @@ def __answer(
184175
file_handler.setFormatter(formatter)
185176
logger.addHandler(file_handler)
186177

178+
# Construct the working directory
179+
if dockerfile_content or image_name:
180+
container = UserDefinedContainer(
181+
repository.get_working_directory(),
182+
workdir,
183+
build_commands,
184+
test_commands,
185+
dockerfile_content,
186+
image_name,
187+
)
188+
else:
189+
container = GeneralContainer(repository.get_working_directory())
190+
187191
# Initialize the IssueGraph with the provided services and parameters
188192
issue_graph = IssueGraph(
189193
advanced_model=self.llm_service.advanced_model,
@@ -221,7 +225,7 @@ def __answer(
221225
)
222226
except Exception as e:
223227
logger.error(f"Error in answer_issue: {str(e)}\n{traceback.format_exc()}")
224-
return None, False, False, False, None, None
228+
return None, False, False, False, None, issue_type
225229
finally:
226230
self.repository_service.update_repository_status(repository_id, is_working=False)
227231
logger.removeHandler(file_handler)

0 commit comments

Comments
 (0)