(
event_name: &str,
payload: &serde_json::Value,
)
| 4524 | } |
| 4525 | |
| 4526 | fn prompt_from_github_context( |
| 4527 | event_name: &str, |
| 4528 | payload: &serde_json::Value, |
| 4529 | ) -> anyhow::Result<String> { |
| 4530 | let custom_prompt = std::env::var("PROMPT") |
| 4531 | .ok() |
| 4532 | .map(|v| v.trim().to_string()) |
| 4533 | .filter(|v| !v.is_empty()); |
| 4534 | |
| 4535 | if github_is_repo_event(event_name) || event_name == "issues" { |
| 4536 | return custom_prompt.ok_or_else(|| { |
| 4537 | let label = if github_is_repo_event(event_name) { |
| 4538 | "scheduled and workflow_dispatch" |
| 4539 | } else { |
| 4540 | "issues" |
| 4541 | }; |
| 4542 | anyhow::anyhow!("PROMPT is required for {} events.", label) |
| 4543 | }); |
| 4544 | } |
| 4545 | |
| 4546 | if let Some(prompt) = custom_prompt { |
| 4547 | return Ok(prompt); |
| 4548 | } |
| 4549 | |
| 4550 | if github_is_comment_event(event_name) { |
| 4551 | let comment = payload |
| 4552 | .get("comment") |
| 4553 | .ok_or_else(|| anyhow::anyhow!("Comment payload is missing `comment` object."))?; |
| 4554 | let body = comment |
| 4555 | .get("body") |
| 4556 | .and_then(|v| v.as_str()) |
| 4557 | .unwrap_or_default() |
| 4558 | .trim() |
| 4559 | .to_string(); |
| 4560 | let body_lower = body.to_ascii_lowercase(); |
| 4561 | let mentions = github_mentions(); |
| 4562 | if mentions.is_empty() { |
| 4563 | anyhow::bail!("No valid mentions configured in MENTIONS."); |
| 4564 | } |
| 4565 | let exact_mention = mentions.iter().any(|m| body_lower == *m); |
| 4566 | let contains_mention = mentions.iter().any(|m| body_lower.contains(m)); |
| 4567 | let review_context = if event_name == "pull_request_review_comment" { |
| 4568 | let file = comment |
| 4569 | .get("path") |
| 4570 | .and_then(|v| v.as_str()) |
| 4571 | .unwrap_or("<unknown-file>"); |
| 4572 | let line = comment |
| 4573 | .get("line") |
| 4574 | .and_then(|v| v.as_u64()) |
| 4575 | .map(|v| v.to_string()) |
| 4576 | .unwrap_or_else(|| "?".to_string()); |
| 4577 | let diff_hunk = comment |
| 4578 | .get("diff_hunk") |
| 4579 | .and_then(|v| v.as_str()) |
| 4580 | .unwrap_or_default(); |
| 4581 | Some((file.to_string(), line, diff_hunk.to_string())) |
| 4582 | } else { |
| 4583 | None |
no test coverage detected