feat(server): implement forge::get_commit_history
Closes kemitix/git-next#13
This commit is contained in:
parent
e27b050a09
commit
a5e9421405
1 changed files with 43 additions and 8 deletions
|
@ -1,6 +1,6 @@
|
|||
use kxio::network;
|
||||
use terrors::OneOf;
|
||||
use tracing::{error, info};
|
||||
use tracing::{debug, error, info, warn};
|
||||
|
||||
use crate::server::{actors::repo::status::Status, config::BranchName, forge};
|
||||
|
||||
|
@ -33,7 +33,7 @@ async fn get_commit_history(
|
|||
"https://{hostname}/api/v1/repos/{path}/commits?sha={branch_name}&stat=false&files=false&token={token}"
|
||||
));
|
||||
|
||||
info!(%url, "Fetching commits");
|
||||
debug!(%url, "Fetching commits");
|
||||
let request = network::NetRequest::new(
|
||||
network::RequestMethod::Get,
|
||||
url,
|
||||
|
@ -66,13 +66,48 @@ struct Commit {
|
|||
}
|
||||
|
||||
pub async fn get_commit_status(
|
||||
_next: forge::Commit,
|
||||
_repo_details: crate::server::config::RepoDetails,
|
||||
_net: network::Network,
|
||||
next: forge::Commit,
|
||||
repo_details: crate::server::config::RepoDetails,
|
||||
net: network::Network,
|
||||
) -> Status {
|
||||
// TODO: (#13) check statuses for next head - if ok, advance main to next and reassess
|
||||
// https://{hostname}/api/v1/repos/{path}/commits/{commit}/status?token={token}
|
||||
Status::Pending
|
||||
let hostname = &repo_details.forge.hostname;
|
||||
let path = &repo_details.repo;
|
||||
let token = &repo_details.forge.token;
|
||||
let url = network::NetUrl::new(format!(
|
||||
"https://{hostname}/api/v1/repos/{path}/commits/{next}/status?token={token}"
|
||||
));
|
||||
|
||||
info!(%url, "Fetching commit status");
|
||||
let request = network::NetRequest::new(
|
||||
network::RequestMethod::Get,
|
||||
url,
|
||||
network::NetRequestHeaders::new(),
|
||||
network::RequestBody::None,
|
||||
network::ResponseType::Json,
|
||||
None,
|
||||
network::NetRequestLogging::None,
|
||||
);
|
||||
let result = net.get::<CombinedStatus>(request).await;
|
||||
match result {
|
||||
Ok(response) => {
|
||||
match response.response_body() {
|
||||
Some(status) => match status.state {
|
||||
CommitStatusState::Success => Status::Pass,
|
||||
CommitStatusState::Pending => Status::Pending,
|
||||
CommitStatusState::Failure => Status::Fail,
|
||||
CommitStatusState::Error => Status::Fail,
|
||||
},
|
||||
None => {
|
||||
warn!("No status found for commit");
|
||||
Status::Pending // assume issue is transient and allow retry
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
error!(?e, "Failed to get commit status");
|
||||
Status::Pending // assume issue is transient and allow retry
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, serde::Deserialize)]
|
||||
|
|
Loading…
Reference in a new issue