// handlePatchLabel is the HTTP handler for the PATCH /api/v2/labels route.
555025
func (h *LabelHandler) handlePatchLabel(w http.ResponseWriter, r *http.Request) {
	ctx := r.Context()

	req, err := decodePatchLabelRequest(ctx, r)
	if err != nil {
		EncodeError(ctx, err, w)
		return
	}

	l, err := h.LabelService.UpdateLabel(ctx, req.LabelID, req.Update)
	if err != nil {
		EncodeError(ctx, err, w)
		return
	}

	if err := encodeResponse(ctx, w, http.StatusOK, newLabelResponse(l)); err != nil {
		logEncodingError(h.Logger, r, err)
		return
	}
}
96275
func (g *Group) Patch(path string, h HandlerFunc, opts ...HandlerOption) {
	g.add(path, h, opts, http.MethodPatch)
}
1236503
func (c *Client) UpdateLabel(ctx context.Context, id influxdb.ID, upd influxdb.LabelUpdate) (*influxdb.Label, error) {
	var label *influxdb.Label
	err := c.db.Update(func(tx *bolt.Tx) error {
		labelResponse, pe := c.updateLabel(ctx, tx, id, upd)
		if pe != nil {
			return &influxdb.Error{
				Err: pe,
				Op:  getOp(influxdb.OpUpdateLabel),
			}
		}
		label = labelResponse
		return nil
	})

	return label, err
}
449589
func (r *Request) Patch(url string) (*Response, error) {
	return r.Execute(MethodPatch, url)
}
1288167
func newDeleteLabelHandler(s plat.LabelService) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		ctx := r.Context()

		req, err := decodeDeleteLabelRequest(ctx, r)
		if err != nil {
			EncodeError(ctx, err, w)
			return
		}

		label := plat.Label{
			ResourceID: req.ResourceID,
			Name:       req.Name,
		}

		if err := s.DeleteLabel(ctx, label); err != nil {
			EncodeError(ctx, err, w)
			return
		}

		w.WriteHeader(http.StatusNoContent)
	}
}
295806
func (p LabelPrefix) String() string {
	s := fmt.Sprintf("%s:%s", p.Source, p.Prefix)
	if p.Ignore {
		s = "!" + s
	}

	return s
}
1131443
func newPostLabelHandler(s plat.LabelService) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		ctx := r.Context()

		req, err := decodePostLabelRequest(ctx, r)
		if err != nil {
			EncodeError(ctx, err, w)
			return
		}

		if err := req.Label.Validate(); err != nil {
			EncodeError(ctx, err, w)
			return
		}

		if err := s.CreateLabel(ctx, &req.Label); err != nil {
			EncodeError(ctx, err, w)
			return
		}

		if err := encodeResponse(ctx, w, http.StatusCreated, newLabelResponse(&req.Label)); err != nil {
			// TODO: this can potentially result in calling w.WriteHeader multiple times, we need to pass a logger in here
			// some how. This isn't as simple as simply passing in a logger to this function since the time that this function
			// is called is distinct from the time that a potential logger is set.
			EncodeError(ctx, err, w)
			return
		}
	}
}
597467
func NewPatchEndpointIDLabels(ctx *middleware.Context, handler PatchEndpointIDLabelsHandler) *PatchEndpointIDLabels {
	return &PatchEndpointIDLabels{Context: ctx, Handler: handler}
}
573311
func HandlerPathPrefix(prefix string, handle http.Handler) http.Handler {
	if !strings.HasPrefix(prefix, "/") {
		prefix = fmt.Sprintf("/%s", prefix)
	}
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		old := r.URL
		r.URL, _ = url.ParseRequestURI(strings.Replace(old.Path, prefix, "", 1))
		handle.ServeHTTP(w, r)
		r.URL = old
	})
}
1038953
func (p *PullRequestLinks) GetPatchURL() string {
	if p == nil || p.PatchURL == nil {
		return ""
	}
	return *p.PatchURL
}
624391
func (c *CommitsComparison) GetPatchURL() string {
	if c == nil || c.PatchURL == nil {
		return ""
	}
	return *c.PatchURL
}
359773
func parseLabelPrefix(label string) (*LabelPrefix, error) {
	labelPrefix := LabelPrefix{}
	i := strings.IndexByte(label, ':')
	if i >= 0 {
		labelPrefix.Source = label[:i]
		labelPrefix.Prefix = label[i+1:]
	} else {
		labelPrefix.Prefix = label
	}

	if labelPrefix.Prefix[0] == '!' {
		labelPrefix.Ignore = true
		labelPrefix.Prefix = labelPrefix.Prefix[1:]
	}

	r, err := regexp.Compile(labelPrefix.Prefix)
	if err != nil {
		return nil, fmt.Errorf("Unable to compile regexp: %s", err)
	}
	labelPrefix.expr = r

	return &labelPrefix, nil
}
997168
func (g *Group) PATCH(path string, handler HandlerFunc) {
	g.Handle("PATCH", path, handler)
}
203401
func (j *AuroraJob) AddLabel(key string, value string) Job {
	if _, ok := j.metadata[key]; ok {
		j.metadata[key].Value = value
	} else {
		j.metadata[key] = &aurora.Metadata{Key: key, Value: value}
		j.jobConfig.TaskConfig.Metadata = append(j.jobConfig.TaskConfig.Metadata, j.metadata[key])
	}
	return j
}
100660
func (h *OrgHandler) handlePatchOrg(w http.ResponseWriter, r *http.Request) {
	ctx := r.Context()

	req, err := decodePatchOrgRequest(ctx, r)
	if err != nil {
		EncodeError(ctx, err, w)
		return
	}

	o, err := h.OrganizationService.UpdateOrganization(ctx, req.OrgID, req.Update)
	if err != nil {
		EncodeError(ctx, err, w)
		return
	}

	if err := encodeResponse(ctx, w, http.StatusOK, newOrgResponse(o)); err != nil {
		logEncodingError(h.Logger, r, err)
		return
	}
}
349878
func (rt *Router) Patch(path string, handler http.Handler) {
	rt.Handle(http.MethodPatch, path, handler)
}
1351613
func (h *LabelHandler) handlePostLabel(w http.ResponseWriter, r *http.Request) {
	ctx := r.Context()

	req, err := decodePostLabelRequest(ctx, r)
	if err != nil {
		EncodeError(ctx, err, w)
		return
	}

	if err := h.LabelService.CreateLabel(ctx, req.Label); err != nil {
		EncodeError(ctx, err, w)
		return
	}

	if err := encodeResponse(ctx, w, http.StatusCreated, newLabelResponse(req.Label)); err != nil {
		logEncodingError(h.Logger, r, err)
		return
	}
}