Просмотр исходного кода

update api contracts and handle linter

Ian Edwards 2 лет назад
Родитель
Сommit
39238cc3da

+ 5 - 0
api/server/handlers/porter_app/create_app_template.go

@@ -218,6 +218,11 @@ func (c *CreateAppTemplateHandler) ServeHTTP(w http.ResponseWriter, r *http.Requ
 		WebhookURL:          webhookURL,
 		PorterAppRepository: c.Repo().PorterApp(),
 	})
+	if err != nil {
+		err := telemetry.Error(ctx, span, err, "unable to set repo webhook")
+		c.HandleAPIError(w, r, apierrors.NewErrPassThroughToClient(err, http.StatusInternalServerError))
+		return
+	}
 
 	res := &CreateAppTemplateResponse{
 		AppTemplateID: updatedAppTemplate.ID.String(),

+ 6 - 1
api/server/handlers/webhook/app_v2_github.go

@@ -136,9 +136,14 @@ func (c *GithubWebhookHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
 		}
 		telemetry.WithAttributes(span, telemetry.AttributeKV{Key: "deployment-target-id", Value: deploymentTarget.ID.String()})
 
+		if deploymentTarget.ClusterID != int(clusterID) {
+			err := telemetry.Error(ctx, span, err, "deployment target cluster id does not match")
+			c.HandleAPIError(w, r, apierrors.NewErrPassThroughToClient(err, http.StatusBadRequest))
+			return
+		}
+
 		deleteTargetReq := connect.NewRequest(&porterv1.DeleteDeploymentTargetRequest{
 			ProjectId:          int64(projectID),
-			ClusterId:          int64(clusterID),
 			DeploymentTargetId: deploymentTarget.ID.String(),
 		})
 

+ 1 - 1
go.mod

@@ -82,7 +82,7 @@ require (
 	github.com/matryer/is v1.4.0
 	github.com/nats-io/nats.go v1.24.0
 	github.com/open-policy-agent/opa v0.44.0
-	github.com/porter-dev/api-contracts v0.2.8
+	github.com/porter-dev/api-contracts v0.2.10
 	github.com/riandyrn/otelchi v0.5.1
 	github.com/santhosh-tekuri/jsonschema/v5 v5.0.1
 	github.com/stefanmcshane/helm v0.0.0-20221213002717-88a4a2c6e77d

+ 2 - 2
go.sum

@@ -1516,8 +1516,8 @@ github.com/pmezard/go-difflib v0.0.0-20151028094244-d8ed2627bdf0/go.mod h1:iKH77
 github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
 github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
 github.com/polyfloyd/go-errorlint v0.0.0-20210722154253-910bb7978349/go.mod h1:wi9BfjxjF/bwiZ701TzmfKu6UKC357IOAtNr0Td0Lvw=
-github.com/porter-dev/api-contracts v0.2.8 h1:z5BZihdZ75J5Dz3jCeX6ziE/wt6h4yhFqaYoO3BqBY8=
-github.com/porter-dev/api-contracts v0.2.8/go.mod h1:fX6JmP5QuzxDLvqP3evFOTXjI4dHxsG0+VKNTjImZU8=
+github.com/porter-dev/api-contracts v0.2.10 h1:xnnV3ffaLSajHMYyn96l49vLIY/J4lvZZgwKF+8aclk=
+github.com/porter-dev/api-contracts v0.2.10/go.mod h1:fX6JmP5QuzxDLvqP3evFOTXjI4dHxsG0+VKNTjImZU8=
 github.com/porter-dev/switchboard v0.0.3 h1:dBuYkiVLa5Ce7059d6qTe9a1C2XEORFEanhbtV92R+M=
 github.com/porter-dev/switchboard v0.0.3/go.mod h1:xSPzqSFMQ6OSbp42fhCi4AbGbQbsm6nRvOkrblFeXU4=
 github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=

+ 3 - 0
internal/porter_app/github.go

@@ -12,6 +12,7 @@ import (
 	"github.com/porter-dev/porter/internal/telemetry"
 )
 
+// SetRepoWebhookInput is the input to the SetRepoWebhook function
 type SetRepoWebhookInput struct {
 	PorterAppName       string
 	ClusterID           uint
@@ -23,6 +24,8 @@ type SetRepoWebhookInput struct {
 	PorterAppRepository repository.PorterAppRepository
 }
 
+// SetRepoWebhook creates or updates a github webhook for a porter app associated with a given repo
+// The webhook watches for pull request and push events, used for managing preview environments
 func SetRepoWebhook(ctx context.Context, inp SetRepoWebhookInput) error {
 	ctx, span := telemetry.NewSpan(ctx, "porter-app-set-repo-webhook")
 	defer span.End()