예제 #1
0
func (s *GitUploadPackService) doRequest(method, url string, content *strings.Reader) (*http.Response, error) {
	var body io.Reader
	if content != nil {
		body = content
	}

	req, err := http.NewRequest(method, url, body)
	if err != nil {
		return nil, core.NewPermanentError(err)
	}

	s.applyHeadersToRequest(req, content)
	s.applyAuthToRequest(req)

	res, err := s.Client.Do(req)
	if err != nil {
		return nil, core.NewUnexpectedError(err)
	}

	if err := NewHTTPError(res); err != nil {
		return nil, err
	}

	return res, nil
}
예제 #2
0
func (r *GitUploadPackInfo) Decode(d *pktline.Decoder) error {
	if err := r.read(d); err != nil {
		if err == EmptyGitUploadPackErr {
			return core.NewPermanentError(err)
		}

		return core.NewUnexpectedError(err)
	}

	return nil
}
예제 #3
0
func NewHTTPError(r *http.Response) error {
	if r.StatusCode >= 200 && r.StatusCode < 300 {
		return nil
	}

	err := &HTTPError{r}
	if r.StatusCode == 404 || r.StatusCode == 401 {
		return core.NewPermanentError(common.NotFoundErr)
	}

	return core.NewUnexpectedError(err)
}
예제 #4
0
func NewEndpoint(url string) (Endpoint, error) {
	vcs, err := vcsurl.Parse(url)
	if err != nil {
		return "", core.NewPermanentError(err)
	}

	link := vcs.Link()
	if !strings.HasSuffix(link, ".git") {
		link += ".git"
	}

	return Endpoint(link), nil
}