Skip to content

Commit 18fae0a

Browse files
authoredFeb 20, 2020
Merge pull request kubernetes#16365 from matthyx/tide-repo
Use util.Repo in prow/tide and prow/config
2 parents 915369d + 1a2cb42 commit 18fae0a

File tree

124 files changed

+298
-193
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

124 files changed

+298
-193
lines changed
 

‎prow/config/config.go

+41
Original file line numberDiff line numberDiff line change
@@ -1987,3 +1987,44 @@ func SetPostsubmitRegexes(ps []Postsubmit) error {
19871987
}
19881988
return nil
19891989
}
1990+
1991+
// OrgRepo supercedes org/repo string handling
1992+
type OrgRepo struct {
1993+
Org string
1994+
Repo string
1995+
}
1996+
1997+
func (repo OrgRepo) String() string {
1998+
return fmt.Sprintf("%s/%s", repo.Org, repo.Repo)
1999+
}
2000+
2001+
// NewOrgRepo creates a OrgRepo from org/repo string
2002+
func NewOrgRepo(orgRepo string) *OrgRepo {
2003+
parts := strings.Split(orgRepo, "/")
2004+
switch len(parts) {
2005+
case 1:
2006+
return &OrgRepo{Org: parts[0]}
2007+
case 2:
2008+
return &OrgRepo{Org: parts[0], Repo: parts[1]}
2009+
default:
2010+
return nil
2011+
}
2012+
}
2013+
2014+
// OrgReposToStrings converts a list of OrgRepo to its String() equivalent
2015+
func OrgReposToStrings(vs []OrgRepo) []string {
2016+
vsm := make([]string, len(vs))
2017+
for i, v := range vs {
2018+
vsm[i] = v.String()
2019+
}
2020+
return vsm
2021+
}
2022+
2023+
// StringsToOrgRepos converts a list of org/repo strings to its OrgRepo equivalent
2024+
func StringsToOrgRepos(vs []string) []OrgRepo {
2025+
vsm := make([]OrgRepo, len(vs))
2026+
for i, v := range vs {
2027+
vsm[i] = *NewOrgRepo(v)
2028+
}
2029+
return vsm
2030+
}

‎prow/config/inrepoconfig.go

+5-7
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"io/ioutil"
2323
"os"
2424
"path"
25-
"strings"
2625

2726
"github.com/sirupsen/logrus"
2827
utilerrors "k8s.io/apimachinery/pkg/util/errors"
@@ -64,12 +63,11 @@ func defaultProwYAMLGetter(
6463
return nil, errors.New("gitClient is nil")
6564
}
6665

67-
identifierSlashSplit := strings.Split(identifier, "/")
68-
if len(identifierSlashSplit) != 2 {
69-
return nil, fmt.Errorf("didn't get two but %d results when splitting repo identifier %q", len(identifierSlashSplit), identifier)
66+
orgRepo := *NewOrgRepo(identifier)
67+
if orgRepo.Repo == "" {
68+
return nil, fmt.Errorf("didn't get two results when splitting repo identifier %q", identifier)
7069
}
71-
organization, repository := identifierSlashSplit[0], identifierSlashSplit[1]
72-
repo, err := gc.ClientFor(organization, repository)
70+
repo, err := gc.ClientFor(orgRepo.Org, orgRepo.Repo)
7371
if err != nil {
7472
return nil, fmt.Errorf("failed to clone repo for %q: %v", identifier, err)
7573
}
@@ -89,7 +87,7 @@ func defaultProwYAMLGetter(
8987
return nil, err
9088
}
9189

92-
mergeMethod := c.Tide.MergeMethod(organization, repository)
90+
mergeMethod := c.Tide.MergeMethod(orgRepo)
9391
log.Debugf("Using merge strategy %q.", mergeMethod)
9492
if err := repo.MergeAndCheckout(baseSHA, string(mergeMethod), headSHAs...); err != nil {
9593
return nil, fmt.Errorf("failed to merge: %v", err)

0 commit comments

Comments
 (0)
Please sign in to comment.