|
|
@@ -11,6 +11,7 @@ import (
|
|
|
"github.com/porter-dev/porter/api/server/shared/commonutils"
|
|
|
"github.com/porter-dev/porter/api/server/shared/config"
|
|
|
"github.com/porter-dev/porter/api/types"
|
|
|
+ "github.com/porter-dev/porter/internal/telemetry"
|
|
|
)
|
|
|
|
|
|
type GithubGetContentsHandler struct {
|
|
|
@@ -29,33 +30,44 @@ func NewGithubGetContentsHandler(
|
|
|
}
|
|
|
|
|
|
func (c *GithubGetContentsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|
|
- ctx := r.Context()
|
|
|
- request := &types.GetContentsRequest{}
|
|
|
-
|
|
|
- ok := c.DecodeAndValidate(w, r, request)
|
|
|
+ ctx, span := telemetry.NewSpan(r.Context(), "serve-github-get-contents")
|
|
|
+ defer span.End()
|
|
|
|
|
|
- if !ok {
|
|
|
+ request := &types.GetContentsRequest{}
|
|
|
+ if ok := c.DecodeAndValidate(w, r, request); !ok {
|
|
|
+ err := telemetry.Error(ctx, span, nil, "invalid request")
|
|
|
+ c.HandleAPIError(w, r, apierrors.NewErrPassThroughToClient(err, http.StatusBadRequest))
|
|
|
return
|
|
|
}
|
|
|
|
|
|
owner, name, ok := commonutils.GetOwnerAndNameParams(c, w, r)
|
|
|
-
|
|
|
if !ok {
|
|
|
+ err := telemetry.Error(ctx, span, nil, "owner and name params not found")
|
|
|
+ c.HandleAPIError(w, r, apierrors.NewErrPassThroughToClient(err, http.StatusBadRequest))
|
|
|
return
|
|
|
}
|
|
|
|
|
|
branch, ok := commonutils.GetBranchParam(c, w, r)
|
|
|
-
|
|
|
if !ok {
|
|
|
+ err := telemetry.Error(ctx, span, nil, "branch param not found")
|
|
|
+ c.HandleAPIError(w, r, apierrors.NewErrPassThroughToClient(err, http.StatusBadRequest))
|
|
|
return
|
|
|
}
|
|
|
|
|
|
client, err := GetGithubAppClientFromRequest(c.Config(), r)
|
|
|
if err != nil {
|
|
|
- c.HandleAPIError(w, r, apierrors.NewErrInternal(err))
|
|
|
+ err = telemetry.Error(ctx, span, err, "could not get github app client from request")
|
|
|
+ c.HandleAPIError(w, r, apierrors.NewErrPassThroughToClient(err, http.StatusInternalServerError))
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+ telemetry.WithAttributes(
|
|
|
+ span,
|
|
|
+ telemetry.AttributeKV{Key: "repo-owner", Value: owner},
|
|
|
+ telemetry.AttributeKV{Key: "repo-name", Value: name},
|
|
|
+ telemetry.AttributeKV{Key: "repo-branch", Value: branch},
|
|
|
+ )
|
|
|
+
|
|
|
repoContentOptions := github.RepositoryContentGetOptions{}
|
|
|
repoContentOptions.Ref = branch
|
|
|
_, directoryContents, resp, err := client.Repositories.GetContents(
|
|
|
@@ -66,8 +78,8 @@ func (c *GithubGetContentsHandler) ServeHTTP(w http.ResponseWriter, r *http.Requ
|
|
|
&repoContentOptions,
|
|
|
)
|
|
|
if err != nil {
|
|
|
- c.HandleAPIError(w, r, apierrors.NewErrPassThroughToClient(
|
|
|
- err, resp.StatusCode))
|
|
|
+ err = telemetry.Error(ctx, span, err, "could not get contents from github")
|
|
|
+ c.HandleAPIError(w, r, apierrors.NewErrPassThroughToClient(err, resp.StatusCode))
|
|
|
return
|
|
|
}
|
|
|
|