From 5e2a1403a2f8ca8fda8bb833418db90ce4f4c6e8 Mon Sep 17 00:00:00 2001 From: kekskurse Date: Tue, 6 Dec 2022 12:22:24 +0100 Subject: [PATCH] Stuff --- .gitignore | 2 +- cmd/gitea-page/main.go | 75 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 cmd/gitea-page/main.go diff --git a/.gitignore b/.gitignore index 4e92f7e..b4eb6ee 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ dist/ -gitea-page +./gitea-page idea/ \ No newline at end of file diff --git a/cmd/gitea-page/main.go b/cmd/gitea-page/main.go new file mode 100644 index 0000000..4be1911 --- /dev/null +++ b/cmd/gitea-page/main.go @@ -0,0 +1,75 @@ +package main + +import ( + "flag" + "gitea-page/internal/config" + git "gitea-page/internal/git" + "gitea-page/internal/gitea" + "gitea-page/internal/promote" + "github.com/rs/zerolog" + "github.com/rs/zerolog/log" + "gopkg.in/yaml.v2" + "net/http" + "os" +) + +func main () { + log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr}) + log.Info().Msg("Start") + config := readConfig() + setupSystem(config) + + g := git.GitHandler{} + g.Config = config + + p := promote.Promote{} + p.Config = config + + gitea := gitea.GiteaWebhook{} + gitea.Config = config + gitea.Git = g + gitea.Promoter = p + + runHTTPServer(gitea) +} + +func setupSystem(config config.GiteaPagesConfig) { + _, err := os.Stat(config.RootPath) + if os.IsNotExist(err) { + log.Fatal().Str("Root Path", config.RootPath).Msg("Root Path not exists") + } +} + +func runHTTPServer(gitea gitea.GiteaWebhook) { + http.HandleFunc("/gitea", gitea.WebhookEndpoint) + http.HandleFunc("/", func(writer http.ResponseWriter, request *http.Request) { + writer.Write([]byte("Ok")) + }) + + err := http.ListenAndServe(":3000", nil) + if err != nil { + log.Warn().Err(err).Msg("Error while running http servre") + } +} + +func readConfig() config.GiteaPagesConfig { + var configFile string + flag.StringVar(&configFile, "c", "/etc/gitea-page/config.yml", "Specify configfile, default /etc/gitea-page/config.yml") + flag.Parse() + + ymlFile, err := os.ReadFile(configFile) + if err != nil { + log.Fatal().Str("configFile", configFile).Err(err).Msg("Cant read config file") + } + + config := config.GiteaPagesConfig{} + + yaml.Unmarshal(ymlFile, &config) + log.Debug().Str("configFile", configFile).Interface("config", config).Msg("Read config from File") + + return config +} + +func updateCallback(owner, name, url string) { + +} \ No newline at end of file