Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
568e5ece49
|
|||
|
4c2086e2b4
|
|||
|
f13906d762
|
|||
|
d8fd1ac57d
|
|||
|
eeeb42b48b
|
1189
Cargo.lock
generated
1189
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -4,9 +4,9 @@ version = "0.1.0"
|
|||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
clap = { version = "4.0", features = ["derive", "env"] }
|
clap = { version = "4.5", features = ["derive", "env"] }
|
||||||
tokio = { version = "1", features = ["full"] }
|
tokio = { version = "1", features = ["full"] }
|
||||||
reqwest = { version = "0.12", features = ["json"] }
|
reqwest = { version = "0.13", features = ["json", "query"] }
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
toml = "0.9"
|
toml = "0.9"
|
||||||
|
|||||||
11
GEMINI.md
Normal file
11
GEMINI.md
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
# Project: Tool to help handle mirroring of projects to Gitea
|
||||||
|
|
||||||
|
## General Instructions
|
||||||
|
|
||||||
|
Look at the `vibe_coding_log` directory (especially the `README.md` file) where you will track conversations for audit/archival purposes.
|
||||||
|
|
||||||
|
Any changes you do should be as minimal as possible to the underlying code (to make code review easier). Also, follow coding styles that already exist and do not deviate from them.
|
||||||
|
|
||||||
|
Always run `cargo check` and `cargo test` and `cargo clippy` to maintain general project quality.
|
||||||
|
|
||||||
|
When creating commits, look at past commits and try to follow that style (so no smileys).
|
||||||
42
build.rs
Normal file
42
build.rs
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
use std::process::Command;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
// Only re-run if .git state changes
|
||||||
|
println!("cargo:rerun-if-changed=.git/HEAD");
|
||||||
|
println!("cargo:rerun-if-changed=.git/refs/tags");
|
||||||
|
|
||||||
|
let output = Command::new("git")
|
||||||
|
.args(["describe", "--tags", "--exact-match"])
|
||||||
|
.output();
|
||||||
|
|
||||||
|
let version = if let Ok(output) = output {
|
||||||
|
if output.status.success() {
|
||||||
|
// Exact tag match
|
||||||
|
String::from_utf8(output.stdout).unwrap().trim().to_string()
|
||||||
|
} else {
|
||||||
|
// Not an exact match, construct version string
|
||||||
|
let tag_output = Command::new("git")
|
||||||
|
.args(["describe", "--tags", "--abbrev=0"])
|
||||||
|
.output()
|
||||||
|
.expect("Failed to execute git describe");
|
||||||
|
|
||||||
|
let sha_output = Command::new("git")
|
||||||
|
.args(["rev-parse", "--short", "HEAD"])
|
||||||
|
.output()
|
||||||
|
.expect("Failed to execute git rev-parse");
|
||||||
|
|
||||||
|
if tag_output.status.success() && sha_output.status.success() {
|
||||||
|
let tag = String::from_utf8(tag_output.stdout).unwrap().trim().to_string();
|
||||||
|
let sha = String::from_utf8(sha_output.stdout).unwrap().trim().to_string();
|
||||||
|
format!("{}-g{}", tag, sha)
|
||||||
|
} else {
|
||||||
|
// Fallback if git fails or no tags
|
||||||
|
"unknown".to_string()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
"unknown".to_string()
|
||||||
|
};
|
||||||
|
|
||||||
|
println!("cargo:rustc-env=GIT_VERSION={}", version);
|
||||||
|
}
|
||||||
69
src/main.rs
69
src/main.rs
@@ -5,10 +5,10 @@ use std::fs;
|
|||||||
use std::io::{self, Write};
|
use std::io::{self, Write};
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use tracing::{Level, error, info, instrument, warn};
|
use tracing::{Level, error, info, instrument, warn};
|
||||||
use tracing_subscriber;
|
|
||||||
|
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
#[command(name = "gitea-mirror")]
|
#[command(name = "gitea-mirror")]
|
||||||
|
#[command(version = env!("GIT_VERSION"))]
|
||||||
#[command(about = "Syncs Git repositories to Gitea based on a TOML config.")]
|
#[command(about = "Syncs Git repositories to Gitea based on a TOML config.")]
|
||||||
struct Args {
|
struct Args {
|
||||||
/// Path to the TOML configuration file.
|
/// Path to the TOML configuration file.
|
||||||
@@ -92,6 +92,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
// 2. Build 'Desired' State (Map<RepoName, CloneUrl>)
|
// 2. Build 'Desired' State (Map<RepoName, CloneUrl>)
|
||||||
info!("Resolving desired state from configuration...");
|
info!("Resolving desired state from configuration...");
|
||||||
let mut desired_repos: HashMap<String, String> = HashMap::new();
|
let mut desired_repos: HashMap<String, String> = HashMap::new();
|
||||||
|
let mut seen_names: HashSet<String> = HashSet::new();
|
||||||
|
let mut has_error = false;
|
||||||
|
|
||||||
// 2a. Static Repos
|
// 2a. Static Repos
|
||||||
if let Some(repos) = &config.repos {
|
if let Some(repos) = &config.repos {
|
||||||
@@ -101,6 +103,18 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
.as_deref()
|
.as_deref()
|
||||||
.or_else(|| extract_repo_name(&r.url))
|
.or_else(|| extract_repo_name(&r.url))
|
||||||
.ok_or_else(|| format!("Invalid URL: {}", r.url))?;
|
.ok_or_else(|| format!("Invalid URL: {}", r.url))?;
|
||||||
|
|
||||||
|
let name_lower = name.to_lowercase();
|
||||||
|
if seen_names.contains(&name_lower) {
|
||||||
|
warn!(
|
||||||
|
"Duplicate repository name detected (case-insensitive): '{}'. URL: {}",
|
||||||
|
name, r.url
|
||||||
|
);
|
||||||
|
has_error = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
seen_names.insert(name_lower);
|
||||||
|
|
||||||
desired_repos.insert(name.to_string(), r.url.clone());
|
desired_repos.insert(name.to_string(), r.url.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -113,12 +127,26 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
fetch_external_org_repos(&http_client, &org.url, org.api_key.as_deref()).await?;
|
fetch_external_org_repos(&http_client, &org.url, org.api_key.as_deref()).await?;
|
||||||
for url in urls {
|
for url in urls {
|
||||||
if let Some(name) = extract_repo_name(&url) {
|
if let Some(name) = extract_repo_name(&url) {
|
||||||
|
let name_lower = name.to_lowercase();
|
||||||
|
if seen_names.contains(&name_lower) {
|
||||||
|
warn!(
|
||||||
|
"Duplicate repository name detected (case-insensitive) from organization import: '{}'. URL: {}",
|
||||||
|
name, url
|
||||||
|
);
|
||||||
|
has_error = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
seen_names.insert(name_lower);
|
||||||
desired_repos.insert(name.to_string(), url);
|
desired_repos.insert(name.to_string(), url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if has_error {
|
||||||
|
return Err("Duplicate repository names detected. Please fix the configuration.".into());
|
||||||
|
}
|
||||||
|
|
||||||
// 3. Build 'Current' State (Set<RepoName>)
|
// 3. Build 'Current' State (Set<RepoName>)
|
||||||
info!("Fetching existing repositories from Gitea ({})", owner_name);
|
info!("Fetching existing repositories from Gitea ({})", owner_name);
|
||||||
let existing_repos =
|
let existing_repos =
|
||||||
@@ -262,7 +290,7 @@ fn load_config(path: &Path) -> Result<Config, Box<dyn std::error::Error>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn extract_repo_name(url: &str) -> Option<&str> {
|
fn extract_repo_name(url: &str) -> Option<&str> {
|
||||||
url.split('/').last().map(|s| s.trim_end_matches(".git"))
|
url.split('/').next_back().map(|s| s.trim_end_matches(".git"))
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- API Calls ---
|
// --- API Calls ---
|
||||||
@@ -290,20 +318,36 @@ async fn fetch_all_target_repos(
|
|||||||
gitea_url: &str,
|
gitea_url: &str,
|
||||||
api_key: &str,
|
api_key: &str,
|
||||||
owner: &str,
|
owner: &str,
|
||||||
|
) -> Result<Vec<String>, Box<dyn std::error::Error>> {
|
||||||
|
let org_url = format!("{}/api/v1/orgs/{}/repos", gitea_url, owner);
|
||||||
|
match fetch_repos_from_endpoint(client, &org_url, api_key).await {
|
||||||
|
Ok(repos) => Ok(repos),
|
||||||
|
Err(e) => {
|
||||||
|
if e.downcast_ref::<reqwest::Error>()
|
||||||
|
.is_some_and(|r| r.status() == Some(reqwest::StatusCode::NOT_FOUND))
|
||||||
|
{
|
||||||
|
info!("Owner '{}' not found as org, trying as user...", owner);
|
||||||
|
let user_url = format!("{}/api/v1/users/{}/repos", gitea_url, owner);
|
||||||
|
return fetch_repos_from_endpoint(client, &user_url, api_key).await;
|
||||||
|
}
|
||||||
|
Err(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn fetch_repos_from_endpoint(
|
||||||
|
client: &reqwest::Client,
|
||||||
|
url: &str,
|
||||||
|
api_key: &str,
|
||||||
) -> Result<Vec<String>, Box<dyn std::error::Error>> {
|
) -> Result<Vec<String>, Box<dyn std::error::Error>> {
|
||||||
let mut names = Vec::new();
|
let mut names = Vec::new();
|
||||||
let mut page = 1;
|
let mut page = 1;
|
||||||
let base_url = format!("{}/api/v1/repos/search", gitea_url);
|
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let params = [
|
let params = [("limit", "50"), ("page", &page.to_string())];
|
||||||
("owner", owner),
|
|
||||||
("limit", "50"),
|
|
||||||
("page", &page.to_string()),
|
|
||||||
];
|
|
||||||
|
|
||||||
let res = client
|
let res = client
|
||||||
.get(&base_url)
|
.get(url)
|
||||||
.bearer_auth(api_key)
|
.bearer_auth(api_key)
|
||||||
.query(¶ms)
|
.query(¶ms)
|
||||||
.send()
|
.send()
|
||||||
@@ -311,10 +355,7 @@ async fn fetch_all_target_repos(
|
|||||||
.error_for_status()?;
|
.error_for_status()?;
|
||||||
|
|
||||||
let json: serde_json::Value = res.json().await?;
|
let json: serde_json::Value = res.json().await?;
|
||||||
let data = json
|
let data = json.as_array().ok_or("Invalid API response")?;
|
||||||
.get("data")
|
|
||||||
.and_then(|d| d.as_array())
|
|
||||||
.ok_or("Invalid API response")?;
|
|
||||||
|
|
||||||
if data.is_empty() {
|
if data.is_empty() {
|
||||||
break;
|
break;
|
||||||
@@ -347,7 +388,7 @@ async fn fetch_external_org_repos(
|
|||||||
// Heuristic to find API endpoint from web URL
|
// Heuristic to find API endpoint from web URL
|
||||||
format!(
|
format!(
|
||||||
"{}s/{}/repos",
|
"{}s/{}/repos",
|
||||||
org_url.replace(user_or_org, &format!("api/v1/user")),
|
org_url.replace(user_or_org, "api/v1/user"),
|
||||||
user_or_org
|
user_or_org
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|||||||
22
vibe_coding_log/README.md
Normal file
22
vibe_coding_log/README.md
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
# Vibe Coding Log
|
||||||
|
|
||||||
|
This directory contains logs of coding sessions with LLM assistants. The purpose is to track the evolution of LLM coding capabilities over time and provide an audit trail of changes made to the codebase.
|
||||||
|
|
||||||
|
## Log Structure
|
||||||
|
|
||||||
|
Each log entry is saved as a Markdown file named with the pattern:
|
||||||
|
`session_<YYYY_MM_DD>_<topic>.md`
|
||||||
|
|
||||||
|
## Instructions for Creating New Entries
|
||||||
|
|
||||||
|
1. **Create a new file**: Use the naming convention above.
|
||||||
|
2. **Record the Session**: Copy the conversation transcript or write a detailed summary of the interaction.
|
||||||
|
3. **Metadata**: Include the following at the top of the file:
|
||||||
|
* **Date**: The date of the session.
|
||||||
|
* **Model**: The name/version of the LLM used (e.g., Gemini 2.5 Flash, GPT-4, etc.).
|
||||||
|
* **Goal**: The primary objective of the session.
|
||||||
|
* **Outcome**: A brief summary of the result.
|
||||||
|
|
||||||
|
## Current Assistant
|
||||||
|
|
||||||
|
The initial logs in this folder were generated by **Gemini** (specifically acting as the Gemini CLI agent).
|
||||||
69
vibe_coding_log/session_2026_01_07_gitea_fix.md
Normal file
69
vibe_coding_log/session_2026_01_07_gitea_fix.md
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
# Session Log: Gitea Mirror Fixes
|
||||||
|
|
||||||
|
**Date**: Wednesday, January 7, 2026
|
||||||
|
**Model**: Gemini (CLI Agent)
|
||||||
|
**Goal**: Fix compiler errors after dependency bump and correct Gitea API usage.
|
||||||
|
**Outcome**: Successfully resolved `reqwest` 0.13 breaking changes and fixed logic for fetching repositories.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Transcript Summary
|
||||||
|
|
||||||
|
### 1. Dependency Update Fix
|
||||||
|
|
||||||
|
**User**: Reported a compiler error after bumping dependencies.
|
||||||
|
**Context**: The project uses `reqwest`. A recent update to `reqwest` 0.13 made the `.query()` method feature-gated.
|
||||||
|
**Error**:
|
||||||
|
```
|
||||||
|
error[E0599]: no method named `query` found for struct `RequestBuilder` in the current scope
|
||||||
|
```
|
||||||
|
|
||||||
|
**Agent Action**:
|
||||||
|
1. Analyzed `Cargo.toml` and build output.
|
||||||
|
2. Identified that `reqwest` 0.13 requires the `query` feature to use the query string builder.
|
||||||
|
3. Updated `Cargo.toml`:
|
||||||
|
```toml
|
||||||
|
reqwest = { version = "0.13", features = ["json", "query"] }
|
||||||
|
```
|
||||||
|
4. Verified with `cargo build`.
|
||||||
|
5. Committed changes: "Fix compilation error by enabling reqwest/query feature".
|
||||||
|
|
||||||
|
### 2. Logic Fix and Refactoring
|
||||||
|
|
||||||
|
**User**: Provided a `git diff` from another machine fixing an issue where Gitea's search API ignored the "owner" field, causing incorrect repo mirroring. Also requested incorporation of the fix.
|
||||||
|
|
||||||
|
**Agent Action**:
|
||||||
|
1. Applied the logic change to `src/main.rs`:
|
||||||
|
* Switched from `/api/v1/repos/search` to `/api/v1/orgs/{owner}/repos`.
|
||||||
|
* Updated response parsing to handle the JSON array directly.
|
||||||
|
2. Addressed `cargo clippy` warnings identified during the process:
|
||||||
|
* Removed unused `tracing_subscriber` import.
|
||||||
|
* Optimized iterator usage: `url.split('/').last()` -> `url.split('/').next_back()`.
|
||||||
|
* Removed redundant `format!` usage.
|
||||||
|
3. Verified with `cargo build` and `cargo clippy`.
|
||||||
|
4. Committed changes: "Fix target repo fetching by using orgs endpoint and address clippy warnings".
|
||||||
|
|
||||||
|
### 3. Verification and Robustness
|
||||||
|
|
||||||
|
**User**: Asked to verify if the logic fix (using `/orgs/{owner}/repos`) was correct via rigorous checking.
|
||||||
|
|
||||||
|
**Analysis**:
|
||||||
|
* Research confirmed that `/repos/search` does not support filtering by `owner` name (only `uid`), validating the need for a change.
|
||||||
|
* However, `/orgs/{owner}/repos` **only** works if the target is an organization. If the target is a User, it would fail.
|
||||||
|
* The correct endpoint for users is `/users/{owner}/repos`.
|
||||||
|
|
||||||
|
**Agent Action**:
|
||||||
|
1. Refactored `fetch_all_target_repos` to use a fallback strategy:
|
||||||
|
* First, try fetching from `/api/v1/orgs/{owner}/repos`.
|
||||||
|
* If the API returns `404 Not Found`, automatically retry with `/api/v1/users/{owner}/repos`.
|
||||||
|
2. Extracted the fetching logic into a helper function `fetch_repos_from_endpoint` to avoid duplication.
|
||||||
|
3. Addressed new `clippy` suggestions regarding `map_or` and `is_some_and`.
|
||||||
|
4. Committed changes: "Implement fallback to user repos endpoint if org not found".
|
||||||
|
|
||||||
|
## Final State
|
||||||
|
|
||||||
|
The codebase now:
|
||||||
|
1. Compiles with the latest dependencies (`reqwest` 0.13).
|
||||||
|
2. Correctly filters repositories by the target owner.
|
||||||
|
3. Robustly handles both Organization and User targets by attempting both endpoints.
|
||||||
|
4. Is free of linting warnings.
|
||||||
23
vibe_coding_log/session_2026_01_10_duplicate_detection.md
Normal file
23
vibe_coding_log/session_2026_01_10_duplicate_detection.md
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
# Session 2026-01-10: Duplicate Repository Detection
|
||||||
|
|
||||||
|
* **Date**: 2026-01-10
|
||||||
|
* **Model**: Gemini 2.5 Flash / Gemini 3 Pro Preview
|
||||||
|
* **Goal**: Implement case-insensitive duplication detection for repository names in the configuration.
|
||||||
|
* **Outcome**: Added logic to detect duplicate repository names (case-insensitive) from both static configuration and organization imports. The tool now logs warnings for all detected duplicates and then exits with a fatal error if any duplicates were found.
|
||||||
|
|
||||||
|
## Details
|
||||||
|
|
||||||
|
1. **Duplicate Detection**:
|
||||||
|
* Modified `src/main.rs` to maintain a `HashSet` of lowercased repository names.
|
||||||
|
* Checks both the `repos` list and `organizations` imports.
|
||||||
|
* If a duplicate is found, a `WARN` log is emitted with details (name and URL).
|
||||||
|
* A `has_error` flag is set to true.
|
||||||
|
|
||||||
|
2. **Error Handling**:
|
||||||
|
* After processing all sources, if `has_error` is true, the program returns a fatal error: "Duplicate repository names detected. Please fix the configuration."
|
||||||
|
* This ensures the user sees all conflicts before the program exits.
|
||||||
|
|
||||||
|
## Testing
|
||||||
|
|
||||||
|
* Created a `duplicate_repro.toml` with conflicting names (e.g., `ProjectA` vs `projecta`).
|
||||||
|
* Verified that `cargo run -- --config duplicate_repro.toml --dry-run` correctly outputted warnings for each duplicate and then exited with a non-zero status code and the expected error message.
|
||||||
38
vibe_coding_log/session_2026_01_10_version_flag.md
Normal file
38
vibe_coding_log/session_2026_01_10_version_flag.md
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
# Session Log: Add Version Flag
|
||||||
|
|
||||||
|
**Date**: Saturday, January 10, 2026
|
||||||
|
**Model**: Gemini (CLI Agent)
|
||||||
|
**Goal**: Add a `--version` flag that displays the git tag and short SHA.
|
||||||
|
**Outcome**: Implemented dynamic versioning using `build.rs` and `clap`.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Transcript Summary
|
||||||
|
|
||||||
|
### 1. Version Flag Implementation
|
||||||
|
|
||||||
|
**User**: Requested a `--version` flag that output the latest git tag. If the current commit is not exactly on a tag, it should append the short SHA (e.g., `v0.6-gd8a9fc`).
|
||||||
|
|
||||||
|
**Agent Action**:
|
||||||
|
1. Analyzed `Cargo.toml` and `src/main.rs`.
|
||||||
|
2. Created a `build.rs` script to handle the logic:
|
||||||
|
* Tries `git describe --tags --exact-match`.
|
||||||
|
* If that fails, tries `git describe --tags --abbrev=0` (latest tag) combined with `git rev-parse --short HEAD` (current SHA).
|
||||||
|
* Sets the `GIT_VERSION` environment variable.
|
||||||
|
3. Modified `src/main.rs`:
|
||||||
|
* Updated the `clap` `Args` struct to use `#[command(version = env!("GIT_VERSION"))]`.
|
||||||
|
4. Verified the output using `cargo run -- --version`.
|
||||||
|
|
||||||
|
### 2. Verification
|
||||||
|
|
||||||
|
**User**: Implicitly relied on agent verification.
|
||||||
|
|
||||||
|
**Agent Action**:
|
||||||
|
1. Ran `cargo run -- --version` -> Output: `gitea-mirror v0.6-gf13906d` (correct format).
|
||||||
|
2. Created a temporary tag `v0.7.0-test`, verified output was `gitea-mirror v0.7.0-test`, then deleted the tag.
|
||||||
|
3. Ran `cargo clippy` (clean).
|
||||||
|
4. Committed changes including the new `build.rs` and updated `src/main.rs`.
|
||||||
|
|
||||||
|
## Final State
|
||||||
|
|
||||||
|
The application now supports `gitea-mirror --version` which dynamically reports the git version at build time.
|
||||||
Reference in New Issue
Block a user