2021-06-20 15:16:06 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2022-05-21 18:21:05 +02:00
|
|
|
"fmt"
|
2021-07-11 15:17:03 +02:00
|
|
|
"log"
|
2021-06-20 15:39:54 +02:00
|
|
|
"os"
|
2021-06-20 15:16:06 +02:00
|
|
|
"path"
|
|
|
|
|
2021-10-10 16:18:14 +02:00
|
|
|
"gitea-sonarqube-pr-bot/internal/api"
|
2022-05-21 18:21:05 +02:00
|
|
|
giteaSdk "gitea-sonarqube-pr-bot/internal/clients/gitea"
|
|
|
|
sonarQubeSdk "gitea-sonarqube-pr-bot/internal/clients/sonarqube"
|
2021-06-29 08:07:28 +02:00
|
|
|
"gitea-sonarqube-pr-bot/internal/settings"
|
2021-10-10 16:18:14 +02:00
|
|
|
|
2022-05-21 18:21:05 +02:00
|
|
|
"github.com/fvbock/endless"
|
2021-07-11 15:17:03 +02:00
|
|
|
"github.com/urfave/cli/v2"
|
2021-06-20 15:16:06 +02:00
|
|
|
)
|
|
|
|
|
2021-06-29 08:07:28 +02:00
|
|
|
func getConfigLocation() string {
|
2021-06-20 15:16:06 +02:00
|
|
|
configPath := path.Join("config")
|
2021-06-20 15:39:54 +02:00
|
|
|
if customConfigPath, ok := os.LookupEnv("PRBOT_CONFIG_PATH"); ok {
|
|
|
|
configPath = customConfigPath
|
|
|
|
}
|
|
|
|
|
|
|
|
return configPath
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
2021-06-29 08:07:28 +02:00
|
|
|
settings.Load(getConfigLocation())
|
2021-07-11 15:17:03 +02:00
|
|
|
|
|
|
|
app := &cli.App{
|
2021-10-03 17:57:22 +02:00
|
|
|
Name: "gitea-sonarqube-pr-bot",
|
|
|
|
Usage: "Improve your experience with SonarQube and Gitea",
|
2021-07-11 15:17:03 +02:00
|
|
|
Description: `By default, gitea-sonarqube-pr-bot will start running the webserver if no arguments are passed.`,
|
2022-05-21 18:21:05 +02:00
|
|
|
Action: serveApi,
|
2021-07-11 15:17:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
err := app.Run(os.Args)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2021-06-20 15:16:06 +02:00
|
|
|
}
|
2022-05-21 18:21:05 +02:00
|
|
|
|
|
|
|
func serveApi(c *cli.Context) error {
|
|
|
|
fmt.Println("Hi! I'm the Gitea-SonarQube-PR bot. At your service.")
|
|
|
|
|
|
|
|
giteaHandler := api.NewGiteaWebhookHandler(giteaSdk.New(), sonarQubeSdk.New())
|
|
|
|
sqHandler := api.NewSonarQubeWebhookHandler(giteaSdk.New(), sonarQubeSdk.New())
|
|
|
|
server := api.New(giteaHandler, sqHandler)
|
|
|
|
|
|
|
|
return endless.ListenAndServe(":3000", server.Engine)
|
|
|
|
}
|