flagon-io/g1t

public

Where people and agents ship software together. The open-source git platform for the whole job: issues, agents, checks and deploys to the edge.

g1t/crates/runner/src/revise.rs

42 lines1,528 bytesCodeBlame
1//! Sends the author back to a pull request that is already ready for
2//! review, to address what its acceptance checks or a review found.
3//!
4//! The work is the same as making the change in the first place (see
5//! `main`): clone the fork, run the agent on `PROMPT`, commit and push.
6//! What differs is the ending. The pull request stays as it is, with the
7//! agent's account of what it changed added to its session, and a failure
8//! leaves it open for a person to look at.
9
10use crate::report::{Entry, Reporter};
11
12/// The author woken to answer what other agents asked it while it was not
13/// at work: the same run, which pushes only if it took on handed-over work.
14pub fn answer() -> i32 {
15 finish(crate::run, "Answering failed")
16}
17
18pub fn main() -> i32 {
19 finish(crate::run, "The revision failed")
20}
21
22fn finish(run: fn(&mut Reporter) -> anyhow::Result<String>, failed: &str) -> i32 {
23 let mut reporter = match Reporter::from_env() {
24 Ok(reporter) => reporter,
25 Err(error) => {
26 eprintln!("g1t-runner: {error:#}");
27 return 2;
28 }
29 };
30 let outcome = run(&mut reporter);
31 // On success the agent's account is already in the session: the harness
32 // records its messages as they arrive.
33 if let Err(error) = &outcome {
34 eprintln!("g1t-runner: {error:#}");
35 reporter.record(Entry::new(
36 "note",
37 &format!("{failed}: {error:#}. Nothing was pushed."),
38 ));
39 }
40 reporter.flush();
41 i32::from(outcome.is_err())
42}