From 79951ad7a0d0b1989ea84d99be31fcb9320ae348 Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Thu, 17 Dec 2020 17:51:48 -0500 Subject: [PATCH] added gitlab visibility mapping --- scm/driver/gitlab/repo.go | 30 ++++++++++++++------ scm/driver/gitlab/testdata/repo.json.golden | 1 + scm/driver/gitlab/testdata/repos.json.golden | 1 + 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/scm/driver/gitlab/repo.go b/scm/driver/gitlab/repo.go index ed3152a25..4ed8b39e5 100644 --- a/scm/driver/gitlab/repo.go +++ b/scm/driver/gitlab/repo.go @@ -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), @@ -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: diff --git a/scm/driver/gitlab/testdata/repo.json.golden b/scm/driver/gitlab/testdata/repo.json.golden index 848432d5b..41c46c08d 100644 --- a/scm/driver/gitlab/testdata/repo.json.golden +++ b/scm/driver/gitlab/testdata/repo.json.golden @@ -9,6 +9,7 @@ }, "Branch": "master", "Private": false, + "Visibility": 1, "Clone": "https://gitlab.com/diaspora/diaspora.git", "CloneSSH": "git@gitlab.com:diaspora/diaspora.git", "Link": "https://gitlab.com/diaspora/diaspora", diff --git a/scm/driver/gitlab/testdata/repos.json.golden b/scm/driver/gitlab/testdata/repos.json.golden index 05ecebae6..5780a5ebd 100644 --- a/scm/driver/gitlab/testdata/repos.json.golden +++ b/scm/driver/gitlab/testdata/repos.json.golden @@ -10,6 +10,7 @@ }, "Branch": "master", "Private": false, + "Visibility": 1, "Clone": "https://gitlab.com/diaspora/diaspora.git", "CloneSSH": "git@gitlab.com:diaspora/diaspora.git", "Link": "https://gitlab.com/diaspora/diaspora",