diff --git a/config.go b/config.go deleted file mode 100644 index ba15e91..0000000 --- a/config.go +++ /dev/null @@ -1,36 +0,0 @@ -package main - -import ( - "io/ioutil" - - "github.com/palantir/go-baseapp/baseapp" - "github.com/palantir/go-githubapp/githubapp" - "github.com/pkg/errors" - "gopkg.in/yaml.v2" -) - -type Config struct { - Server baseapp.HTTPConfig `yaml:"server"` - Github githubapp.Config `yaml:"github"` - - AppConfig MyApplicationConfig `yaml:"app_configuration"` -} - -type MyApplicationConfig struct { - PullRequestPreamble string `yaml:"pull_request_preamble"` -} - -func ReadConfig(path string) (*Config, error) { - var c Config - - bytes, err := ioutil.ReadFile(path) - if err != nil { - return nil, errors.Wrapf(err, "reading server config file") - } - - if err := yaml.UnmarshalStrict(bytes, &c); err != nil { - return nil, errors.Wrap(err, "parsing configuration file as yaml") - } - - return &c, nil -} diff --git a/config.yml b/config.yml deleted file mode 100644 index 9c46fee..0000000 --- a/config.yml +++ /dev/null @@ -1,11 +0,0 @@ -server: - address: "127.0.0.1" - port: 8080 - public_url: "http://localhost:8080" - -github: - v3_api_url: "https://api.github.com/" - app: - integration_id: 0 -app_configuration: - pull_request_preamble: "I am echo bot." \ No newline at end of file diff --git a/go.sum b/go.sum index 19ba459..c800d8c 100644 --- a/go.sum +++ b/go.sum @@ -40,6 +40,7 @@ github.com/palantir/go-baseapp v0.2.1 h1:9dTuuFgLum5zgdhhhTLVO9VmjdHIgMylygeWDKv github.com/palantir/go-baseapp v0.2.1/go.mod h1:vQuqaqAh5XRwfllV8eJBs2fDczpOvOPAoLlJ+kVsF9A= github.com/palantir/go-githubapp v0.4.0 h1:k4Ot5kzm61mR4Gi7bblGI7gGmbJZn+Mi55mfi+QOZCk= github.com/palantir/go-githubapp v0.4.0/go.mod h1:/Xm5h66uEBX24An2Ln8H6Rk44z8uwk4E6m4gNrPadjQ= +github.com/palantir/go-githubapp v0.5.0 h1:mAdLgaaNV0zrqSv1q0zpJbKq65H92uIrAlSwRIRsGEE= github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= diff --git a/issue_release_status.go b/issue_release_status.go index c64902a..2a8eb42 100644 --- a/issue_release_status.go +++ b/issue_release_status.go @@ -3,6 +3,7 @@ package main import ( "context" "encoding/json" + "fmt" "io/ioutil" "net/http" "strings" @@ -83,15 +84,19 @@ func (handler *PRCreateHandler) Handle(ctx context.Context, eventType, deliveryI if err != nil { return errors.Wrap(err, "sending HTTP request") } - - var policyResponse ListPoliciesResponse + defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { return errors.Wrap(err, "reading release-manager HTTP response body") } - defer resp.Body.Close() + if resp.StatusCode != 200 { + logger.Info().Msgf("Request body: %v", body) + return errors.Errorf("expected status code 200, but recieved " + fmt.Sprintf("%v", resp.StatusCode)) + } + + var policyResponse ListPoliciesResponse err = json.Unmarshal(body, &policyResponse) if err != nil { diff --git a/main.go b/main.go index d0d9581..5a47fcd 100644 --- a/main.go +++ b/main.go @@ -15,9 +15,20 @@ import ( func main() { logger := zerolog.New(os.Stdout).With().Timestamp().Logger() - configPath := pflag.String("config-path", "config.yml", "path to configuration file") releaseManagerAuthToken := pflag.String("release-manager-auth-token", "", "auth token for accessing release manager") releaseManagerURL := pflag.String("release-manager-url", "http://localhost:8080", "url to release manager") + + var httpServerConfig baseapp.HTTPConfig + pflag.StringVar(&httpServerConfig.Address, "http-address", "localhost", "http listen address") + pflag.IntVar(&httpServerConfig.Port, "http-port", 8080, "http listen port") + pflag.StringVar(&httpServerConfig.PublicURL, "http-public_url", "https://localhost:8080", "http public url") + + var githubappConfig githubapp.Config + pflag.StringVar(&githubappConfig.V3APIURL, "github-v3_api_url", "https://api.github.com/", "github v3 api url") + pflag.Int64Var(&githubappConfig.App.IntegrationID, "github-integrationID", 0, "github integration ID") + pflag.StringVar(&githubappConfig.App.WebhookSecret, "github-webhookSecret", "", "github webhook secret") + pflag.StringVar(&githubappConfig.App.PrivateKey, "github-privateKey", "", "github app private key content") + pflag.Parse() if *releaseManagerAuthToken == "" { @@ -26,15 +37,8 @@ func main() { return } - config, err := ReadConfig(*configPath) - if err != nil { - logger.Error().Msgf("Failed to parse config: %v", err) - os.Exit(1) - return - } - server, err := baseapp.NewServer( - config.Server, + httpServerConfig, baseapp.DefaultParams(logger, "exampleapp.")..., ) if err != nil { @@ -44,8 +48,8 @@ func main() { } cc, err := githubapp.NewDefaultCachingClientCreator( - config.Github, - githubapp.WithClientUserAgent("example-app/1.0.0"), + githubappConfig, + githubapp.WithClientUserAgent("release-managar-bot/1.0.0"), githubapp.WithClientTimeout(3*time.Second), githubapp.WithClientCaching(false, func() httpcache.Cache { return httpcache.NewMemoryCache() }), githubapp.WithClientMiddleware( @@ -60,12 +64,11 @@ func main() { pullRequestHandler := &PRCreateHandler{ ClientCreator: cc, - preamble: config.AppConfig.PullRequestPreamble, releaseManagerAuthToken: *releaseManagerAuthToken, releaseManagerURL: *releaseManagerURL, } - webhookHandler := githubapp.NewDefaultEventDispatcher(config.Github, pullRequestHandler) + webhookHandler := githubapp.NewDefaultEventDispatcher(githubappConfig, pullRequestHandler) server.Mux().Handle(pat.Post("/webhook/github/bot"), webhookHandler)