Skip to content

Automatically create repos and setup push-mirrors from a gitlab instance to github organizations (mirror)

License

Notifications You must be signed in to change notification settings

inp-net/automirror

Repository files navigation

Automatically create a mirror repository on a github organization and add a push mirror to the corresponding gitlab repository

Usage

Manual

git clone https://git.inpt.fr/inp-net/automirror cd automirror cp .env.example .env # Edit .env file to fill with your own values go run main.go

Docker

There's a docker image accessible at dockerhub

docker run -v $(pwd)/.env:/app/.env uwun/automirror

Kubernetes

You'll find an example Kubernetes deployment in the k8s-example directory that runs the script every monday at 01:00.

Configuration

Credentials

Credentials are set with environment variables. Automirror will also load a .env if the file exists. You can find an example in the .env.example file.

VariableDescriptionExample
GITHUB_TOKENThe personal access token to use to authenticate to the github API. Must have the administration:write scope, and also permissions to push to the repositories that will be created
GITHUB_USERNAMEThe username of the github user that will be used to create the mirrored repositories
GITLAB_TOKENThe personal access token to use to authenticate to the gitlab API. Must have the necessary permissions to query and update push mirrors on a project

GITHUB_TOKEN and GITHUB_USERNAME will be used to construct the mirror URL passed to gitlab, as https://{USERNAME}:{TOKEN}@github.com/{ORGANIZATION}/{REPOSITORY}.

Mirrors

Configuration of mirrors is defined in a YAML file. A JSON Schema is available at config.schema.json, and example config files are in examples/.

# yaml-language-server: $schema=https://git.inpt.fr/inp-net/automirror/-/raw/main/config.schema.jsonto: github.com # Target git host. Only github.com is supported for now.from: my-gitlab.example.com # Source git host. Only gitlab hosts are supported for now.# Set defaults to avoid repeating yourselfdefaults: topics: [mirrored to github] # selects repositories that have one of these topics. Providing an empty array selects no repositories.subgroups: flatten: "-"# with what character to join gitlab sub-groups to compute the github repo name. For example, if the gitlab project is `group/subgroup/project`, the github repo name will be `subgroup-project`orgs: # Repositories to mirror to github.com/my-github-orgmy-github-org: - from: foo # Mirror all public repositories from gitlab org "foo" that have the topic "mirrored to github" (see `defaults`) - from: bar prefix: baz # Prefix the github repository names with "baz"# there's also `suffix` - from: qux except: [qux/example] # Don't mirror the repository "qux/example" - from: spam only: [spam/eggs, spam/bacon] # Only mirror repositories "spam/eggs" and "spam/bacon"

About

Automatically create repos and setup push-mirrors from a gitlab instance to github organizations (mirror)

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •