From d85279e574f7a0bf425842b48998cffd38932d2a Mon Sep 17 00:00:00 2001 From: mxve <68632137+mxve@users.noreply.github.com> Date: Mon, 16 Oct 2023 18:53:35 +0200 Subject: [PATCH] cleanup + doc --- README.md | 37 +++++++++++++++++++++++++++++++++++++ config.example.toml | 3 ++- src/config.rs | 1 + src/main.rs | 9 ++++++--- 4 files changed, 46 insertions(+), 4 deletions(-) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..66a239a --- /dev/null +++ b/README.md @@ -0,0 +1,37 @@ +# TeaHub +#### Mirror GitHub repositories to Gitea +###### Inspired by [Gickup](https://github.com/cooperspencer/gickup) + +TeaHub makes use of Gitea's mirroring feature and uses the GitHub and Gitea API to automate the process of mirroring GitHub repositories to Gitea. + +## Featues +- Mirror GitHub repositories to Gitea (duh) +- Prefix repo name with owner name if not owned by user + - Mirroring your own repo would result in `/` + - Mirroring this repo would result in `/mxve_teahub` +- Option to include starred repos +- Option to include private repos +- Option to keep all repos private +- Configurable (Gitea) mirror interval + +## Usage +- Setup config file (see [config.example.json](config.example.json)) +- Run teahub +- ??? +- Profit + +## Config +```toml +[github] +token = "" # GitHub personal access token +user = "" # GitHub username +include_starred = true # Include starred repositories +include_private = true # Include private repositories + +[gitea] +token = "" # Gitea access token +user = "" # Gitea username +url = "" # Gitea URL (without trailing slash) +keep_private = true # Set all repositories to private, otherwise use the same visibility as on GitHub +mirror_interval = "2h" # Gitea mirror interval +``` \ No newline at end of file diff --git a/config.example.toml b/config.example.toml index b550325..e2f1510 100644 --- a/config.example.toml +++ b/config.example.toml @@ -8,4 +8,5 @@ include_private = true token = "" user = "" url = "" -keep_private = true \ No newline at end of file +keep_private = true +mirror_interval = "2h" \ No newline at end of file diff --git a/src/config.rs b/src/config.rs index 3f0ec2f..7cd21e9 100644 --- a/src/config.rs +++ b/src/config.rs @@ -7,6 +7,7 @@ pub struct CGitea { pub user: String, pub url: String, pub keep_private: bool, + pub mirror_interval: String, } #[derive(Deserialize, Debug)] diff --git a/src/main.rs b/src/main.rs index 37fec4e..a04f146 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,5 @@ use serde_derive::{Deserialize, Serialize}; -use std::path::PathBuf; +use std::{path::PathBuf, time::Duration}; mod config; #[allow(dead_code)] @@ -124,7 +124,7 @@ fn mirror_repo(repo: &Repo, config: &config::Config) { issues: true, lfs: true, mirror: true, - mirror_interval: "2h".to_string(), + mirror_interval: config.gitea.mirror_interval.clone(), private: true, pull_requests: true, releases: true, @@ -157,6 +157,7 @@ fn mirror_repo(repo: &Repo, config: &config::Config) { .header("Content-Length", &payload.len()) .header("Content-Type", "application/json") .header("Authorization", &format!("token {}", &config.gitea.token)) + .timeout(Some(Duration::from_secs(90))) // When mirroring many and or large repos it can take a while .send(&mut buffer) { Ok(req) => { @@ -178,7 +179,9 @@ fn main() { let gitea_repos_names: Vec = gitea_repos.iter().map(|r| r.name.clone()).collect(); for repo in github_repos { let prefixed_name = format!("{}_{}", repo.owner.login, repo.name); - if gitea_repos_names.contains(&repo.name) || gitea_repos_names.contains(&prefixed_name) { + if (gitea_repos_names.contains(&repo.name) && repo.owner.login == config.github.user) + || gitea_repos_names.contains(&prefixed_name) + { println!("{} already exists", repo.name); continue; }