// FormatRepoURL returns a canonical gitiles URL of the repo.
// If auth is true, the returned URL has "/a/" path prefix.
// See also ParseRepoURL.
557708
func FormatRepoURL(host, project string, auth bool) url.URL {
	pathPrefix := ""
	if auth {
		pathPrefix = "/a"
	}
	return url.URL{
		Scheme: "https",
		Host:   host,
		Path:   fmt.Sprintf("%s/%s", pathPrefix, project),
	}
}
609709
func (r *Repository) GetMirrorURL() string {
	if r == nil || r.MirrorURL == nil {
		return ""
	}
	return *r.MirrorURL
}
550678
func (s *Service) Url(publicId string, rtype ResourceType) string {
	path := imageType
	if rtype == PdfType {
		path = pdfType
	} else if rtype == VideoType {
		path = videoType
	} else if rtype == RawType {
		path = rawType
	}
	return fmt.Sprintf("%s/%s/%s/upload/%s", baseResourceUrl, s.cloudName, path, publicId)
}
77341
func (c *client) getRaw(ctx context.Context, urlPath string, query url.Values) (http.Header, []byte, error) {
	u := fmt.Sprintf("%s/%s", strings.TrimSuffix(c.BaseURL, "/"), strings.TrimPrefix(urlPath, "/"))
	if query != nil {
		u = fmt.Sprintf("%s?%s", u, query.Encode())
	}
	r, err := ctxhttp.Get(ctx, c.Client, u)
	if err != nil {
		return http.Header{}, []byte{}, transient.Tag.Apply(err)
	}

	defer r.Body.Close()
	body, err := ioutil.ReadAll(r.Body)
	if err != nil {
		return r.Header, []byte{}, errors.Annotate(err, "could not read response body").Err()
	}

	switch r.StatusCode {
	case http.StatusOK:
		return r.Header, bytes.TrimPrefix(body, jsonPrefix), nil

	case http.StatusTooManyRequests:
		logging.Errorf(ctx, "Gitiles quota error.\nResponse headers: %v\nResponse body: %s",
			r.Header, body)
		return r.Header, body, status.Errorf(codes.ResourceExhausted, "insufficient Gitiles quota")

	case http.StatusNotFound:
		return r.Header, body, status.Errorf(codes.NotFound, "not found")

	default:
		logging.Errorf(ctx, "gitiles: unexpected HTTP %d response.\nResponse headers: %v\nResponse body: %s",
			r.StatusCode,
			r.Header, body)
		return r.Header, body, status.Errorf(codes.Internal, "unexpected HTTP %d from Gitiles", r.StatusCode)
	}
}
860915
func (c *Client) MkdirAll(path string, _ os.FileMode) error {
	path = FixSlashes(path)
	status := c.mkcol(path)
	if status == 201 {
		return nil
	} else if status == 409 {
		paths := strings.Split(path, "/")
		sub := "/"
		for _, e := range paths {
			if e == "" {
				continue
			}
			sub += e + "/"
			status = c.mkcol(sub)
			if status != 201 {
				return newPathError("MkdirAll", sub, status)
			}
		}
		return nil
	}

	return newPathError("MkdirAll", path, status)
}
1158240
func (client *peerRESTClient) ReloadFormat(dryRun bool) error {
	values := make(url.Values)
	if dryRun {
		values.Set(peerRESTDryRun, "true")
	} else {
		values.Set(peerRESTDryRun, "false")
	}

	respBody, err := client.call(peerRESTMethodReloadFormat, values, nil, -1)
	if err != nil {
		return err
	}
	defer http.DrainBody(respBody)
	return nil
}
1053847
func ParseUpstreamURL() (owner, repo string, err error) {
	// Load the Git config.
	gitConfig, err := git.LoadConfig()
	if err != nil {
		return "", "", err
	}
	remoteName := gitConfig.RemoteName

	// Get the upstream URL.
	task := fmt.Sprintf("Get URL for git remote '%v'", remoteName)
	remoteURL, err := git.GetConfigString(fmt.Sprintf("remote.%v.url", remoteName))
	if err != nil {
		return "", "", errs.NewError(task, err)
	}

	// Parse it and return the result.
	return parseUpstreamURL(remoteURL)
}
1231936
func (c *Content) IsRepoValidURL() bool {
	r, err := regexp.Compile(`(?:git|ssh|https?|git@[-\w.]+):(\/\/)?(.*?)(\.git)(\/?|\#[-\d\w._]+?)$`)
	if err != nil {
		return false
	}
	return r.MatchString(c.Repository)
}
249151
func (p *PathSpec) RelURL(in string, addLanguage bool) string {
	baseURL := p.BaseURL.String()
	canonifyURLs := p.CanonifyURLs
	if (!strings.HasPrefix(in, baseURL) && strings.HasPrefix(in, "http")) || strings.HasPrefix(in, "//") {
		return in
	}

	u := in

	if strings.HasPrefix(in, baseURL) {
		u = strings.TrimPrefix(u, baseURL)
	}

	if addLanguage {
		prefix := p.GetLanguagePrefix()
		if prefix != "" {
			hasPrefix := false
			// avoid adding language prefix if already present
			if strings.HasPrefix(in, "/") {
				hasPrefix = strings.HasPrefix(in[1:], prefix)
			} else {
				hasPrefix = strings.HasPrefix(in, prefix)
			}

			if !hasPrefix {
				hadSlash := strings.HasSuffix(u, "/")

				u = path.Join(prefix, u)

				if hadSlash {
					u += "/"
				}
			}
		}
	}

	if !canonifyURLs {
		u = AddContextRoot(baseURL, u)
	}

	if in == "" && !strings.HasSuffix(u, "/") && strings.HasSuffix(baseURL, "/") {
		u += "/"
	}

	if !strings.HasPrefix(u, "/") {
		u = "/" + u
	}

	return u
}
998866
func (r *SourceRepository) RemoteURL() (*s2igit.URL, bool, error) {
	if r.remoteURL != nil {
		return r.remoteURL, true, nil
	}
	if r.url.IsLocal() {
		gitRepo := git.NewRepository()
		remote, ok, err := gitRepo.GetOriginURL(r.url.LocalPath())
		if err != nil && err != git.ErrGitNotAvailable {
			return nil, false, err
		}
		if !ok {
			return nil, ok, nil
		}
		ref := gitRepo.GetRef(r.url.LocalPath())
		if len(ref) > 0 {
			remote = fmt.Sprintf("%s#%s", remote, ref)
		}

		if r.remoteURL, err = s2igit.Parse(remote); err != nil {
			return nil, false, err
		}
	} else {
		r.remoteURL = &r.url
	}
	return r.remoteURL, true, nil
}
1301184
func (s *RemoteApplication) URL() (string, bool) {
	return s.doc.URL, s.doc.URL != ""
}
776264
func (t *Trending) buildAvatarURL(avatar string, exists bool) *url.URL {
	if exists == false {
		return nil
	}

	avatarURL, err := url.Parse(avatar)
	if err != nil {
		return nil
	}

	// Remove s parameter
	// The "s" parameter controls the size of the avatar
	q := avatarURL.Query()
	q.Del("s")
	avatarURL.RawQuery = q.Encode()

	return avatarURL
}
1165894
func (a GatewayUnsupported) ReloadFormat(ctx context.Context, dryRun bool) error {
	return NotImplemented{}
}
779958
func (s *AliasService) buildURL() (string, url.Values, error) {
	path := "/_aliases"

	// Add query string parameters
	params := url.Values{}
	if s.pretty {
		params.Set("pretty", fmt.Sprintf("%v", s.pretty))
	}
	return path, params, nil
}
982498
func (s *IndicesShrinkService) buildURL() (string, url.Values, error) {
	// Build URL
	path, err := uritemplates.Expand("/{source}/_shrink/{target}", map[string]string{
		"source": s.source,
		"target": s.target,
	})
	if err != nil {
		return "", url.Values{}, err
	}

	// Add query string parameters
	params := url.Values{}
	if s.pretty {
		params.Set("pretty", "true")
	}
	if s.masterTimeout != "" {
		params.Set("master_timeout", s.masterTimeout)
	}
	if s.timeout != "" {
		params.Set("timeout", s.timeout)
	}
	if s.waitForActiveShards != "" {
		params.Set("wait_for_active_shards", s.waitForActiveShards)
	}
	return path, params, nil
}
1109172
func NormalizeRepoURL(repoURL string, auth bool) (*url.URL, error) {
	host, project, err := ParseRepoURL(repoURL)
	if err != nil {
		return nil, err
	}
	u := FormatRepoURL(host, project, auth)
	return &u, nil
}
872501
func (n *Nginx) TOML() string {
	s := make([]string, len(n.URLs))
	for k, v := range n.URLs {
		s[k] = strconv.Quote(v)
	}
	return fmt.Sprintf(`[[inputs.%s]]
  # An array of Nginx stub_status URI to gather stats.
  # exp http://localhost/server_status
  urls = [%s]
`, n.PluginName(), strings.Join(s, ", "))
}