You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: get_branch_head.go
    path of file: ./repos/porter/api/server/handlers/gitinstallation
    
    the code of the file until where you have to start completion: package gitinstallation

import (
	"net/http"

	"github.com/porter-dev/porter/api/server/handlers"
	"github.com/porter-dev/porter/api/server/shared"
	"github.com/porter-dev/porter/api/server/shared/apierrors"
	"github.com/porter-dev/porter/api/server/shared/commonutils"
	"github.com/porter-dev/porter/api/server/shared/config"
	"github.com/porter-dev/porter/internal/telemetry"
)

// GetBranchHeadHandler is the handler for the /{branch}/head endpoint
type GetBranchHeadHandler struct {
	handlers.PorterHandlerReadWriter
}

// NewGetBranchHeadHandler handles GET requests to /{branch}/head
func NewGetBranchHeadHandler(
	config *config.Config,
	decoderValidator shared.RequestDecoderValidator,
	writer shared.ResultWriter,
) *GetBranchHeadHandler {
	return &GetBranchHeadHandler{
		PorterHandlerReadWriter: handlers.NewDefaultPorterHandler(config, decoderValidator, writer),
	}
}

// GetBra
    
func (c *GetBranchHeadHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	ctx, span := telemetry.NewSpan(r.Context(), "serve-get-branch-head")
	defer span.End()

	owner, name, ok := commonutils.GetOwnerAndNameParams(c, w, r)

	if !ok {
		err := telemetry.Error(ctx, span, nil, "could not get owner and name from request")
		c.HandleAPIError(w, r, apierrors.NewErrPassThroughToClient(err, http.StatusBadRequest))
		return
	}

	telemetry.WithAttributes(span,
		telemetry.AttributeKV{Key: "owner", Value: owner},
		telemetry.AttributeKV{Key: "name", Value: name},
	)

	branchName, ok := commonutils.GetBranchParam(c, w, r)
	if !ok {
		err := telemetry.Error(ctx, span, nil, "unable to get branch name")
		c.HandleAPIError(w, r, apierrors.NewErrPassThroughToClient(err, http.StatusBadRequest))
		return
	}

	client, err := GetGithubAppClientFromRequest(c.Config(), r)
	if err != nil {
		err = telemetry.Error(ctx, span, err, "could not get github app client")
		c.HandleAPIError(w, r, apierrors.NewErrPassThroughToClient(err, http.StatusInternalServerError))
		return
	}

	branch, _, err := client.Repositories.GetBranch(ctx, owner, name, branchName, true)
	if err != nil {
		err = telemetry.Error(ctx, span, err, "could not get branch")
		c.HandleAPIError(w, r, apierrors.NewErrPassThroughToClient(err, http.StatusInternalServerError))
		return
	}

	if branch == nil {
		err = telemetry.Error(ctx, span, nil, "branch does not exist")
		c.HandleAPIError(w, r, apierrors.NewErrPassThroughToClient(err, http.StatusNotFound))
		return
	}

	if branch.Commit == nil || branch.Commit.SHA == nil {
		err = telemetry.Error(ctx, span, nil, "branch head does not exist")
		c.HandleAPIError(w, r, apierrors.NewErrPassThroughToClient(err, http.StatusNotFound))
		return
	}

	response := &GetBranchHeadResponse{
		CommitSHA: *branch.Commit.SHA,
	}

	c.WriteResult(w, r, response)
}