refactor: delete dead code

This commit is contained in:
Paul Campbell 2024-04-18 19:19:10 +01:00
parent 0d57ee7bc0
commit 0bfa1df875

View file

@ -1,98 +1 @@
use kxio::network;
use secrecy::ExposeSecret;
use crate::server::{self, config::BranchName, gitforge};
pub mod config; pub mod config;
#[tracing::instrument(fields(%branch_name),skip_all)]
async fn get_commit_history(
repo_details: &server::config::RepoDetails,
branch_name: &BranchName,
find_commits: Vec<gitforge::Commit>,
net: &kxio::network::Network,
) -> Result<Vec<gitforge::Commit>, network::NetworkError> {
let hostname = &repo_details.forge.hostname;
let path = &repo_details.repo;
let mut page = 1;
let limit = match find_commits.is_empty() {
true => 1,
false => 50,
};
let options = "stat=false&verification=false&files=false";
let mut all_commits = Vec::new();
loop {
let token = repo_details.forge.token.expose_secret();
let url = network::NetUrl::new(format!(
"https://{hostname}/api/v1/repos/{path}/commits?sha={branch_name}&{options}&token={token}&page={page}&limit={limit}"
));
let request = network::NetRequest::new(
network::RequestMethod::Get,
url,
network::NetRequestHeaders::new(),
network::RequestBody::None,
network::ResponseType::Json,
None,
network::NetRequestLogging::None,
);
let response = net.get::<Vec<Commit>>(request).await?;
let commits = response
.response_body()
.unwrap_or_default()
.into_iter()
.map(gitforge::Commit::from)
.collect::<Vec<_>>();
let found = find_commits.is_empty()
|| find_commits
.clone()
.into_iter()
.any(|find_commit| commits.iter().any(|commit| commit == &find_commit));
let at_end = commits.len() < limit;
all_commits.extend(commits);
if found || at_end {
break;
}
page += 1;
}
Ok(all_commits)
}
#[allow(dead_code)]
#[derive(Debug, Default, serde::Deserialize)]
struct Commit {
sha: String,
commit: RepoCommit,
}
#[allow(dead_code)]
#[derive(Debug, Default, serde::Deserialize)]
struct RepoCommit {
message: String,
}
impl From<Commit> for gitforge::Commit {
fn from(value: Commit) -> Self {
Self::new(&value.sha, &value.commit.message)
}
}
#[derive(Debug, serde::Deserialize)]
pub struct CombinedStatus {
pub state: CommitStatusState,
}
#[derive(Debug, serde::Deserialize)]
pub enum CommitStatusState {
#[serde(rename = "success")]
Success,
#[serde(rename = "pending")]
Pending,
#[serde(rename = "failure")]
Failure,
#[serde(rename = "error")]
Error,
#[serde(rename = "")]
Blank,
}