func()

in internal/gitlabnet/lfstransfer/client.go [285:333]


func (c *Client) Unlock(id string, force bool, refname string) (*Lock, error) {
	var ref *batchRef
	if refname != "" {
		ref = &batchRef{
			Name: refname,
		}
	}
	body := &unlockRequest{
		Force: force,
		Ref:   ref,
	}
	jsonData, err := json.Marshal(body)
	if err != nil {
		return nil, err
	}
	jsonReader := bytes.NewReader(jsonData)

	req, err := newHTTPRequest(http.MethodPost, fmt.Sprintf("%s/locks/%s/unlock", c.href, id), jsonReader)
	if err != nil {
		return nil, err
	}

	req.Header.Set("Content-Type", "application/vnd.git-lfs+json")
	req.Header.Set("Authorization", c.auth)

	client := newHTTPClient()
	res, err := client.Do(req)
	if err != nil {
		return nil, err
	}

	defer func() { _ = res.Body.Close() }()

	switch {
	case res.StatusCode >= 200 && res.StatusCode <= 299:
		response := &unlockResponse{}
		if err := gitlabnet.ParseJSON(res, response); err != nil {
			return nil, err
		}

		return response.Lock, nil
	case res.StatusCode == http.StatusForbidden:
		return nil, transfer.ErrForbidden
	case res.StatusCode == http.StatusNotFound:
		return nil, transfer.ErrNotFound
	default:
		return nil, fmt.Errorf("internal error")
	}
}