From 0bfa1df875f7dc8dfeeecc173db6e0239d1c1166 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Thu, 18 Apr 2024 19:19:10 +0100 Subject: [PATCH] refactor: delete dead code --- src/server/forge/forgejo/mod.rs | 97 --------------------------------- 1 file changed, 97 deletions(-) diff --git a/src/server/forge/forgejo/mod.rs b/src/server/forge/forgejo/mod.rs index c6b03c02..ef68c369 100644 --- a/src/server/forge/forgejo/mod.rs +++ b/src/server/forge/forgejo/mod.rs @@ -1,98 +1 @@ -use kxio::network; -use secrecy::ExposeSecret; - -use crate::server::{self, config::BranchName, gitforge}; - 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, - net: &kxio::network::Network, -) -> Result, 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::>(request).await?; - let commits = response - .response_body() - .unwrap_or_default() - .into_iter() - .map(gitforge::Commit::from) - .collect::>(); - - 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 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, -}