Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -107,80 +107,80 @@ class GitHubBot:
|
|
107 |
return response.json()
|
108 |
|
109 |
def resolve_issue(self, token: str, owner: str, repo: str, issue_number: int, resolution: str, forked_repo: str) -> str:
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
# Create a unique branch name for this fix
|
115 |
-
branch_name = f"fix/issue-{issue_number}-{datetime.now().strftime('%Y%m%d-%H%M%S')}"
|
116 |
-
|
117 |
-
# Clone repository and create new branch
|
118 |
-
if not self.git.clone(forked_repo):
|
119 |
-
raise Exception("Failed to clone repository")
|
120 |
-
|
121 |
-
if not self.git.create_branch(branch_name):
|
122 |
-
raise Exception("Failed to create branch")
|
123 |
-
|
124 |
-
# Get repository content and analyze
|
125 |
-
code_contexts = self._get_main_branch_content(owner, repo)
|
126 |
-
|
127 |
-
# Get issue details
|
128 |
-
issue_url = f"{self.github_api.base_url}/repos/{owner}/{repo}/issues/{issue_number}"
|
129 |
-
response = requests.get(issue_url, headers=self.github_api.headers)
|
130 |
-
response.raise_for_status()
|
131 |
-
issue = response.json()
|
132 |
-
|
133 |
-
# Determine severity
|
134 |
-
severity = self._determine_severity(issue)
|
135 |
-
|
136 |
-
# Generate AI solution
|
137 |
-
context = f"Repository: {owner}/{repo}\nIssue #{issue_number}: {issue['title']}\n\nCode contexts:\n"
|
138 |
-
for ctx in code_contexts[:3]:
|
139 |
-
context += f"\nFile: {ctx.file_path}\n```{ctx.language}\n{ctx.content}\n```\n"
|
140 |
-
|
141 |
-
ai_solution = self.ai_provider.generate_solution(context, issue['body'])
|
142 |
-
|
143 |
-
# Create comprehensive resolution document
|
144 |
-
full_resolution = self._create_resolution_document(
|
145 |
-
issue_number, severity, resolution, ai_solution
|
146 |
-
)
|
147 |
-
|
148 |
-
# Save resolution
|
149 |
-
resolution_path = Path(RESOLUTIONS_DIRECTORY) / f"resolution_{issue_number}_{datetime.now().strftime('%Y%m%d_%H%M%S')}.md"
|
150 |
-
resolution_path.write_text(full_resolution)
|
151 |
-
|
152 |
-
# Prompt for manual intervention
|
153 |
-
print("\nAI-generated solution and original resolution have been saved.")
|
154 |
-
print(f"Please review and apply changes in: {self.temp_dir}")
|
155 |
-
input("Press Enter when changes are ready to commit...")
|
156 |
-
|
157 |
-
# Commit and push changes
|
158 |
-
if not self.git.commit(f"Fix #{issue_number}: {issue['title']}\n\n{resolution}"):
|
159 |
-
raise Exception("Failed to commit changes")
|
160 |
-
|
161 |
-
if not self.git.push("origin", branch_name):
|
162 |
-
raise Exception("Failed to push changes")
|
163 |
-
|
164 |
-
# Create pull request
|
165 |
-
pr = self.create_pull_request(
|
166 |
-
owner=owner,
|
167 |
-
repo=repo,
|
168 |
-
title=f"Fix #{issue_number}: {issue['title']}",
|
169 |
-
body=full_resolution,
|
170 |
-
head=branch_name
|
171 |
-
)
|
172 |
|
173 |
-
|
|
|
174 |
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
179 |
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
184 |
|
185 |
def _create_resolution_document(self, issue_number: int, severity: IssueSeverity,
|
186 |
resolution: str, ai_solution: str) -> str:
|
|
|
107 |
return response.json()
|
108 |
|
109 |
def resolve_issue(self, token: str, owner: str, repo: str, issue_number: int, resolution: str, forked_repo: str) -> str:
|
110 |
+
try:
|
111 |
+
if not self.ai_provider:
|
112 |
+
raise ValueError("AI provider not initialized. Please initialize with an AI provider.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
113 |
|
114 |
+
# Create a unique branch name for this fix
|
115 |
+
branch_name = f"fix/issue-{issue_number}-{datetime.now().strftime('%Y%m%d-%H%M%S')}"
|
116 |
|
117 |
+
# Clone repository and create new branch
|
118 |
+
if not self.git.clone(forked_repo):
|
119 |
+
raise Exception("Failed to clone repository")
|
120 |
+
|
121 |
+
if not self.git.create_branch(branch_name):
|
122 |
+
raise Exception("Failed to create branch")
|
123 |
+
|
124 |
+
# Get repository content and analyze
|
125 |
+
code_contexts = self._get_main_branch_content(owner, repo)
|
126 |
+
|
127 |
+
# Get issue details
|
128 |
+
issue_url = f"{self.github_api.base_url}/repos/{owner}/{repo}/issues/{issue_number}"
|
129 |
+
response = requests.get(issue_url, headers=self.github_api.headers)
|
130 |
+
response.raise_for_status()
|
131 |
+
issue = response.json()
|
132 |
+
|
133 |
+
# Determine severity
|
134 |
+
severity = self._determine_severity(issue)
|
135 |
+
|
136 |
+
# Generate AI solution
|
137 |
+
context = f"Repository: {owner}/{repo}\nIssue #{issue_number}: {issue['title']}\n\nCode contexts:\n"
|
138 |
+
for ctx in code_contexts[:3]:
|
139 |
+
context += f"\nFile: {ctx.file_path}\n```{ctx.language}\n{ctx.content}\n```\n"
|
140 |
+
|
141 |
+
ai_solution = self.ai_provider.generate_solution(context, issue['body'])
|
142 |
+
|
143 |
+
# Create comprehensive resolution document
|
144 |
+
full_resolution = self._create_resolution_document(
|
145 |
+
issue_number, severity, resolution, ai_solution
|
146 |
+
)
|
147 |
+
|
148 |
+
# Save resolution
|
149 |
+
resolution_path = Path(RESOLUTIONS_DIRECTORY) / f"resolution_{issue_number}_{datetime.now().strftime('%Y%m%d_%H%M%S')}.md"
|
150 |
+
resolution_path.write_text(full_resolution)
|
151 |
+
|
152 |
+
# Prompt for manual intervention
|
153 |
+
print("\nAI-generated solution and original resolution have been saved.")
|
154 |
+
print(f"Please review and apply changes in: {self.temp_dir}")
|
155 |
+
input("Press Enter when changes are ready to commit...")
|
156 |
+
|
157 |
+
# Commit and push changes
|
158 |
+
if not self.git.commit(f"Fix #{issue_number}: {issue['title']}\n\n{resolution}"):
|
159 |
+
raise Exception("Failed to commit changes")
|
160 |
+
|
161 |
+
if not self.git.push("origin", branch_name):
|
162 |
+
raise Exception("Failed to push changes")
|
163 |
+
|
164 |
+
# Create pull request
|
165 |
+
pr = self.create_pull_request(
|
166 |
+
owner=owner,
|
167 |
+
repo=repo,
|
168 |
+
title=f"Fix #{issue_number}: {issue['title']}",
|
169 |
+
body=full_resolution,
|
170 |
+
head=branch_name
|
171 |
+
)
|
172 |
|
173 |
+
return f"Resolution implemented and PR created: {pr['html_url']}"
|
174 |
+
|
175 |
+
except Exception as e:
|
176 |
+
error_msg = f"Error resolving issue #{issue_number} in repository {owner}/{repo}: {str(e)}"
|
177 |
+
self.logger.error(error_msg)
|
178 |
+
return error_msg
|
179 |
+
|
180 |
+
finally:
|
181 |
+
# Cleanup
|
182 |
+
if self.temp_dir and os.path.exists(self.temp_dir):
|
183 |
+
shutil.rmtree(self.temp_dir)
|
184 |
|
185 |
def _create_resolution_document(self, issue_number: int, severity: IssueSeverity,
|
186 |
resolution: str, ai_solution: str) -> str:
|