feat(server): implement forge::forgejo::get_commit_history
Some checks failed
ci/woodpecker/push/cron-docker-builder Pipeline was successful
ci/woodpecker/push/tag-created Pipeline was successful
ci/woodpecker/push/push-next Pipeline failed

Closes kemitix/git-next#13
This commit is contained in:
Paul Campbell 2024-04-10 11:48:24 +01:00
parent e27b050a09
commit a5e9421405

View file

@ -1,6 +1,6 @@
use kxio::network; use kxio::network;
use terrors::OneOf; use terrors::OneOf;
use tracing::{error, info}; use tracing::{debug, error, info, warn};
use crate::server::{actors::repo::status::Status, config::BranchName, forge}; 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}" "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( let request = network::NetRequest::new(
network::RequestMethod::Get, network::RequestMethod::Get,
url, url,
@ -66,13 +66,48 @@ struct Commit {
} }
pub async fn get_commit_status( pub async fn get_commit_status(
_next: forge::Commit, next: forge::Commit,
_repo_details: crate::server::config::RepoDetails, repo_details: crate::server::config::RepoDetails,
_net: network::Network, net: network::Network,
) -> Status { ) -> Status {
// TODO: (#13) check statuses for next head - if ok, advance main to next and reassess let hostname = &repo_details.forge.hostname;
// https://{hostname}/api/v1/repos/{path}/commits/{commit}/status?token={token} let path = &repo_details.repo;
Status::Pending 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)] #[derive(Debug, serde::Deserialize)]