swarm-controller: record builder runs with nix's tail and link the status to them
This commit is contained in:
parent
70a0435814
commit
d4714072a9
11 changed files with 833 additions and 48 deletions
|
|
@ -62,6 +62,16 @@ pub mod site_admin;
|
|||
/// sends, in characters. The forge keeps more; its PR view shows one line.
|
||||
pub const STATUS_DESCRIPTION_MAX: usize = 200;
|
||||
|
||||
/// One commit status, as [`Client::create_commit_status`] writes it.
|
||||
pub struct CommitStatus<'a> {
|
||||
pub context: &'a str,
|
||||
pub state: CommitStatusState,
|
||||
/// Cut to [`STATUS_DESCRIPTION_MAX`] characters.
|
||||
pub description: &'a str,
|
||||
/// Where the status links to, if anywhere.
|
||||
pub target_url: Option<&'a str>,
|
||||
}
|
||||
|
||||
/// `description` cut to [`STATUS_DESCRIPTION_MAX`] characters, an ellipsis
|
||||
/// marking a cut.
|
||||
fn status_description(description: &str) -> String {
|
||||
|
|
@ -1213,9 +1223,7 @@ impl Client {
|
|||
Ok(rows.into_iter().flatten().collect())
|
||||
}
|
||||
|
||||
/// Set the commit status named `context` on `sha` of `owner/repo` to
|
||||
/// `state`, with `description` cut to [`STATUS_DESCRIPTION_MAX`]
|
||||
/// characters.
|
||||
/// Set `status` on `sha` of `owner/repo`.
|
||||
///
|
||||
/// # Errors
|
||||
/// The forge refused the status.
|
||||
|
|
@ -1224,15 +1232,14 @@ impl Client {
|
|||
owner: &str,
|
||||
repo: &str,
|
||||
sha: &str,
|
||||
context: &str,
|
||||
state: CommitStatusState,
|
||||
description: &str,
|
||||
status: CommitStatus<'_>,
|
||||
) -> Result<()> {
|
||||
let context = status.context;
|
||||
let status = CreateStatusOption {
|
||||
context: Some(context.to_owned()),
|
||||
description: Some(status_description(description)),
|
||||
state: Some(state),
|
||||
target_url: None,
|
||||
description: Some(status_description(status.description)),
|
||||
state: Some(status.state),
|
||||
target_url: status.target_url.map(str::to_owned),
|
||||
};
|
||||
self.api
|
||||
.call(|api| {
|
||||
|
|
@ -2796,9 +2803,12 @@ mod tests {
|
|||
CONFIG_ORG,
|
||||
"atlas",
|
||||
"abc",
|
||||
"swarm-builder",
|
||||
CommitStatusState::Failure,
|
||||
"error: boom",
|
||||
CommitStatus {
|
||||
context: "swarm-builder",
|
||||
state: CommitStatusState::Failure,
|
||||
description: "error: boom",
|
||||
target_url: Some("https://swarm.example/api/builder/runs/r1"),
|
||||
},
|
||||
)
|
||||
.await
|
||||
.expect("the stub accepts the status");
|
||||
|
|
@ -2809,5 +2819,9 @@ mod tests {
|
|||
assert_eq!(body["context"], "swarm-builder");
|
||||
assert_eq!(body["state"], "failure");
|
||||
assert_eq!(body["description"], "error: boom");
|
||||
assert_eq!(
|
||||
body["target_url"],
|
||||
"https://swarm.example/api/builder/runs/r1"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue