Skip to content

Commit

Permalink
fix: fall back to only branch if default branch is missing in gitea (a…
Browse files Browse the repository at this point in the history
…rgoproj#9228)

* fix: fall back to only branch if default branch is missing in gitea

Signed-off-by: Michael Crenshaw <michael@crenshaw.dev>

* throw meaningful error, use different org for test

Signed-off-by: Michael Crenshaw <michael@crenshaw.dev>
  • Loading branch information
crenshaw-dev authored Apr 27, 2022
1 parent e07b3e7 commit 721798e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
5 changes: 4 additions & 1 deletion applicationset/services/scm_provider/gitea.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ func NewGiteaProvider(ctx context.Context, owner, token, url string, allBranches

func (g *GiteaProvider) GetBranches(ctx context.Context, repo *Repository) ([]*Repository, error) {
if !g.allBranches {
branch, _, err := g.client.GetRepoBranch(g.owner, repo.Repository, repo.Branch)
branch, status, err := g.client.GetRepoBranch(g.owner, repo.Repository, repo.Branch)
if status.StatusCode == 404 {
return nil, fmt.Errorf("got 404 while getting default branch %q for repo %q - check your repo config: %w", repo.Branch, repo.Repository, err)
}
if err != nil {
return nil, err
}
Expand Down
16 changes: 8 additions & 8 deletions applicationset/services/scm_provider/gitea_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@ func TestGiteaListRepos(t *testing.T) {
{
name: "blank protocol",
allBranches: false,
url: "git@gitea.com:gitea/go-sdk.git",
branches: []string{"master"},
url: "git@gitea.com:test-argocd/pr-test.git",
branches: []string{"main"},
},
{
name: "ssh protocol",
allBranches: false,
proto: "ssh",
url: "git@gitea.com:gitea/go-sdk.git",
url: "git@gitea.com:test-argocd/pr-test.git",
},
{
name: "https protocol",
allBranches: false,
proto: "https",
url: "https://gitea.com/gitea/go-sdk",
url: "https://gitea.com/test-argocd/pr-test",
},
{
name: "other protocol",
Expand All @@ -43,14 +43,14 @@ func TestGiteaListRepos(t *testing.T) {
{
name: "all branches",
allBranches: true,
url: "git@gitea.com:gitea/go-sdk.git",
branches: []string{"master", "release/v0.11", "release/v0.12", "release/v0.13", "release/v0.14", "release/v0.15"},
url: "git@gitea.com:test-argocd/pr-test.git",
branches: []string{"main"},
},
}

for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
provider, _ := NewGiteaProvider(context.Background(), "gitea", "", "https://gitea.com/", c.allBranches, false)
provider, _ := NewGiteaProvider(context.Background(), "test-argocd", "", "https://gitea.com/", c.allBranches, false)
rawRepos, err := ListRepos(context.Background(), provider, c.filters, c.proto)
if c.hasError {
assert.NotNil(t, err)
Expand All @@ -61,7 +61,7 @@ func TestGiteaListRepos(t *testing.T) {
repos := []*Repository{}
branches := []string{}
for _, r := range rawRepos {
if r.Repository == "go-sdk" {
if r.Repository == "pr-test" {
repos = append(repos, r)
branches = append(branches, r.Branch)
}
Expand Down

0 comments on commit 721798e

Please sign in to comment.