Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[gitlab] Accept '#' sign in branches / context URLs #5362

Merged
merged 1 commit into from
Sep 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions components/server/src/gitlab/gitlab-context-parser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,66 @@ class TestGitlabContextParser {
})
}

@test public async testTreeContextBranchWithHashSign01() {
corneliusludmann marked this conversation as resolved.
Show resolved Hide resolved
const result = await this.parser.handle({}, this.user, 'https://gitlab.com/gp-test-group/gp-test-project/-/tree/feature/%23123-issue');
expect(result).to.deep.include({
"ref": "feature/#123-issue",
"refType": "branch",
"path": "",
"revision": "8b389233c0a3a55a5cd75f89d2c96761420bf2c8",
"isFile": false,
"repository": {
"host": "gitlab.com",
"owner": "gp-test-group",
"name": "gp-test-project",
"cloneUrl": "https://gitlab.com/gp-test-group/gp-test-project.git",
"defaultBranch": "master",
"private": false
},
"title": "gp-test-group/gp-test-project - feature/#123-issue"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: Shall we move this group under gitpod-io group?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I definitely would love it if we would create proper repos for all these (and the GH) tests under the gitpod-io group. For the sake of MVP what do you think of creating an issue for that?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I definitely would love it if we would create proper repos for all these (and the GH) tests under the gitpod-io group. For the sake of MVP what do you think of creating an issue for that?

💯 x 💯

})
}

@test public async testTreeContextBranchWithHashSign02() {
const result = await this.parser.handle({}, this.user, 'https://gitlab.com/gp-test-group/gp-test-project/-/tree/issue-%23123');
expect(result).to.deep.include({
"ref": "issue-#123",
"refType": "branch",
"path": "",
"revision": "8b389233c0a3a55a5cd75f89d2c96761420bf2c8",
"isFile": false,
"repository": {
"host": "gitlab.com",
"owner": "gp-test-group",
"name": "gp-test-project",
"cloneUrl": "https://gitlab.com/gp-test-group/gp-test-project.git",
"defaultBranch": "master",
"private": false
},
"title": "gp-test-group/gp-test-project - issue-#123"
})
}

@test public async testTreeContextBranchWithAndSign() {
const result = await this.parser.handle({}, this.user, 'https://gitlab.com/gp-test-group/gp-test-project/-/tree/another&branch');
expect(result).to.deep.include({
"ref": "another&branch",
"refType": "branch",
"path": "",
"revision": "8b389233c0a3a55a5cd75f89d2c96761420bf2c8",
"isFile": false,
"repository": {
"host": "gitlab.com",
"owner": "gp-test-group",
"name": "gp-test-project",
"cloneUrl": "https://gitlab.com/gp-test-group/gp-test-project.git",
"defaultBranch": "master",
"private": false
},
"title": "gp-test-group/gp-test-project - another&branch"
})
}

@test public async testEmptyProject() {
const result = await this.parser.handle({}, this.user, 'https://gitlab.com/gp-test-group/gp-test-empty-project');
expect(result).to.deep.include({
Expand Down
4 changes: 3 additions & 1 deletion components/server/src/gitlab/gitlab-context-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ export class GitlabContextParser extends AbstractContextParser implements IConte
public async parseURL(user: User, contextUrl: string): Promise<URLParts> {
var { host, owner, repoName, moreSegments, searchParams } = await super.parseURL(user, contextUrl);
// TODO: we remove the /-/ in the path in the next line as quick fix for #3809 -- improve this in the long term
const segments = [owner, repoName, ...moreSegments.filter(s => s !== '-')];
const segments = [owner, repoName, ...moreSegments.filter(s => s !== '-')]
// Replace URL encoded '#' sign. Don't use decodeURI() because GitLab seems to be inconsistent in what needs to be decoded and what not.
.map(x => x.replace(/%23/g, '#'));
var moreSegmentsStart: number = 2;
/*
We cannot deduce the namespace (aka `owner`) and project name (aka `repoName`) from the URI with certainty.
Expand Down