This commit is contained in:
Adam Majer 2024-07-16 17:05:43 +02:00
parent a1758ba643
commit f260ee678e

View File

@ -1,52 +1,28 @@
package main package main
import ( import (
"errors"
"fmt"
"log"
"net/http"
"os"
"path/filepath"
"src.opensuse.org/autogits/common" "src.opensuse.org/autogits/common"
) )
const ( const (
GitAuthor = "GiteaBot - Obs Staging" GitAuthor = "GiteaBot - Obs Staging"
ObsBuildBot = "/obsbuild"
) )
var GiteaToken string var GiteaToken string
func parseObsSecretToken() (string, error) {
ObsToken := os.Getenv(ObsTokenEnv)
if len(ObsToken) < 10 {
return "", fmt.Errorf("Missing %s", ObsTokenEnv)
}
err := os.Setenv(ObsTokenEnv, "")
if err != nil {
return "", fmt.Errorf("Cannot reset %s: %v", GiteaTokenEnv, err)
}
return ObsToken, nil
}
func parseGiteaSecretToken() (string, error) {
GiteaToken := os.Getenv(GiteaTokenEnv)
if len(GiteaToken) < 10 {
return errors.New(GiteaTokenEnv + " not provided")
}
err := os.Setenv(GiteaTokenEnv, "")
if err != nil {
return fmt.Errorf("%s: %v", "Cannot reset "+GiteaTokenEnv, err)
}
return nil
}
func main() { func main() {
parseGiteaSecretToken() var defs common.ListenDefinitions
parseObsSecretToken()
// createListenServer() defs.Url = ObsBuildBot
defs.GitAuthor = GitAuthor
defs.Handlers = make(map[string]common.RequestProcessor)
defs.Handlers[common.RequestType_PR] = processPullRequest
defs.Handlers[common.RequestType_PR_sync] = processPullRequest
common.RequireGiteaSecretToken()
common.RequireObsSecretToken()
common.StartServerWithAddress(defs, ListenAddr)
} }