refactor: use 'repo_path' use consistently

This commit is contained in:
Paul Campbell 2024-04-20 20:49:38 +01:00
parent 1170510c44
commit 18143c17fd
7 changed files with 21 additions and 20 deletions

View file

@ -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<WebhookId> {
let mut ids: Vec<WebhookId> = 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,

View file

@ -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<RepoConfig>,
@ -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,
)
}

View file

@ -11,11 +11,11 @@ pub async fn get_all(
net: &Network,
) -> Result<Vec<gitforge::Branch>, 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");

View file

@ -160,7 +160,7 @@ async fn get_commit_history(
net: &kxio::network::Network,
) -> Result<Vec<gitforge::Commit>, 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(

View file

@ -13,12 +13,12 @@ pub(super) async fn contents_get(
file_path: &str,
) -> Result<String, ForgeFileError> {
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");

View file

@ -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(

View file

@ -31,7 +31,7 @@ pub fn forge_name(n: u32) -> ForgeName {
pub fn repo_details(n: u32, forge: ForgeDetails, config: Option<RepoConfig>) -> RepoDetails {
RepoDetails {
name: repo_alias(n),
repo: repo_path(n),
repo_path: repo_path(n),
branch: branch_name(n),
forge,
config,