mirror of
https://github.com/cupcakearmy/gitea-sync.git
synced 2024-12-22 16:16:27 +00:00
Compare commits
1 Commits
2e34bf8ca0
...
dfb6b0fb6d
Author | SHA1 | Date | |
---|---|---|---|
dfb6b0fb6d |
@ -33,12 +33,6 @@ GITEA_TOKEN=
|
|||||||
|
|
||||||
# Cron schedule
|
# Cron schedule
|
||||||
CRON="0 */2 * * *"
|
CRON="0 */2 * * *"
|
||||||
|
|
||||||
# Debug level
|
|
||||||
DEBUG_LEVEL=debug
|
|
||||||
|
|
||||||
# Only run one, skip cron and exit
|
|
||||||
RUN_ONCE=1
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Known limitations
|
## Known limitations
|
||||||
|
@ -35,6 +35,5 @@ export const Config = {
|
|||||||
token: simple('GITEA_TOKEN'),
|
token: simple('GITEA_TOKEN'),
|
||||||
},
|
},
|
||||||
cron: getEnv('CRON', '0 */2 * * *'),
|
cron: getEnv('CRON', '0 */2 * * *'),
|
||||||
runOnce: getEnv('RUN_ONCE', false, Boolean),
|
|
||||||
version: getEnv('npm_package_version', 'unknown'),
|
version: getEnv('npm_package_version', 'unknown'),
|
||||||
}
|
}
|
||||||
|
@ -18,14 +18,10 @@ export async function sync() {
|
|||||||
const toSync = await githubRepos()
|
const toSync = await githubRepos()
|
||||||
l.debug('loaded repos', { remote: toSync.length, local: syncedRepos.length })
|
l.debug('loaded repos', { remote: toSync.length, local: syncedRepos.length })
|
||||||
|
|
||||||
// List of all the repos in gitea, that are not on github
|
|
||||||
const notInSource = new Set(syncedRepos.map((r) => r.name))
|
|
||||||
|
|
||||||
for (const repo of toSync) {
|
for (const repo of toSync) {
|
||||||
const lr = l.child({ repo: repo.name })
|
const lr = l.child({ repo: repo.name })
|
||||||
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) {
|
||||||
notInSource.delete(sameName.name)
|
|
||||||
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 })
|
if (sameName.private === repo.private) logger.info('Already synced, skipping', { name: repo.name })
|
||||||
else {
|
else {
|
||||||
@ -56,9 +52,6 @@ export async function sync() {
|
|||||||
await mirror(options)
|
await mirror(options)
|
||||||
lr.info('mirrored repository')
|
lr.info('mirrored repository')
|
||||||
}
|
}
|
||||||
if (notInSource.size) {
|
|
||||||
l.info(`Found ${notInSource.size} surplus repositories in gitea`, { repos: [...notInSource] })
|
|
||||||
}
|
|
||||||
l.info('Finished sync')
|
l.info('Finished sync')
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
l.debug(error)
|
l.debug(error)
|
||||||
|
10
src/index.ts
10
src/index.ts
@ -6,13 +6,5 @@ import { logger } from './logger.ts'
|
|||||||
|
|
||||||
logger.info(`Mirror manager - ${Config.version}`, { version: Config.version })
|
logger.info(`Mirror manager - ${Config.version}`, { version: Config.version })
|
||||||
|
|
||||||
Deno.addSignalListener('SIGINT', () => {
|
|
||||||
console.log('exiting...')
|
|
||||||
Deno.exit()
|
|
||||||
})
|
|
||||||
|
|
||||||
// Run on startup once, then delegate to cron
|
|
||||||
await sync()
|
await sync()
|
||||||
if (!Config.runOnce) {
|
cron.schedule(Config.cron, sync)
|
||||||
cron.schedule(Config.cron, sync)
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user