コード例 #1
0
ファイル: helper.go プロジェクト: fclairamb/drone
// convertRepo is a helper function used to convert a Bitbucket
// repository structure to the common Drone repository structure.
func convertRepo(from *Repo) *model.Repo {
	repo := model.Repo{
		Owner:     strings.Split(from.FullName, "/")[0],
		Name:      strings.Split(from.FullName, "/")[1],
		FullName:  from.FullName,
		Link:      from.Links.Html.Href,
		IsPrivate: from.IsPrivate,
		Avatar:    from.Owner.Links.Avatar.Href,
		Kind:      from.Scm,
		Branch:    "master",
	}

	if repo.Kind == model.RepoHg {
		repo.Branch = "default"
	}

	// in some cases, the owner of the repository is not
	// provided, however, we do have the full name.
	if len(repo.Owner) == 0 {
		repo.Owner = strings.Split(repo.FullName, "/")[0]
	}

	// above we manually constructed the repository clone url.
	// below we will iterate through the list of clone links and
	// attempt to instead use the clone url provided by bitbucket.
	for _, link := range from.Links.Clone {
		if link.Name == "https" {
			repo.Clone = link.Href
			break
		}
	}

	// if no repository name is provided, we use the Html link.
	// this excludes the .git suffix, but will still clone the repo.
	if len(repo.Clone) == 0 {
		repo.Clone = repo.Link
	}

	// if bitbucket tries to automatically populate the user
	// in the url we must strip it out.
	clone, err := url.Parse(repo.Clone)
	if err == nil {
		clone.User = nil
		repo.Clone = clone.String()
	}

	return &repo
}
コード例 #2
0
ファイル: convert.go プロジェクト: sis-tools/drone
// convertRepo is a helper function used to convert a Bitbucket server repository
// structure to the common Drone repository structure.
func convertRepo(from *internal.Repo) *model.Repo {

	repo := model.Repo{
		Name:      from.Slug,
		Owner:     from.Project.Key,
		Branch:    "master",
		Kind:      model.RepoGit,
		IsPrivate: true, // Since we have to use Netrc it has to always be private :/
		FullName:  fmt.Sprintf("%s/%s", from.Project.Key, from.Slug),
	}

	for _, item := range from.Links.Clone {
		if item.Name == "http" {
			uri, err := url.Parse(item.Href)
			if err != nil {
				return nil
			}
			uri.User = nil
			repo.Clone = uri.String()
		}
	}
	for _, item := range from.Links.Self {
		if item.Href != "" {
			repo.Link = item.Href
		}
	}
	return &repo

}