Go to file
Dennis Wielepsky 5789b1aadf source needs bash 2024-09-24 14:51:25 +02:00
.devcontainer Add devcontainer file 2023-02-13 21:35:10 +00:00
.github/workflows update docker login action 2023-02-15 13:20:30 +01:00
src Log the start of each run with its parameters 2024-07-20 01:11:41 +01:00
.dockerignore initial commit 2019-03-09 13:47:07 +01:00
.gitignore Fix public and private repos 2023-02-03 01:29:38 -05:00
Dockerfile Add slash for copy 2023-02-03 18:37:22 -05:00
LICENSE Update LICENSE 2024-08-18 14:38:06 +02:00
README.md Merge pull request #18 from jdevera/skip_forks 2024-09-24 14:39:49 +02:00
docker-entrypoint.sh Add variable delay time 2023-02-03 18:19:20 -05:00
package-lock.json Ran `npm update` to regenerate package-lock.json 2023-02-13 21:48:51 +00:00
package.json fix: upgrade octokit to fix 'TypeError: Octokit is not a constructor' 2021-01-11 23:11:31 +01:00
run-local.sh source needs bash 2024-09-24 14:51:25 +02:00

README.md

Automatically Mirror Github Repo To Your Gitea Server

Badges

image pulls

Description

This script automatically mirrors the repositories from a github-user or github-organization to your gitea server. Once started, it will create a mirrored repository under a given token for a gitea user, completely automatically.

Example: A github user github-user has public repositories dotfiles and zsh-config. Starting the script with a gitea token for the account gitea-user will create the following mirrored repositories:

  • github.com/github-user/dotfiles → your-gitea.url/gitea-user/dotfiles
  • github.com/github-user/zsh-config → your-gitea.url/gitea-user/zsh-config

The mirror settings are default by your gitea instance.

It is also possible to mirror private repos, which can be configred here in #parameters. When mirroring private repos, they will be created as private repos on your gitea server.

Prerequisites

  • A github user or organization with repositories
  • Configured Gitea instance up and running
  • User for Gitea with generated token (Settings -> Applications -> Generate New Token)
  • Docker or Docker Compose

Docker Run

docker run \
 -d \
 --restart always \
 -e GITHUB_USERNAME=github-user \
 -e GITEA_URL=https://your-gitea.url \
 -e GITEA_TOKEN=please-exchange-with-token \
 jaedle/mirror-to-gitea:latest

This will a spin up a docker container which will run forever, mirroring all your repositories once every hour to your gitea server.

Docker Compose

version: "3.3"
services:
    mirror-to-gitea:
        image: jaedle/mirror-to-gitea:latest
        restart: unless-stopped
        environment:
          - GITHUB_USERNAME=github-user
          - GITEA_URL=https://your-gitea.url
          - GITEA_TOKEN=please-exchange-with-token
          # - GITHUB_TOKEN=please-exchange-with-token # Optional, set to mirror private repos
          # - MIRROR_PRIVATE_REPOSITORIES=true # Optional, set to mirror private repos
          # - DELAY=3600 # Optional, set to change the delay between checks (in seconds)
          # - SKIP_FORKS=true # Optional, set to skip forks
          # - DRY_RUN=true # Optional, set to only log what would be done
        container_name: mirror-to-gitea

Building from Source

Prerequisites

  • NodeJS
  • NPM

Build

npm install

If errors occur, try deleting the package-lock.json file and run npm install again.

Build Docker Image

docker build -t mirror-to-gitea .

Run With NodeJS

export GITHUB_USERNAME=github-user
export GITEA_URL=https://your-gitea.url
export GITEA_TOKEN=please-exchange-with-token
node src/index.js

Also export GITHUB_TOKEN and MIRROR_PRIVATE_REPOSITORIES if you want to mirror private repos, or DELAY if you want to change the delay between checks.

Run With Docker

In the above Docker run command, replace jaedle/mirror-to-gitea:latest with mirror-to-gitea. In your Docker Compose file, replace jaedle/mirror-to-gitea:latest with build: .. Then run docker compose build and docker compose up -d.

Parameters

Required

  • GITHUB_USERNAME: The name of your user or organization which public repos should be mirrored
  • GITEA_URL: The url of your gitea server
  • GITEA_TOKEN: The token for your gitea user (Settings -> Applications -> Generate New Token)

Optional

  • GITHUB_TOKEN: GitHub personal access token. Attention: if this is set, the token will be transmitted to your specified Gitea instance!
  • MIRROR_PRIVATE_REPOSITORIES: If set to true or 1, your private GitHub repositories will also be mirrored to gitea. The GITHUB_TOKEN parameter must be set for this to work.
  • SKIP_FORKS: If set to true or 1, forks will NOT be mirrored.
  • DELAY: How often to check for new repositories in seconds. Default is 3600 (1 hour).
  • DRY_RUN: If set to true or 1, the script will only log what would be done, but not actually create any mirror.