MCPcopy Index your code
hub / github.com/ChrisFeldmeier/OpenCodeRust / prompt_from_github_context

Function prompt_from_github_context

crates/opencode-cli/src/main.rs:4526–4620  ·  view source on GitHub ↗
(
    event_name: &str,
    payload: &serde_json::Value,
)

Source from the content-addressed store, hash-verified

4524}
4525
4526fn 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

Callers 1

handle_github_commandFunction · 0.85

Calls 8

github_is_repo_eventFunction · 0.85
github_is_comment_eventFunction · 0.85
github_mentionsFunction · 0.85
is_emptyMethod · 0.80
containsMethod · 0.80
filterMethod · 0.45
getMethod · 0.45
as_strMethod · 0.45

Tested by

no test coverage detected