Skip to content

Commit

Permalink
fix(gitlab): AddCollaborator tell when user is a member
Browse files Browse the repository at this point in the history
Fixing AddCollaborator to tell when a user is already a member:
- response 409 Conflict signals user having already been a member
GitLab doesn't implement the invite/accept workflow:
- successfully adding a member also reports it as being a member

Signed-off-by: Manuel Stein <[email protected]>
  • Loading branch information
manuelstein authored and msvticket committed Aug 31, 2023
1 parent ca0f320 commit 3bfe234
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion scm/driver/gitlab/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,15 @@ func (s *repositoryService) AddCollaborator(ctx context.Context, repo, username,
AccessLevel: stringToAccessLevel(permission),
}
res, err := s.client.do(ctx, "POST", path, in, &out)
if res.Status == 409 {
// GitLab returns 409 Conflict and message "Member already exists"
return false, true, res, err
}
if err != nil {
return false, false, res, err
}
return true, false, res, nil
// Return that user has become a member already (no invite/accept in GitLab)
return true, true, res, nil
}

func (s *repositoryService) IsCollaborator(ctx context.Context, repo, user string) (bool, *scm.Response, error) {
Expand Down

0 comments on commit 3bfe234

Please sign in to comment.