Skip to content

Commit 0e36d43

Browse files
authored
Gitlab: Fix private repo discovery (#78)
The `Public` attribute from go-gitlab is not configured correctly, so we simply use the `Visibility` attribute.
1 parent d8c1598 commit 0e36d43

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

repositories.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ func getRepositories(client interface{},
152152
} else {
153153
cloneURL = repo.SSHURLToRepo
154154
}
155-
repositories = append(repositories, &Repository{CloneURL: cloneURL, Name: repo.Name, Namespace: namespace, Private: repo.Public})
155+
repositories = append(repositories, &Repository{CloneURL: cloneURL, Name: repo.Name, Namespace: namespace, Private: repo.Visibility == "private"})
156156
}
157157
if resp.NextPage == 0 {
158158
break

repositories_test.go

+26
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,32 @@ func TestGetGitLabRepositories(t *testing.T) {
138138
}
139139
}
140140

141+
func TestGetGitLabPrivateRepositories(t *testing.T) {
142+
setup()
143+
defer teardown()
144+
145+
mux.HandleFunc("/api/v4/projects", func(w http.ResponseWriter,
146+
r *http.Request) {
147+
fmt.Fprint(w, `[{"path_with_namespace": "test/r1",
148+
"id":1, "ssh_url_to_repo": "https://gitlab.com/u/r1", "name": "r1",
149+
"visibility": "private"}]`)
150+
})
151+
152+
repos, err := getRepositories(GitLabClient, "gitlab",
153+
"private", "", "", false)
154+
if err != nil {
155+
t.Fatalf("%v", err)
156+
}
157+
var expected []*Repository
158+
expected = append(expected, &Repository{Namespace: "test",
159+
CloneURL: "https://gitlab.com/u/r1", Name: "r1", Private: true})
160+
if !reflect.DeepEqual(repos, expected) {
161+
for i := 0; i < len(repos); i++ {
162+
t.Errorf("Expected %+v, Got %+v", expected[i], repos[i])
163+
}
164+
}
165+
}
166+
141167
func TestGetStarredGitLabRepositories(t *testing.T) {
142168
setup()
143169
defer teardown()

0 commit comments

Comments
 (0)