Skip to content

Commit

Permalink
added gitlab visibility mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
bradrydzewski committed Dec 17, 2020
1 parent 5141b8e commit 79951ad
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
30 changes: 22 additions & 8 deletions scm/driver/gitlab/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,14 +176,15 @@ func convertRepositoryList(from []*repository) []*scm.Repository {
// to the common repository structure.
func convertRepository(from *repository) *scm.Repository {
to := &scm.Repository{
ID: strconv.Itoa(from.ID),
Namespace: from.Namespace.Path,
Name: from.Path,
Branch: from.DefaultBranch,
Private: convertPrivate(from.Visibility),
Clone: from.HTTPURL,
CloneSSH: from.SSHURL,
Link: from.WebURL,
ID: strconv.Itoa(from.ID),
Namespace: from.Namespace.Path,
Name: from.Path,
Branch: from.DefaultBranch,
Private: convertPrivate(from.Visibility),
Visibility: convertVisibility(from.Visibility),
Clone: from.HTTPURL,
CloneSSH: from.SSHURL,
Link: from.WebURL,
Perm: &scm.Perm{
Pull: true,
Push: canPush(from),
Expand Down Expand Up @@ -308,6 +309,19 @@ func convertPrivate(from string) bool {
}
}

func convertVisibility(from string) scm.Visibility {
switch from {
case "public":
return scm.VisibilityPublic
case "private":
return scm.VisibilityPrivate
case "internal":
return scm.VisibilityInternal
default:
return scm.VisibilityUndefined
}
}

func canPush(proj *repository) bool {
switch {
case proj.Permissions.ProjectAccess.AccessLevel >= 30:
Expand Down
1 change: 1 addition & 0 deletions scm/driver/gitlab/testdata/repo.json.golden
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
},
"Branch": "master",
"Private": false,
"Visibility": 1,
"Clone": "https://gitlab.com/diaspora/diaspora.git",
"CloneSSH": "[email protected]:diaspora/diaspora.git",
"Link": "https://gitlab.com/diaspora/diaspora",
Expand Down
1 change: 1 addition & 0 deletions scm/driver/gitlab/testdata/repos.json.golden
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
},
"Branch": "master",
"Private": false,
"Visibility": 1,
"Clone": "https://gitlab.com/diaspora/diaspora.git",
"CloneSSH": "[email protected]:diaspora/diaspora.git",
"Link": "https://gitlab.com/diaspora/diaspora",
Expand Down

0 comments on commit 79951ad

Please sign in to comment.