From 3f45a5f52757998309cf234fa7ffee58ff39cf42 Mon Sep 17 00:00:00 2001 From: Khue Doan Date: Tue, 22 Mar 2022 13:47:57 +0700 Subject: [PATCH] feat(gitea): create or migrate repo depending on config --- platform/gitea/files/config/config.yaml | 15 ++++++++-- platform/gitea/files/config/main.go | 37 ++++++++++++++++--------- 2 files changed, 36 insertions(+), 16 deletions(-) diff --git a/platform/gitea/files/config/config.yaml b/platform/gitea/files/config/config.yaml index 99fdc7e1..6fa7160c 100644 --- a/platform/gitea/files/config/config.yaml +++ b/platform/gitea/files/config/config.yaml @@ -9,16 +9,25 @@ organizations: members: - renovate repositories: - - path: ops/homelab + - name: homelab + owner: ops private: false migrate: source: https://github.com/khuedoan/homelab mirror: false webhooks: - http://gitea-webhook.tekton-pipelines:3000 - - path: khuedoan/blog + - name: blog + owner: khuedoan + migrate: + source: https://github.com/khuedoan/blog + mirror: true webhooks: - http://gitea-webhook.tekton-pipelines:3000 - - path: khuedoan/backstage + - name: backstage + owner: khuedoan + migrate: + source: https://github.com/khuedoan/backstage + mirror: true webhooks: - http://gitea-webhook.tekton-pipelines:3000 diff --git a/platform/gitea/files/config/main.go b/platform/gitea/files/config/main.go index 282f5376..e27b8469 100644 --- a/platform/gitea/files/config/main.go +++ b/platform/gitea/files/config/main.go @@ -15,12 +15,14 @@ type User struct { } type Organization struct { - Name string + Name string Description string } type Repository struct { - Path string + Name string + Owner string + Private bool Migrate struct { Source string Mirror bool @@ -74,17 +76,26 @@ func main() { } } - _, _, err = client.MigrateRepo(gitea.MigrateRepoOption{ - RepoName: "homelab", - RepoOwner: "ops", - CloneAddr: "https://github.com/khuedoan/homelab", - Service: gitea.GitServicePlain, - Mirror: true, - Private: false, - MirrorInterval: "10m", - }) + for _, repo := range config.Repositories { + if repo.Migrate.Source != "" { + _, _, err = client.MigrateRepo(gitea.MigrateRepoOption{ + RepoName: repo.Name, + RepoOwner: repo.Owner, + CloneAddr: repo.Migrate.Source, + Service: gitea.GitServicePlain, + Mirror: repo.Migrate.Mirror, + Private: repo.Private, + MirrorInterval: "10m", + }) - if err != nil { - log.Printf("Migrate %s/%s: %s", "ops", "homelab", err) + if err != nil { + log.Printf("Migrate %s/%s: %s", repo.Owner, repo.Name, err) + } + } else { + _, _, err = client.AdminCreateRepo(repo.Owner, gitea.CreateRepoOption{ + Name: repo.Name, + Private: repo.Private, + }) + } } }