Skip to content

Commit 35ce827

Browse files
fix(gitlab): repo visibility
1 parent 2c3c75d commit 35ce827

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

pkg/semrel/github.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ func NewGithubRepository(ctx context.Context, gheHost, slug, token string) (*Git
2424
return nil, errors.New("invalid slug")
2525
}
2626
repo := new(GithubRepository)
27-
splited := strings.Split(slug, "/")
28-
repo.owner = splited[0]
29-
repo.repo = splited[1]
27+
split := strings.Split(slug, "/")
28+
repo.owner = split[0]
29+
repo.repo = split[1]
3030
repo.Ctx = ctx
3131
oauthClient := oauth2.NewClient(ctx, oauth2.StaticTokenSource(&oauth2.Token{AccessToken: token}))
3232
if gheHost != "" {

pkg/semrel/gitlab.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,20 @@ type GitlabRepository struct {
2020
}
2121

2222
func NewGitlabRepository(ctx context.Context, gitlabBaseUrl, slug, token, branch string, projectID string) (*GitlabRepository, error) {
23-
repo := new(GitlabRepository)
24-
repo.Ctx = ctx
25-
repo.branch = branch
26-
2723
if projectID == "" {
2824
return nil, fmt.Errorf("project id is required")
2925
}
3026

27+
repo := new(GitlabRepository)
3128
repo.projectID = projectID
29+
repo.Ctx = ctx
30+
repo.branch = branch
31+
32+
if strings.Contains(slug, "/") {
33+
split := strings.Split(slug, "/")
34+
repo.owner = split[0]
35+
repo.repo = split[1]
36+
}
3237

3338
var (
3439
client *gitlab.Client
@@ -57,7 +62,7 @@ func (repo *GitlabRepository) GetInfo() (string, bool, error) {
5762
return "", false, err
5863
}
5964

60-
return project.DefaultBranch, !project.Public, nil
65+
return project.DefaultBranch, project.Visibility == gitlab.PrivateVisibility, nil
6166
}
6267

6368
func (repo *GitlabRepository) GetCommits(sha string) ([]*Commit, error) {

pkg/semrel/gitlab_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func TestNewGitlabRepository(t *testing.T) {
2020
t.Fatal("invalid initialization")
2121
}
2222
repo, err = NewGitlabRepository(context.TODO(), "", "owner/test-repo", "token", "", "1")
23-
if repo == nil || err != nil {
23+
if repo == nil || err != nil || repo.Owner() != "owner" || repo.Repo() != "test-repo" {
2424
t.Fatal("invalid initialization")
2525
}
2626
repo, err = NewGitlabRepository(context.TODO(), "https://mygitlab.com", "owner/test-repo", "token", "", "1")
@@ -40,10 +40,9 @@ func createGitlabTag(name, sha string) *gitlab.Tag {
4040
}
4141

4242
var (
43-
GITLAB_REPO_PRIVATE = true
4443
GITLAB_PROJECT_ID = 12324322
4544
GITLAB_DEFAULTBRANCH = "master"
46-
GITLAB_PROJECT = gitlab.Project{DefaultBranch: GITLAB_DEFAULTBRANCH, Public: !GITLAB_REPO_PRIVATE, ID: GITLAB_PROJECT_ID}
45+
GITLAB_PROJECT = gitlab.Project{DefaultBranch: GITLAB_DEFAULTBRANCH, Visibility: gitlab.PrivateVisibility, ID: GITLAB_PROJECT_ID}
4746
GITLAB_COMMITS = []*gitlab.Commit{
4847
createGitlabCommit("abcd", "feat(app): new feature"),
4948
createGitlabCommit("dcba", "Fix: bug"),

0 commit comments

Comments
 (0)