MCPcopy
hub / github.com/harness/harness / GetPackageMetadata

Method GetPackageMetadata

registry/app/api/handler/npm/get_metadata.go:30–55  ·  view source on GitHub ↗
(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

28)
29
30func (h *handler) GetPackageMetadata(w http.ResponseWriter, r *http.Request) {
31 ctx := r.Context()
32 info, ok := request.ArtifactInfoFrom(ctx).(npm2.ArtifactInfo)
33 if !ok {
34 log.Ctx(ctx).Error().Msg("Failed to get npm artifact info from context")
35 h.HandleErrors(r.Context(), []error{fmt.Errorf("failed to fetch npm artifact info from context")}, w)
36 return
37 }
38
39 response := h.controller.GetPackageMetadata(ctx, info)
40
41 if !commons.IsEmpty(response.GetError()) {
42 if errors2.IsNotFound(response.GetError()) {
43 http.Error(w, response.GetError().Error(), http.StatusNotFound)
44 return
45 }
46 http.Error(w, response.GetError().Error(), http.StatusInternalServerError)
47 return
48 }
49 w.Header().Set("Content-Type", "application/json")
50 err := json.NewEncoder(w).Encode(response.PackageMetadata)
51 if err != nil {
52 http.Error(w, err.Error(), http.StatusInternalServerError)
53 return
54 }
55}

Callers

nothing calls this directly

Calls 11

HandleErrorsMethod · 0.95
ArtifactInfoFromFunction · 0.92
IsEmptyFunction · 0.92
MsgMethod · 0.80
ErrorMethod · 0.65
GetPackageMetadataMethod · 0.65
GetErrorMethod · 0.65
SetMethod · 0.65
EncodeMethod · 0.65
ErrorfMethod · 0.45
HeaderMethod · 0.45

Tested by

no test coverage detected