mirror of
https://github.com/khuedoan/homelab.git
synced 2025-01-05 13:08:52 +07:00
feat(gitea): read config from file
This commit is contained in:
parent
ad180d24de
commit
f52cca560a
@ -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
|
||||
)
|
||||
|
@ -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=
|
||||
|
@ -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{
|
||||
|
Loading…
Reference in New Issue
Block a user