Skip to content

Commit e6cc596

Browse files
committed
EX-344: fix jira v2
1 parent 3ab5a4b commit e6cc596

File tree

3 files changed

+22
-30
lines changed

3 files changed

+22
-30
lines changed

src/code_review_agent/cli.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -451,16 +451,6 @@ def assess(
451451
logging.info("🔍 Gathering data for Jira assessment...")
452452
commit_messages = git_utils.get_commit_messages(repo_path, base_ref, head_ref)
453453

454-
logging.info(f"📊 Generated structured diff summary")
455-
structured_diff_summary = git_utils.get_structured_diff_summary(repo_path, base_ref, head_ref)
456-
457-
458-
if "error" in structured_diff_summary:
459-
logging.error("Failed to generate structured diff summary. Skipping Jira assessment.")
460-
return
461-
462-
463-
logging.info("\n--- Summarizing changes for Jira ---")
464454

465455
# Manual override
466456
manual_task = os.environ.get("JIRA_TASK_ID")
@@ -500,6 +490,13 @@ def assess(
500490
logging.info("No task ID found; skipping relevance assessment.")
501491
return
502492

493+
logging.info("📊 Generating structured diff summary...")
494+
structured_diff_summary = git_utils.get_structured_diff_summary(repo_path, base_ref, head_ref)
495+
496+
if "error" in structured_diff_summary:
497+
logging.error("Failed to generate structured diff summary. Skipping Jira assessment.")
498+
return
499+
503500
logging.info("\n--- Summarizing changes for Jira ---")
504501

505502
summary = summarizer.summarize_changes_for_jira(

src/code_review_agent/git_utils.py

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -233,27 +233,20 @@ def create_annotated_file(full_content: str, diff_content: str) -> str:
233233

234234

235235
def get_structured_diff_summary(repo_path: str, base_ref: str, head_ref: str) -> dict:
236-
"""Analyzes the diff and returns a structured summary of changes."""
237-
summary = {
238-
"files_added": [], "files_deleted": [], "files_renamed": [],
239-
"files_modified": [], "total_insertions": 0, "total_deletions": 0,
240-
}
236+
"""Analyzes the diff and returns a structured summary using `git diff --numstat`."""
237+
summary = { "files_changed": [] }
241238
try:
242239
repo = git.Repo(repo_path, search_parent_directories=True)
243-
base_commit = repo.commit(base_ref)
244-
head_commit = repo.commit(head_ref)
245-
246-
diff_output = repo.git.diff(base_commit, head_commit, '--numstat')
247-
240+
diff_output = repo.git.diff(base_ref, head_ref, '--numstat')
248241
for line in diff_output.splitlines():
249242
parts = line.split('\t')
250243
if len(parts) == 3:
251244
insertions, deletions, path = parts
252-
summary["total_insertions"] += int(insertions)
253-
summary["total_deletions"] += int(deletions)
254-
if path not in summary["files_modified"]:
255-
summary["files_modified"].append(path)
256-
245+
summary["files_changed"].append({
246+
"path": path,
247+
"insertions": int(insertions),
248+
"deletions": int(deletions)
249+
})
257250
return summary
258251
except Exception as e:
259252
logger.error(f"Could not get structured diff summary: {e}", exc_info=True)

src/code_review_agent/summarizer.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ def summarize_changes_for_jira(
1717
model = llm_config.get('models', {}).get('summarizer', 'google/gemini-pro-1.5')
1818

1919
system_prompt = """
20-
You are an expert AI software analyst. Your task is to analyze a structured summary of code changes and produce a high-level summary for a Jira ticket.
21-
DO NOT analyze the code itself, only the provided metadata.
20+
You are an expert AI software analyst. Your task is to analyze metadata about code changes and produce a high-level summary for a Jira ticket.
2221
2322
CRITICAL OUTPUT FORMATTING RULE:
2423
Your entire response MUST be a single, valid JSON object that adheres to the `MergeSummary` schema.
@@ -29,19 +28,22 @@ def summarize_changes_for_jira(
2928
user_prompt = f"""
3029
Please analyze the following data and provide a structured summary.
3130
31+
**Jira Task Details:**
32+
```
3233
{jira_details}
34+
```
3335
3436
**Commit Messages:**
3537
```
3638
{commit_messages}
3739
```
3840
39-
**Structured Summary of Code Changes:**
41+
**Structured Summary of Code Changes (file paths, insertions, deletions):**
4042
```json
4143
{diff_summary_text}
4244
```
4345
44-
Based on this metadata, provide your assessment.
46+
Based on all this metadata, provide your assessment.
4547
Return your findings as a raw JSON object string.
4648
"""
4749

@@ -54,14 +56,14 @@ def summarize_changes_for_jira(
5456
],
5557
temperature=0
5658
)
57-
5859
raw_response_text = response.choices[0].message.content.strip()
5960

6061
try:
6162
parsed_json = json.loads(raw_response_text, strict=False)
6263
return MergeSummary(**parsed_json)
6364
except (json.JSONDecodeError, ValidationError) as e:
6465
logger.warning(f"Failed to parse summary response. Error: {e}")
66+
logger.debug(f"Problematic response was: '{raw_response_text}'")
6567
return None
6668

6769
except Exception as e:

0 commit comments

Comments
 (0)