diff --git a/platform/gitea/files/config/go.mod b/platform/gitea/files/config/go.mod index dc3c1f37..4e91d99a 100644 --- a/platform/gitea/files/config/go.mod +++ b/platform/gitea/files/config/go.mod @@ -5,4 +5,5 @@ go 1.18 require ( code.gitea.io/sdk/gitea v0.15.1 // indirect github.com/hashicorp/go-version v1.2.1 // indirect + gopkg.in/yaml.v2 v2.4.0 // indirect ) diff --git a/platform/gitea/files/config/go.sum b/platform/gitea/files/config/go.sum index c14d70f1..2c93101f 100644 --- a/platform/gitea/files/config/go.sum +++ b/platform/gitea/files/config/go.sum @@ -26,3 +26,5 @@ golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8T golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= diff --git a/platform/gitea/files/config/main.go b/platform/gitea/files/config/main.go index 1768870f..282f5376 100644 --- a/platform/gitea/files/config/main.go +++ b/platform/gitea/files/config/main.go @@ -1,9 +1,12 @@ package main import ( + "fmt" "log" + "os" "code.gitea.io/sdk/gitea" + "gopkg.in/yaml.v2" ) type User struct { @@ -13,7 +16,7 @@ type User struct { type Organization struct { Name string - Members []string + Description string } type Repository struct { @@ -32,6 +35,22 @@ type Config struct { } func main() { + data, err := os.ReadFile("./config.yaml") + + if err != nil { + log.Fatalf("unable to read config file: %v", err) + } + + config := Config{} + + err = yaml.Unmarshal([]byte(data), &config) + + if err != nil { + log.Fatalf("error: %v", err) + } + + fmt.Println(config) + // TODO url := "https://git.khuedoan.com" // url := "http://gitea-http:3000" @@ -44,13 +63,15 @@ func main() { log.Fatal(err) } - _, _, err = client.CreateOrg(gitea.CreateOrgOption{ - Name: "testing", - Description: "this is org description", - }) + for _, org := range config.Organizations { + _, _, err = client.CreateOrg(gitea.CreateOrgOption{ + Name: org.Name, + Description: org.Description, + }) - if err != nil { - log.Printf("Create organization %s: %s", "testing", err) + if err != nil { + log.Printf("Create organization %s: %s", "testing", err) + } } _, _, err = client.MigrateRepo(gitea.MigrateRepoOption{