Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/deepseek-code-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ jobs:
- name: Run DeepSeekCode GitHub Action bridge
if: ${{ env.DEEPSEEK_API_KEY != '' }}
env:
GH_TOKEN: ${{ github.token }}
GITHUB_TOKEN: ${{ github.token }}
run: cargo run --locked -- github action --mode review --post --trigger "@deepseek"

Expand Down
1 change: 1 addition & 0 deletions .github/workflows/deepseek-code-write.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ jobs:
env:
DEEPSEEK_API_KEY: ${{ secrets.DEEPSEEK_API_KEY }}
GH_TOKEN: ${{ github.token }}
GITHUB_TOKEN: ${{ github.token }}
steps:
- name: Checkout DeepSeekCode
uses: actions/checkout@v4
Expand Down
7 changes: 7 additions & 0 deletions docs/hosted-workflow-fixture.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Hosted Workflow Fixture

This temporary fixture exists only to prove the hosted DeepSeekCode GitHub
review/write workflows can run against a real pull request.

Requested state: after
Current state: after
7 changes: 7 additions & 0 deletions src/cli/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,12 @@ pub enum PrAction {
Fix {
reference: String,
job: Option<String>,
request: Option<String>,
benchmark_gate: bool,
},
Patch {
reference: String,
request: Option<String>,
commit: bool,
benchmark_gate: bool,
},
Expand Down Expand Up @@ -587,6 +589,7 @@ pub fn parse_pr_subcommand(args: Vec<String>) -> Result<PrAction, String> {
Ok(PrAction::Fix {
reference,
job,
request: None,
benchmark_gate,
})
}
Expand All @@ -611,6 +614,7 @@ pub fn parse_pr_subcommand(args: Vec<String>) -> Result<PrAction, String> {
}
Ok(PrAction::Patch {
reference,
request: None,
commit,
benchmark_gate,
})
Expand Down Expand Up @@ -6720,10 +6724,12 @@ mod tests {
PrAction::Fix {
reference,
job,
request,
benchmark_gate,
} => {
assert_eq!(reference, "owner/repo#7");
assert_eq!(job.as_deref(), Some("test-rust"));
assert_eq!(request, None);
assert!(benchmark_gate);
}
_ => panic!("expected fix"),
Expand Down Expand Up @@ -6788,6 +6794,7 @@ mod tests {
PrAction::Patch {
commit: true,
benchmark_gate: true,
request: None,
ref reference,
} if reference == "5"
));
Expand Down
118 changes: 114 additions & 4 deletions src/cli/commands/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ struct GithubActionTarget {
repo: String,
number: u64,
mode: GithubActionMode,
request: Option<String>,
trigger_matched: bool,
reason: String,
}
Expand Down Expand Up @@ -132,10 +133,12 @@ fn run_action(args: GithubActionArgs) -> AppResult<()> {
GithubActionMode::Fix => PrAction::Fix {
reference,
job: args.job,
request: target.request.clone(),
benchmark_gate: false,
},
GithubActionMode::Patch => PrAction::Patch {
reference,
request: target.request.clone(),
commit: args.commit,
benchmark_gate: false,
},
Expand Down Expand Up @@ -400,6 +403,14 @@ fn github_background_task_prompt(
if let Some(job) = job.map(str::trim).filter(|job| !job.is_empty()) {
lines.push(format!("- CI job focus: {job}"));
}
if let Some(request) = target
.request
.as_deref()
.map(str::trim)
.filter(|request| !request.is_empty())
{
lines.push(format!("- Requested action: {request}"));
}
lines.push(String::new());
match target.mode {
GithubActionMode::Review => lines.push(
Expand Down Expand Up @@ -664,6 +675,7 @@ fn github_action_target_from_event(
repo,
number,
mode: resolve_action_mode(requested_mode, ""),
request: None,
trigger_matched: true,
reason: "pull_request events review without comment trigger".to_string(),
})
Expand All @@ -680,11 +692,14 @@ fn github_action_target_from_event(
.and_then(|comment| string_field(comment, "body").ok())
.unwrap_or("");
let matched = trigger_matches(comment_body, trigger, allow_untriggered)?;
let command = command_after_trigger(comment_body, trigger);
let mode = resolve_action_mode(requested_mode, command);
Ok(GithubActionTarget {
event_name: event_name.to_string(),
repo,
number: u64_field(issue, "number")?,
mode: resolve_action_mode(requested_mode, command_after_trigger(comment_body, trigger)),
mode,
request: action_request_from_command(command, mode),
trigger_matched: matched,
reason: "issue_comment trigger matched on pull request".to_string(),
})
Expand All @@ -696,11 +711,14 @@ fn github_action_target_from_event(
.and_then(|comment| string_field(comment, "body").ok())
.unwrap_or("");
let matched = trigger_matches(comment_body, trigger, allow_untriggered)?;
let command = command_after_trigger(comment_body, trigger);
let mode = resolve_action_mode(requested_mode, command);
Ok(GithubActionTarget {
event_name: event_name.to_string(),
repo,
number: u64_field(pull_request, "number")?,
mode: resolve_action_mode(requested_mode, command_after_trigger(comment_body, trigger)),
mode,
request: action_request_from_command(command, mode),
trigger_matched: matched,
reason: "pull_request_review_comment trigger matched".to_string(),
})
Expand All @@ -712,11 +730,14 @@ fn github_action_target_from_event(
.and_then(|review| string_field(review, "body").ok())
.unwrap_or("");
let matched = trigger_matches(review_body, trigger, allow_untriggered)?;
let command = command_after_trigger(review_body, trigger);
let mode = resolve_action_mode(requested_mode, command);
Ok(GithubActionTarget {
event_name: event_name.to_string(),
repo,
number: u64_field(pull_request, "number")?,
mode: resolve_action_mode(requested_mode, command_after_trigger(review_body, trigger)),
mode,
request: action_request_from_command(command, mode),
trigger_matched: matched,
reason: "pull_request_review trigger matched".to_string(),
})
Expand Down Expand Up @@ -759,6 +780,46 @@ fn command_after_trigger<'a>(body: &'a str, trigger: &str) -> &'a str {
body.get(index + trigger.len()..).unwrap_or("").trim()
}

fn action_request_from_command(command: &str, mode: GithubActionMode) -> Option<String> {
let command = command.trim();
if command.is_empty() {
return None;
}
let request = match leading_action_word(command) {
Some((word, rest_index)) if action_words_for_mode(mode).contains(&word.as_str()) => command
.get(rest_index..)
.unwrap_or("")
.trim_start_matches(|ch: char| ch.is_whitespace() || matches!(ch, ':' | '-' | ','))
.trim(),
_ => command,
};
if request.is_empty() {
None
} else {
Some(request.to_string())
}
}

fn leading_action_word(command: &str) -> Option<(String, usize)> {
let start = command
.char_indices()
.find_map(|(index, ch)| ch.is_ascii_alphanumeric().then_some(index))?;
let end = command[start..]
.char_indices()
.find_map(|(index, ch)| (!ch.is_ascii_alphanumeric()).then_some(start + index))
.unwrap_or(command.len());
Some((command[start..end].to_ascii_lowercase(), end))
}

fn action_words_for_mode(mode: GithubActionMode) -> &'static [&'static str] {
match mode {
GithubActionMode::Fix => &["fix", "repair"],
GithubActionMode::Patch => &["patch", "apply"],
GithubActionMode::Review => &["review"],
GithubActionMode::Auto => &[],
}
}

fn repository_full_name(root: &std::collections::BTreeMap<String, JsonValue>) -> AppResult<String> {
let repository = object_field(root, "repository")?;
string_field(repository, "full_name").map(str::to_string)
Expand Down Expand Up @@ -802,14 +863,19 @@ fn u64_field(map: &std::collections::BTreeMap<String, JsonValue>, key: &str) ->
}

fn render_action_target_json(target: &GithubActionTarget, post: bool) -> String {
let request = match target.request.as_deref() {
Some(request) => format!("\"{}\"", json_escape(request)),
None => "null".to_string(),
};
format!(
"{{\"kind\":\"deepseek.github_action_target.v1\",\"event\":\"{}\",\"repo\":\"{}\",\"number\":{},\"reference\":\"{}#{}\",\"mode\":\"{}\",\"post\":{},\"trigger_matched\":{},\"reason\":\"{}\"}}",
"{{\"kind\":\"deepseek.github_action_target.v1\",\"event\":\"{}\",\"repo\":\"{}\",\"number\":{},\"reference\":\"{}#{}\",\"mode\":\"{}\",\"request\":{},\"post\":{},\"trigger_matched\":{},\"reason\":\"{}\"}}",
json_escape(&target.event_name),
json_escape(&target.repo),
target.number,
json_escape(&target.repo),
target.number,
github_action_mode_label(target.mode),
request,
post,
target.trigger_matched,
json_escape(&target.reason)
Expand Down Expand Up @@ -1012,6 +1078,43 @@ mod tests {

assert_eq!(fix.mode, GithubActionMode::Fix);
assert_eq!(patch.mode, GithubActionMode::Patch);
assert_eq!(fix.request.as_deref(), Some("the failing CI"));
assert_eq!(patch.request.as_deref(), Some("this follow-up"));
}

#[test]
fn issue_comment_captures_patch_request_after_command_word() {
let target = github_action_target_from_event(
"issue_comment",
&issue_comment_event(
"@deepseek patch change docs/hosted-workflow-fixture.md Current state to after",
),
GithubActionMode::Auto,
"@deepseek",
false,
)
.unwrap();

assert_eq!(target.mode, GithubActionMode::Patch);
assert_eq!(
target.request.as_deref(),
Some("change docs/hosted-workflow-fixture.md Current state to after")
);
}

#[test]
fn issue_comment_empty_action_command_has_no_request() {
let target = github_action_target_from_event(
"issue_comment",
&issue_comment_event("@deepseek patch"),
GithubActionMode::Auto,
"@deepseek",
false,
)
.unwrap();

assert_eq!(target.mode, GithubActionMode::Patch);
assert_eq!(target.request, None);
}

#[test]
Expand Down Expand Up @@ -1083,13 +1186,15 @@ mod tests {
repo: "owner/repo".to_string(),
number: 7,
mode: GithubActionMode::Patch,
request: Some("tighten validation".to_string()),
trigger_matched: true,
reason: "ok".to_string(),
};
let rendered = render_action_target_json(&target, true);

assert!(rendered.contains("\"reference\":\"owner/repo#7\""));
assert!(rendered.contains("\"mode\":\"patch\""));
assert!(rendered.contains("\"request\":\"tighten validation\""));
assert!(rendered.contains("\"post\":true"));
}

Expand All @@ -1100,6 +1205,7 @@ mod tests {
repo: "owner/repo".to_string(),
number: 7,
mode: GithubActionMode::Review,
request: None,
trigger_matched: true,
reason: "ok".to_string(),
};
Expand All @@ -1117,6 +1223,7 @@ mod tests {
repo: "owner/repo".to_string(),
number: 7,
mode: GithubActionMode::Patch,
request: None,
trigger_matched: true,
reason: "ok".to_string(),
};
Expand All @@ -1132,6 +1239,7 @@ mod tests {
repo: "owner/repo".to_string(),
number: 11,
mode: GithubActionMode::Fix,
request: None,
trigger_matched: true,
reason: "ok".to_string(),
};
Expand Down Expand Up @@ -1260,6 +1368,7 @@ mod tests {
repo: "owner/repo".to_string(),
number: 11,
mode: GithubActionMode::Fix,
request: Some("fix the background task".to_string()),
trigger_matched: true,
reason: "issue_comment trigger matched on pull request".to_string(),
};
Expand All @@ -1269,6 +1378,7 @@ mod tests {

assert!(prompt.contains("owner/repo#11"));
assert!(prompt.contains("Mode: fix"));
assert!(prompt.contains("Requested action: fix the background task"));
assert!(prompt.contains("CI job focus: test-ci"));
assert!(prompt.contains("isolated task worktree"));
assert!(prompt.contains("Do not push"));
Expand Down
Loading