mirror of
https://github.com/cupcakearmy/gitea-sync.git
synced 2024-12-23 08:36:23 +00:00
Compare commits
No commits in common. "9b535f621b66a3d7260ea6c50da88913b7a759fc" and "cf19e698b36c72f52b1967f3edfb6b235ff2c187" have entirely different histories.
9b535f621b
...
cf19e698b3
13
README.md
13
README.md
@ -1,10 +1,10 @@
|
|||||||
# Backup GitHub repos to Gitea
|
# Backup Github repos to Gitea
|
||||||
|
|
||||||
Simple docker image that syncs your GitHub repos to a given Gitea server. It takes all the repos (public and private) and sets up a mirror. Private repos will stay a private mirror. Repos that are already set up will be skipped.
|
Simple docker image that syncs your Github repos to a given Gitea server. It takes all the repos (public and private) and sets up a mirror. Private repos will stay a private mirror. Repos that are already setup will be skipped.
|
||||||
|
|
||||||
## Quick Start
|
## Quick Start
|
||||||
|
|
||||||
Create a `docker-compose.yaml` and `.env` (see `.env.sample`). Create and insert tokens, and you are ready to go.
|
Create a `docker-compose.yaml` and `.env` (see `.env.sample`). Create and insert tokens and you are ready to go.
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
version: '3.8'
|
version: '3.8'
|
||||||
@ -19,14 +19,13 @@ services:
|
|||||||
## Configuration
|
## Configuration
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
# Github PAT (deprecated)
|
# Github PAT
|
||||||
# or
|
# Also works with the new fine grained, read-only tokens
|
||||||
# Fine Grained token (Metadata and Content read-only scopes required)
|
|
||||||
GITHUB_TOKEN=
|
GITHUB_TOKEN=
|
||||||
|
|
||||||
# Host of the Gitea server
|
# Host of the Gitea server
|
||||||
GITEA_HOST=
|
GITEA_HOST=
|
||||||
# Gitea token (scopes: repo)
|
# Gitea token
|
||||||
GITEA_TOKEN=
|
GITEA_TOKEN=
|
||||||
|
|
||||||
# OPTIONAL
|
# OPTIONAL
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"version": "1.1.0",
|
"version": "1.0.0",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node .",
|
"start": "node .",
|
||||||
|
@ -3,7 +3,6 @@ import axios, { AxiosError } from 'axios'
|
|||||||
import { Config } from '../config.js'
|
import { Config } from '../config.js'
|
||||||
import { logger } from '../logger.js'
|
import { logger } from '../logger.js'
|
||||||
import { ListRepositoriesResponse } from './gitea.types.js'
|
import { ListRepositoriesResponse } from './gitea.types.js'
|
||||||
import { Repository } from './github.types.js'
|
|
||||||
|
|
||||||
const Base = axios.create({
|
const Base = axios.create({
|
||||||
baseURL: new URL('/api/v1', Config.gitea.host).href,
|
baseURL: new URL('/api/v1', Config.gitea.host).href,
|
||||||
@ -78,12 +77,3 @@ export async function listAllRepositories() {
|
|||||||
logger.debug('Listed all repositories in Gitea', { data: repos })
|
logger.debug('Listed all repositories in Gitea', { data: repos })
|
||||||
return repos
|
return repos
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function updateRepository(owner: string, repo: string, body: Partial<Repository>) {
|
|
||||||
logger.debug('Updating repository', { owner, repo, body })
|
|
||||||
await Base({
|
|
||||||
url: `/repos/${owner}/${repo}`,
|
|
||||||
method: 'PATCH',
|
|
||||||
data: body,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
15
src/core.ts
15
src/core.ts
@ -1,4 +1,4 @@
|
|||||||
import { listAllRepositories as giteaRepos, mirror, MirrorOptions, updateRepository } from './api/gitea.js'
|
import { listAllRepositories as giteaRepos, mirror, MirrorOptions } from './api/gitea.js'
|
||||||
import { listAllRepositories as githubRepos } from './api/github.js'
|
import { listAllRepositories as githubRepos } from './api/github.js'
|
||||||
import { Config } from './config.js'
|
import { Config } from './config.js'
|
||||||
import { logger } from './logger.js'
|
import { logger } from './logger.js'
|
||||||
@ -20,12 +20,7 @@ export async function sync() {
|
|||||||
const sameName = syncedRepos.find((r) => r.name === repo.name || r.original_url === repo.clone_url)
|
const sameName = syncedRepos.find((r) => r.name === repo.name || r.original_url === repo.clone_url)
|
||||||
if (sameName) {
|
if (sameName) {
|
||||||
if (sameName.original_url === repo.clone_url) {
|
if (sameName.original_url === repo.clone_url) {
|
||||||
if (sameName.private === repo.private) logger.info('Already synced, skipping', { name: repo.name })
|
logger.info('Already synced, skipping', { name: repo.name })
|
||||||
else {
|
|
||||||
logger.info('Visibility changed, updating', { name: repo.name })
|
|
||||||
const [owner, repository] = sameName.full_name.split('/')
|
|
||||||
await updateRepository(owner, repository, { private: repo.private })
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
logger.error('Repo with same name but different url', {
|
logger.error('Repo with same name but different url', {
|
||||||
name: repo.name,
|
name: repo.name,
|
||||||
@ -47,9 +42,9 @@ export async function sync() {
|
|||||||
logger.info('Mirrored repository', { name: repo.name })
|
logger.info('Mirrored repository', { name: repo.name })
|
||||||
}
|
}
|
||||||
logger.info('Finished sync')
|
logger.info('Finished sync')
|
||||||
} catch (error) {
|
} catch (e) {
|
||||||
logger.debug(error)
|
logger.error(e)
|
||||||
logger.error('Failed to sync', { error: error instanceof Error ? error.message : 'Unknown error' })
|
logger.error('Failed to sync')
|
||||||
} finally {
|
} finally {
|
||||||
running = false
|
running = false
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user