This commit is contained in:
2024-07-20 18:28:25 +02:00
parent 5482ca6400
commit 527ccfdf45
4 changed files with 23 additions and 5 deletions

20
main.go
View File

@@ -8,9 +8,11 @@ import (
"os"
"code.gitea.io/sdk/gitea"
"github.com/joho/godotenv"
)
var Error *log.Logger
func init() {
log.SetFlags(log.Lmicroseconds | log.Lshortfile)
logFile, err := os.Create("main.log")
@@ -27,6 +29,15 @@ func init() {
}
func main() {
godotenv.Load()
username := os.Getenv("GITEA_USER")
password := os.Getenv("GITEA_PASSWORD")
if username == "" || password == "" {
Error.Fatalf("GITEA_USER and GITEA_PASSWORD environment variables are required")
os.Exit(1)
}
var name string
var private bool
flag.StringVar(&name, "name", "", "Name of the repository")
@@ -49,15 +60,16 @@ func main() {
Error.Fatalf("Error creating client: %v", err)
os.Exit(1)
}
client.SetBasicAuth("dave", "D7u@NHh^9d33ue!xVAEu")
repo, _, err := client.CreateRepo(gitea.CreateRepoOption{
Name: name,
Private: private,
Name: name,
Private: private,
DefaultBranch: "master",
})
if err != nil {
Error.Fatalf("Error creating repository: %v", err)
os.Exit(1)
}
log.Printf("Repository created: %v", repo)
}
log.Printf("Repository created at:\n%s", repo.CloneURL)
}