drone/go-scm

Namespace in GitLab is wrong

odg0318 opened this issue · 0 comments

Hello. I have an issue in GitLab repository.

Some repositories in my GitLab belong to sub-group, such as foo/bar/baz/sample.
In this case, sample is project name and foo/bar/baz is namespace in my opinion.
But actually only baz is parsed as namespace via this code.

Related codes are below.
https://github.com/drone/go-scm/blob/master/scm/driver/gitlab/repo.go#L172

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,
		Perm: &scm.Perm{
			Pull:  true,
			Push:  canPush(from),
			Admin: canAdmin(from),
		},
	}
	if to.Namespace == "" {
		if parts := strings.SplitN(from.PathNamespace, "/", 2); len(parts) == 2 {
			to.Namespace = parts[1]
		}
	}
	return to
}

As I know, Drone also uses this drone/scm project to communicate various kinds of repositories. And the above issue makes some errors to sync GitLab repository.

GitLab response of foo/bar/baz/sample project is as below.

[
  {
    "id": 1000,
    "name": "sample",
    "path": "sample",
    "path_with_namespace": "foo/bar/baz/sample",
    "namespace": {
      "id": 256,
      "name": "baz",
      "path": "baz",
      "kind": "group",
      "full_path": "foo/bar/baz",
      "parent_id": 14
    },

I suggest that namespace.full_path is used as namespace property.

Reference: https://discourse.drone.io/t/drone-cannot-parse-sub-group-project-path/6361