Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Add skip to test if branch do not exists, instead of failing #9204

Closed
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions applicationset/services/scm_provider/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ func getBranches(ctx context.Context, provider SCMProviderService, repos []*Repo
for _, repo := range repos {
reposFilled, err := provider.GetBranches(ctx, repo)
if err != nil {
if checkBranchDoNotExist(err.Error()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this hide an error where the repo doesn't exist? Or will it only return true if a branch doesn't exist?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will only skip errors if branch doesn't exist, i'll add a UT for this

Copy link
Member Author

@rishabh625 rishabh625 Apr 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added Test cases, added with gitea provider only

  1. branch doesn't exist
  2. repo doesn't exist

continue
}
return nil, err
}
reposWithBranches = append(reposWithBranches, reposFilled...)
Expand Down Expand Up @@ -165,3 +168,11 @@ func getApplicableFilters(filters []*Filter) map[FilterType][]*Filter {
}
return filterMap
}

func checkBranchDoNotExist(error string) bool {
error = strings.ToLower(error)
if strings.Contains(error, "not found") || strings.Contains(error, "notfound") || strings.Contains(error, "404") || strings.Contains(error, "do not exists") {
rishabh625 marked this conversation as resolved.
Show resolved Hide resolved
return true
}
return false
}