Skip to content

Commit

Permalink
check repo access level for private repos
Browse files Browse the repository at this point in the history
Signed-off-by: Raghav Kaul <[email protected]>
  • Loading branch information
raghavkaul committed Jun 23, 2023
1 parent 02f10b7 commit 9b07a8e
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions clients/gitlabrepo/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,20 @@ type Client struct {
commitDepth int
}

var errRepoAccess = errors.New("repo inaccessible")

// raise an error if repository access level isn't public.
func checkRepoAccessible(repo *gitlab.Project) error {
if (repo.RepositoryAccessLevel != gitlab.PublicAccessControl) &&
(repo.RepositoryAccessLevel != gitlab.EnabledAccessControl) {
return fmt.Errorf("%w: %s access level %s",
errRepoAccess, repo.PathWithNamespace, string(repo.RepositoryAccessLevel),
)
}

return nil
}

// InitRepo sets up the GitLab project in local storage for improving performance and GitLab token usage efficiency.
func (client *Client) InitRepo(inputRepo clients.Repo, commitSHA string, commitDepth int) error {
glRepo, ok := inputRepo.(*repoURL)
Expand All @@ -71,6 +85,11 @@ func (client *Client) InitRepo(inputRepo clients.Repo, commitSHA string, commitD
if err != nil {
return sce.WithMessage(sce.ErrRepoUnreachable, proj+"\t"+err.Error())
}

if err = checkRepoAccessible(repo); err != nil {
return sce.WithMessage(sce.ErrRepoUnreachable, err.Error())
}

if commitDepth <= 0 {
client.commitDepth = 30 // default
} else {
Expand Down

0 comments on commit 9b07a8e

Please sign in to comment.