Skip to content

Commit

Permalink
cleanup + doc
Browse files Browse the repository at this point in the history
  • Loading branch information
mxve committed Oct 16, 2023
1 parent 357c868 commit d85279e
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 4 deletions.
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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 `<yourgiteauser>/<reponame>`
- Mirroring this repo would result in `<yourgiteauser>/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
```
3 changes: 2 additions & 1 deletion config.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ include_private = true
token = ""
user = ""
url = ""
keep_private = true
keep_private = true
mirror_interval = "2h"
1 change: 1 addition & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub struct CGitea {
pub user: String,
pub url: String,
pub keep_private: bool,
pub mirror_interval: String,
}

#[derive(Deserialize, Debug)]
Expand Down
9 changes: 6 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use serde_derive::{Deserialize, Serialize};
use std::path::PathBuf;
use std::{path::PathBuf, time::Duration};
mod config;

#[allow(dead_code)]
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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) => {
Expand All @@ -178,7 +179,9 @@ fn main() {
let gitea_repos_names: Vec<String> = 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;
}
Expand Down

0 comments on commit d85279e

Please sign in to comment.