Skip to content
Snippets Groups Projects
Commit 98cf176c authored by Hidde Beydals's avatar Hidde Beydals
Browse files

Improve Git provider error messages

parent 39b00797
No related branches found
No related tags found
No related merge requests found
...@@ -77,7 +77,7 @@ func (p *GithubProvider) CreateRepository(ctx context.Context, r *Repository) (b ...@@ -77,7 +77,7 @@ func (p *GithubProvider) CreateRepository(ctx context.Context, r *Repository) (b
}) })
if err != nil { if err != nil {
if !strings.Contains(err.Error(), "name already exists on this account") { if !strings.Contains(err.Error(), "name already exists on this account") {
return false, fmt.Errorf("create repository error: %w", err) return false, fmt.Errorf("failed to create repository, error: %w", err)
} }
} else { } else {
return true, nil return true, nil
...@@ -95,13 +95,13 @@ func (p *GithubProvider) AddTeam(ctx context.Context, r *Repository, name, permi ...@@ -95,13 +95,13 @@ func (p *GithubProvider) AddTeam(ctx context.Context, r *Repository, name, permi
// check team exists // check team exists
_, _, err = gh.Teams.GetTeamBySlug(ctx, r.Owner, name) _, _, err = gh.Teams.GetTeamBySlug(ctx, r.Owner, name)
if err != nil { if err != nil {
return false, fmt.Errorf("get team %s error: %w", name, err) return false, fmt.Errorf("failed to retrieve team '%s', error: %w", name, err)
} }
// check if team is assigned to the repo // check if team is assigned to the repo
_, resp, err := gh.Teams.IsTeamRepoBySlug(ctx, r.Owner, name, r.Owner, r.Name) _, resp, err := gh.Teams.IsTeamRepoBySlug(ctx, r.Owner, name, r.Owner, r.Name)
if resp == nil && err != nil { if resp == nil && err != nil {
return false, fmt.Errorf("is team %s error: %w", name, err) return false, fmt.Errorf("failed to determine if team '%s' is assigned to the repository, error: %w", name, err)
} }
// add team to the repo // add team to the repo
...@@ -110,7 +110,7 @@ func (p *GithubProvider) AddTeam(ctx context.Context, r *Repository, name, permi ...@@ -110,7 +110,7 @@ func (p *GithubProvider) AddTeam(ctx context.Context, r *Repository, name, permi
Permission: permission, Permission: permission,
}) })
if err != nil { if err != nil {
return false, fmt.Errorf("add team %s error: %w", name, err) return false, fmt.Errorf("failed to add team '%s' to the repository, error: %w", name, err)
} }
return true, nil return true, nil
} }
...@@ -128,10 +128,10 @@ func (p *GithubProvider) AddDeployKey(ctx context.Context, r *Repository, key, k ...@@ -128,10 +128,10 @@ func (p *GithubProvider) AddDeployKey(ctx context.Context, r *Repository, key, k
// list deploy keys // list deploy keys
keys, resp, err := gh.Repositories.ListKeys(ctx, r.Owner, r.Name, nil) keys, resp, err := gh.Repositories.ListKeys(ctx, r.Owner, r.Name, nil)
if err != nil { if err != nil {
return false, fmt.Errorf("list deploy keys error: %w", err) return false, fmt.Errorf("failed to list deploy keys, error: %w", err)
} }
if resp.StatusCode >= 300 { if resp.StatusCode >= 300 {
return false, fmt.Errorf("list deploy keys failed with status code: %s", resp.Status) return false, fmt.Errorf("failed to list deploy keys (status code: %s)", resp.Status)
} }
// check if the key exists // check if the key exists
...@@ -152,10 +152,10 @@ func (p *GithubProvider) AddDeployKey(ctx context.Context, r *Repository, key, k ...@@ -152,10 +152,10 @@ func (p *GithubProvider) AddDeployKey(ctx context.Context, r *Repository, key, k
if existingKey != nil { if existingKey != nil {
resp, err := gh.Repositories.DeleteKey(ctx, r.Owner, r.Name, *existingKey.ID) resp, err := gh.Repositories.DeleteKey(ctx, r.Owner, r.Name, *existingKey.ID)
if err != nil { if err != nil {
return false, fmt.Errorf("delete deploy key error: %w", err) return false, fmt.Errorf("failed to delete deploy key '%s', error: %w", keyName, err)
} }
if resp.StatusCode >= 300 { if resp.StatusCode >= 300 {
return false, fmt.Errorf("delete deploy key failed with status code: %s", resp.Status) return false, fmt.Errorf("failed to delete deploy key '%s' (status code: %s)", keyName, resp.Status)
} }
} }
...@@ -168,7 +168,7 @@ func (p *GithubProvider) AddDeployKey(ctx context.Context, r *Repository, key, k ...@@ -168,7 +168,7 @@ func (p *GithubProvider) AddDeployKey(ctx context.Context, r *Repository, key, k
ReadOnly: &isReadOnly, ReadOnly: &isReadOnly,
}) })
if err != nil { if err != nil {
return false, fmt.Errorf("create deploy key error: %w", err) return false, fmt.Errorf("failed to create deploy key '%s', error: %w", keyName, err)
} }
return true, nil return true, nil
} }
......
...@@ -59,7 +59,7 @@ func (p *GitLabProvider) CreateRepository(ctx context.Context, r *Repository) (b ...@@ -59,7 +59,7 @@ func (p *GitLabProvider) CreateRepository(ctx context.Context, r *Repository) (b
if !p.IsPersonal { if !p.IsPersonal {
groups, _, err := gl.Groups.ListGroups(&gitlab.ListGroupsOptions{Search: gitlab.String(r.Owner)}, gitlab.WithContext(ctx)) groups, _, err := gl.Groups.ListGroups(&gitlab.ListGroupsOptions{Search: gitlab.String(r.Owner)}, gitlab.WithContext(ctx))
if err != nil { if err != nil {
return false, fmt.Errorf("list groups error: %w", err) return false, fmt.Errorf("failed to list groups, error: %w", err)
} }
if len(groups) > 0 { if len(groups) > 0 {
...@@ -74,7 +74,7 @@ func (p *GitLabProvider) CreateRepository(ctx context.Context, r *Repository) (b ...@@ -74,7 +74,7 @@ func (p *GitLabProvider) CreateRepository(ctx context.Context, r *Repository) (b
projects, _, err := gl.Projects.ListProjects(&gitlab.ListProjectsOptions{Search: gitlab.String(r.Name)}, gitlab.WithContext(ctx)) projects, _, err := gl.Projects.ListProjects(&gitlab.ListProjectsOptions{Search: gitlab.String(r.Name)}, gitlab.WithContext(ctx))
if err != nil { if err != nil {
return false, fmt.Errorf("list projects error: %w", err) return false, fmt.Errorf("failed to list projects, error: %w", err)
} }
if len(projects) == 0 { if len(projects) == 0 {
...@@ -87,7 +87,7 @@ func (p *GitLabProvider) CreateRepository(ctx context.Context, r *Repository) (b ...@@ -87,7 +87,7 @@ func (p *GitLabProvider) CreateRepository(ctx context.Context, r *Repository) (b
_, _, err := gl.Projects.CreateProject(p) _, _, err := gl.Projects.CreateProject(p)
if err != nil { if err != nil {
return false, fmt.Errorf("create project error: %w", err) return false, fmt.Errorf("failed to create project, error: %w", err)
} }
return true, nil return true, nil
} }
...@@ -111,7 +111,7 @@ func (p *GitLabProvider) AddDeployKey(ctx context.Context, r *Repository, key, k ...@@ -111,7 +111,7 @@ func (p *GitLabProvider) AddDeployKey(ctx context.Context, r *Repository, key, k
var projId int var projId int
projects, _, err := gl.Projects.ListProjects(&gitlab.ListProjectsOptions{Search: gitlab.String(r.Name)}, gitlab.WithContext(ctx)) projects, _, err := gl.Projects.ListProjects(&gitlab.ListProjectsOptions{Search: gitlab.String(r.Name)}, gitlab.WithContext(ctx))
if err != nil { if err != nil {
return false, fmt.Errorf("list projects error: %w", err) return false, fmt.Errorf("failed to list projects, error: %w", err)
} }
if len(projects) > 0 { if len(projects) > 0 {
projId = projects[0].ID projId = projects[0].ID
...@@ -122,7 +122,7 @@ func (p *GitLabProvider) AddDeployKey(ctx context.Context, r *Repository, key, k ...@@ -122,7 +122,7 @@ func (p *GitLabProvider) AddDeployKey(ctx context.Context, r *Repository, key, k
// check if the key exists // check if the key exists
keys, _, err := gl.DeployKeys.ListProjectDeployKeys(projId, &gitlab.ListProjectDeployKeysOptions{}) keys, _, err := gl.DeployKeys.ListProjectDeployKeys(projId, &gitlab.ListProjectDeployKeysOptions{})
if err != nil { if err != nil {
return false, fmt.Errorf("list keys error: %w", err) return false, fmt.Errorf("failed to list deploy keys, error: %w", err)
} }
shouldCreateKey := true shouldCreateKey := true
...@@ -142,7 +142,7 @@ func (p *GitLabProvider) AddDeployKey(ctx context.Context, r *Repository, key, k ...@@ -142,7 +142,7 @@ func (p *GitLabProvider) AddDeployKey(ctx context.Context, r *Repository, key, k
if existingKey != nil { if existingKey != nil {
_, err := gl.DeployKeys.DeleteDeployKey(projId, existingKey.ID, gitlab.WithContext(ctx)) _, err := gl.DeployKeys.DeleteDeployKey(projId, existingKey.ID, gitlab.WithContext(ctx))
if err != nil { if err != nil {
return false, fmt.Errorf("delete key error: %w", err) return false, fmt.Errorf("failed to delete deploy key '%s', error: %w", keyName, err)
} }
} }
...@@ -154,7 +154,7 @@ func (p *GitLabProvider) AddDeployKey(ctx context.Context, r *Repository, key, k ...@@ -154,7 +154,7 @@ func (p *GitLabProvider) AddDeployKey(ctx context.Context, r *Repository, key, k
CanPush: gitlab.Bool(false), CanPush: gitlab.Bool(false),
}, gitlab.WithContext(ctx)) }, gitlab.WithContext(ctx))
if err != nil { if err != nil {
return false, fmt.Errorf("add key error: %w", err) return false, fmt.Errorf("failed to create deploy key '%s', error: %w", keyName, err)
} }
return true, nil return true, nil
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment