From 18143c17fd519e5c80e6ea2a37c0095ba76b7a30 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Sat, 20 Apr 2024 20:49:38 +0100 Subject: [PATCH] refactor: use 'repo_path' use consistently --- src/server/actors/repo/webhook.rs | 13 +++++++------ src/server/config/mod.rs | 10 +++++----- src/server/gitforge/forgejo/branch/get_all.rs | 4 ++-- .../gitforge/forgejo/branch/validate_positions.rs | 4 ++-- src/server/gitforge/forgejo/file/mod.rs | 4 ++-- src/server/gitforge/forgejo/mod.rs | 4 ++-- src/server/gitforge/tests/common.rs | 2 +- 7 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/server/actors/repo/webhook.rs b/src/server/actors/repo/webhook.rs index f94cce3..c9b6a2d 100644 --- a/src/server/actors/repo/webhook.rs +++ b/src/server/actors/repo/webhook.rs @@ -64,11 +64,11 @@ pub async fn unregister( ) { info!(?webhook_id, "unregister webhook"); let hostname = &repo_details.forge.hostname; - let path = repo_details.repo; + let repo_path = repo_details.repo_path; use secrecy::ExposeSecret; let token = repo_details.forge.token.expose_secret(); let url = network::NetUrl::new(format!( - "https://{hostname}/api/v1/repos/{path}/hooks/{webhook_id}?token={token}" + "https://{hostname}/api/v1/repos/{repo_path}/hooks/{webhook_id}?token={token}" )); let request = network::NetRequest::new( network::RequestMethod::Delete, @@ -105,11 +105,11 @@ pub async fn register( info!("Registering webhook"); let hostname = &repo_details.forge.hostname; - let path = repo_details.repo; + let repo_path = repo_details.repo_path; use secrecy::ExposeSecret; let token = repo_details.forge.token.expose_secret(); let url = network::NetUrl::new(format!( - "https://{hostname}/api/v1/repos/{path}/hooks?token={token}" + "https://{hostname}/api/v1/repos/{repo_path}/hooks?token={token}" )); let repo_alias = &repo_details.name; let headers = network::NetRequestHeaders::new().with("Content-Type", "application/json"); @@ -153,12 +153,13 @@ async fn find_existing_webhooks( ) -> Vec { let mut ids: Vec = vec![]; let hostname = &repo_details.forge.hostname; - let path = &repo_details.repo; + let repo_path = &repo_details.repo_path; let mut page = 1; loop { use secrecy::ExposeSecret; let token = &repo_details.forge.token.expose_secret(); - let url = format!("https://{hostname}/api/v1/repos/{path}/hooks?page={page}&token={token}"); + let url = + format!("https://{hostname}/api/v1/repos/{repo_path}/hooks?page={page}&token={token}"); let net_url = network::NetUrl::new(url); let request = network::NetRequest::new( network::RequestMethod::Get, diff --git a/src/server/config/mod.rs b/src/server/config/mod.rs index 4a95622..6716594 100644 --- a/src/server/config/mod.rs +++ b/src/server/config/mod.rs @@ -320,7 +320,7 @@ impl Deref for BranchName { #[derive(Clone, Debug)] pub struct RepoDetails { pub name: RepoAlias, - pub repo: RepoPath, + pub repo_path: RepoPath, pub branch: BranchName, pub forge: ForgeDetails, pub config: Option, @@ -334,7 +334,7 @@ impl RepoDetails { ) -> Self { Self { name: name.clone(), - repo: RepoPath(server_repo_config.repo.clone()), + repo_path: RepoPath(server_repo_config.repo.clone()), config: server_repo_config.repo_config(), branch: BranchName(server_repo_config.branch.clone()), forge: ForgeDetails { @@ -350,11 +350,11 @@ impl RepoDetails { let repo_details = self; let user = &repo_details.forge.user; let hostname = &repo_details.forge.hostname; - let path = &repo_details.repo; + let repo_path = &repo_details.repo_path; use secrecy::ExposeSecret; let expose_secret = &repo_details.forge.token; let token = expose_secret.expose_secret(); - let origin = format!("https://{user}:{token}@{hostname}/{path}.git"); + let origin = format!("https://{user}:{token}@{hostname}/{repo_path}.git"); origin.into() } } @@ -368,7 +368,7 @@ impl Display for RepoDetails { self.forge.forge_type, self.forge.hostname, self.forge.user, - self.repo, + self.repo_path, self.branch, ) } diff --git a/src/server/gitforge/forgejo/branch/get_all.rs b/src/server/gitforge/forgejo/branch/get_all.rs index 0b69c1e..d11a296 100644 --- a/src/server/gitforge/forgejo/branch/get_all.rs +++ b/src/server/gitforge/forgejo/branch/get_all.rs @@ -11,11 +11,11 @@ pub async fn get_all( net: &Network, ) -> Result, ForgeBranchError> { let hostname = &repo_details.forge.hostname; - let path = &repo_details.repo; + let repo_path = &repo_details.repo_path; use secrecy::ExposeSecret; let token = repo_details.forge.token.expose_secret(); let url = network::NetUrl::new(format!( - "https://{hostname}/api/v1/repos/{path}/branches?token={token}" + "https://{hostname}/api/v1/repos/{repo_path}/branches?token={token}" )); info!(%url, "Listing branches"); diff --git a/src/server/gitforge/forgejo/branch/validate_positions.rs b/src/server/gitforge/forgejo/branch/validate_positions.rs index d6b8aef..b13c1e4 100644 --- a/src/server/gitforge/forgejo/branch/validate_positions.rs +++ b/src/server/gitforge/forgejo/branch/validate_positions.rs @@ -160,7 +160,7 @@ async fn get_commit_history( net: &kxio::network::Network, ) -> Result, network::NetworkError> { let hostname = &repo_details.forge.hostname; - let path = &repo_details.repo; + let repo_path = &repo_details.repo_path; let mut page = 1; let limit = match find_commits.is_empty() { @@ -174,7 +174,7 @@ async fn get_commit_history( use secrecy::ExposeSecret; let token = api_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}" + "https://{hostname}/api/v1/repos/{repo_path}/commits?sha={branch_name}&{options}&token={token}&page={page}&limit={limit}" )); let request = network::NetRequest::new( diff --git a/src/server/gitforge/forgejo/file/mod.rs b/src/server/gitforge/forgejo/file/mod.rs index 42c0759..3d5b9c1 100644 --- a/src/server/gitforge/forgejo/file/mod.rs +++ b/src/server/gitforge/forgejo/file/mod.rs @@ -13,12 +13,12 @@ pub(super) async fn contents_get( file_path: &str, ) -> Result { let hostname = &repo_details.forge.hostname; - let path = &repo_details.repo; + let repo_path = &repo_details.repo_path; let api_token = &repo_details.forge.token; use secrecy::ExposeSecret; let token = api_token.expose_secret(); let url = network::NetUrl::new(format!( - "https://{hostname}/api/v1/repos/{path}/contents/{file_path}?ref={branch}&token={token}" + "https://{hostname}/api/v1/repos/{repo_path}/contents/{file_path}?ref={branch}&token={token}" )); info!(%url, "Loading config"); diff --git a/src/server/gitforge/forgejo/mod.rs b/src/server/gitforge/forgejo/mod.rs index 24e4ce2..19cc468 100644 --- a/src/server/gitforge/forgejo/mod.rs +++ b/src/server/gitforge/forgejo/mod.rs @@ -61,12 +61,12 @@ impl super::ForgeLike for ForgeJoEnv { async fn commit_status(&self, commit: &gitforge::Commit) -> gitforge::CommitStatus { let repo_details = &self.repo_details; let hostname = &repo_details.forge.hostname; - let path = &repo_details.repo; + let repo_path = &repo_details.repo_path; let api_token = &repo_details.forge.token; use secrecy::ExposeSecret; let token = api_token.expose_secret(); let url = network::NetUrl::new(format!( - "https://{hostname}/api/v1/repos/{path}/commits/{commit}/status?token={token}" + "https://{hostname}/api/v1/repos/{repo_path}/commits/{commit}/status?token={token}" )); let request = network::NetRequest::new( diff --git a/src/server/gitforge/tests/common.rs b/src/server/gitforge/tests/common.rs index 374216a..7ad0dce 100644 --- a/src/server/gitforge/tests/common.rs +++ b/src/server/gitforge/tests/common.rs @@ -31,7 +31,7 @@ pub fn forge_name(n: u32) -> ForgeName { pub fn repo_details(n: u32, forge: ForgeDetails, config: Option) -> RepoDetails { RepoDetails { name: repo_alias(n), - repo: repo_path(n), + repo_path: repo_path(n), branch: branch_name(n), forge, config,