kubero-dev / kubero-dev/kubero

GitLab integration fails for repositories in nested groups/subgroups

Open Beginner friendly
#728 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
TypeScript
Stars
4.4k
Forks
213
PR merge metrics
No merged PRs in 30d

Description

### Description

GitLab repository connection fails with a 404 error when the repository is located in a nested group structure
(e.g., owner/subgroup/repo).

### Steps to Reproduce

1. Configure Kubero with GitLab credentials (GITLAB_PERSONAL_ACCESS_TOKEN and GITLAB_BASEURL)
2. Try to connect a repository located in a nested group, e.g.,

3. Click "Connect" in the pipeline configuration
4. Observe 404 error in logs

### Expected Behavior

Repository should connect successfully, as the GitLab API token has proper access to the repository.

### Actual Behavior

Connection fails with:
HTTPError: Response code 404 (Not Found)
TypeError: Cannot set properties of undefined (setting 'admin') at GitlabApi.getRepository
(/app/server/repo/git/gitlab.js:53:31)

### Root Cause

In server/src/repo/git/gitlab.ts around line 53, the code parses the git URL and constructs the API path as:

```typescript
const parsed = gitUrlParse(gitrepo);
const repo = parsed.name;
const owner = parsed.owner;

const res: any = await this.gitlab
.get(`projects/${owner}%2F${repo}`)
```

For a repository like `owner/subgroup/repo`, `gitUrlParse` extracts:

- owner = `owner`
- repo = `repo`

This constructs the API call: `projects/owner%2Frepo` (404)

But the correct API path should be: `projects/owner%2Fsubgroup%2Frepo`

### Proposed Solution

Instead of using `owner` and `repo` separately, extract the full project path from the parsed URL:

```typescript
const parsed = gitUrlParse(gitrepo);
// For gitlab.com/owner/subgroup/repo.git
// parsed.pathname = "/owner/subgroup/repo.git"
const projectPath = parsed.pathname.replace(/^\//, '').replace(/\.git$/, '');
const encodedPath = encodeURIComponent(projectPath);

const res: any = await this.gitlab
.get(`projects/${encodedPath}`)
```

Or alternatively, use `parsed.full_name` if the `gitUrlParse` library provides it.

Environment:

- Kubero version: latest (ghcr.io/kubero-dev/kubero/kubero:latest)
- GitLab: gitlab.com (SaaS)

### Verification

Manual API test confirms the issue:

#### What Kubero calls (404)

```bash
curl -H "PRIVATE-TOKEN: $TOKEN" ""
```

#### What should be called (200)

```bash
curl -H "PRIVATE-TOKEN: $TOKEN" ""
```

Contributor guide

Open the contributing guide

Research direction

Start in server/src/repo/git/gitlab.ts around line 53 and inspect how gitUrlParse provides the project path before the GitLab projects API request. Verify a nested path such as owner/subgroup/repo is encoded in the request and that connecting the repository succeeds, using the curl examples in the issue for API-level verification.

Written by the indexing model from the issue text.

Assessment

Tech stack
git, typescript
Domain
api, backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.