Compare commits
2 Commits
9e63a0e3a8
...
121387dbd2
Author | SHA1 | Date | |
---|---|---|---|
121387dbd2
|
|||
0292577ff8
|
24
src/main.rs
24
src/main.rs
@@ -71,7 +71,7 @@ async fn main() -> Result<()> {
|
|||||||
toml::from_str(&config_content).context("Failed to parse TOML configuration")?;
|
toml::from_str(&config_content).context("Failed to parse TOML configuration")?;
|
||||||
|
|
||||||
if cli.dry_run {
|
if cli.dry_run {
|
||||||
info!("🔬 Performing a dry run. No migrations will be created.");
|
info!("Performing a dry run. No migrations will be created.");
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut headers = reqwest::header::HeaderMap::new();
|
let mut headers = reqwest::header::HeaderMap::new();
|
||||||
@@ -94,10 +94,7 @@ async fn main() -> Result<()> {
|
|||||||
.json::<GiteaUser>()
|
.json::<GiteaUser>()
|
||||||
.await
|
.await
|
||||||
.context("Failed to get Gitea user info. Check your API key and Gitea URL.")?;
|
.context("Failed to get Gitea user info. Check your API key and Gitea URL.")?;
|
||||||
info!(
|
info!("Authenticated as user '{}' (ID: {})", user.login, user.id);
|
||||||
"🔑 Authenticated as user '{}' (ID: {})",
|
|
||||||
user.login, user.id
|
|
||||||
);
|
|
||||||
|
|
||||||
// **MODIFIED**: We now build two sets: one for source URLs and one for existing repo names.
|
// **MODIFIED**: We now build two sets: one for source URLs and one for existing repo names.
|
||||||
info!("🔍 Fetching all existing repositories to build a local cache...");
|
info!("🔍 Fetching all existing repositories to build a local cache...");
|
||||||
@@ -147,7 +144,7 @@ async fn main() -> Result<()> {
|
|||||||
// CHECK 1: Has this exact source URL already been mirrored?
|
// CHECK 1: Has this exact source URL already been mirrored?
|
||||||
if existing_mirror_sources.contains(url_to_mirror) {
|
if existing_mirror_sources.contains(url_to_mirror) {
|
||||||
info!(
|
info!(
|
||||||
"✅ Mirror for source URL '{}' already exists. Skipping.",
|
"Mirror for source URL '{}' already exists. Skipping.",
|
||||||
url_to_mirror
|
url_to_mirror
|
||||||
);
|
);
|
||||||
continue;
|
continue;
|
||||||
@@ -164,7 +161,7 @@ async fn main() -> Result<()> {
|
|||||||
// CHECK 2: Will creating this mirror cause a name collision?
|
// CHECK 2: Will creating this mirror cause a name collision?
|
||||||
if existing_repo_names.contains(&target_repo_name) {
|
if existing_repo_names.contains(&target_repo_name) {
|
||||||
warn!(
|
warn!(
|
||||||
"⚠️ Cannot create mirror for '{}'. A repository named '{}' already exists. Skipping.",
|
"Cannot create mirror for '{}'. A repository named '{}' already exists. Skipping.",
|
||||||
url_to_mirror, target_repo_name
|
url_to_mirror, target_repo_name
|
||||||
);
|
);
|
||||||
continue;
|
continue;
|
||||||
@@ -172,7 +169,7 @@ async fn main() -> Result<()> {
|
|||||||
|
|
||||||
// If both checks pass, we are clear to create the migration.
|
// If both checks pass, we are clear to create the migration.
|
||||||
info!(
|
info!(
|
||||||
"🔎 Mirror for '{}' not found and name '{}' is available. Needs creation.",
|
"Mirror for '{}' not found and name '{}' is available. Needs creation.",
|
||||||
url_to_mirror, target_repo_name
|
url_to_mirror, target_repo_name
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -189,7 +186,7 @@ async fn main() -> Result<()> {
|
|||||||
uid: user.id,
|
uid: user.id,
|
||||||
repo_name: &target_repo_name,
|
repo_name: &target_repo_name,
|
||||||
mirror: true,
|
mirror: true,
|
||||||
private: true,
|
private: false,
|
||||||
description: format!("Mirror of {}", url_to_mirror),
|
description: format!("Mirror of {}", url_to_mirror),
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -206,10 +203,7 @@ async fn main() -> Result<()> {
|
|||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
if response.status().is_success() {
|
if response.status().is_success() {
|
||||||
info!(
|
info!("Successfully initiated migration for '{}'.", url_to_mirror);
|
||||||
"✅ Successfully initiated migration for '{}'.",
|
|
||||||
url_to_mirror
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
let status = response.status();
|
let status = response.status();
|
||||||
let error_body = response
|
let error_body = response
|
||||||
@@ -217,13 +211,13 @@ async fn main() -> Result<()> {
|
|||||||
.await
|
.await
|
||||||
.unwrap_or_else(|_| "Could not read error body".to_string());
|
.unwrap_or_else(|_| "Could not read error body".to_string());
|
||||||
error!(
|
error!(
|
||||||
"🔥 Failed to create migration for '{}'. Status: {}. Body: {}",
|
"Failed to create migration for '{}'. Status: {}. Body: {}",
|
||||||
url_to_mirror, status, error_body
|
url_to_mirror, status, error_body
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
info!("✨ All tasks completed.");
|
info!("All tasks completed.");
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user