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

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