Skip to content

Commit 39ad4b4

Browse files
Fix user env variables for GitLab repos in subgroups
This allows projects like 'foo/bar/baz' where 'foo/bar' is the owner and 'baz' the user.
1 parent e3cc972 commit 39ad4b4

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

components/dashboard/src/components/user-env-vars.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ class UserEnvVarComponent extends React.Component<UserEnvVarComponentProps, User
206206
return 'Must not be empty.';
207207
}
208208
const split = pattern.split('/');
209-
if (split.length !== 2) {
209+
if (split.length < 2) {
210210
return "Please use the form 'organization/repo'.";
211211
}
212212
for (const name of split) {

components/gitpod-protocol/src/protocol.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,13 +149,12 @@ export interface UserEnvVar extends UserEnvVarValue {
149149
export namespace UserEnvVar {
150150

151151
export function normalizeRepoPattern(pattern: string) {
152-
const [owner, repo] = pattern.split('/');
153-
return `${owner.toLocaleLowerCase()}/${repo.toLocaleLowerCase()}`;
152+
return pattern.toLocaleLowerCase();
154153
}
155154

156155
export function filter<T extends UserEnvVarValue>(vars: T[], owner: string, repo: string): T[] {
157156
let result = vars.filter(e => {
158-
const [ownerPattern, repoPattern] = e.repositoryPattern.split('/');
157+
const [ownerPattern, repoPattern] = splitRepositoryPattern(e.repositoryPattern);
159158
if (ownerPattern !== '*' && ownerPattern !== '#' && (!!owner && ownerPattern !== owner.toLocaleLowerCase())) {
160159
return false;
161160
}
@@ -195,7 +194,7 @@ export namespace UserEnvVar {
195194
// */* = 3
196195
// #/# = 4 (used for env vars passed through the URL)
197196
// the lower the score, the higher the precedence.
198-
const [ownerPattern, repoPattern] = e.repositoryPattern.split('/');
197+
const [ownerPattern, repoPattern] = splitRepositoryPattern(e.repositoryPattern);
199198
let score = 0;
200199
if (repoPattern == "*") {
201200
score += 1;
@@ -217,6 +216,13 @@ export namespace UserEnvVar {
217216

218217
return result;
219218
}
219+
220+
function splitRepositoryPattern(repositoryPattern: string): string[] {
221+
const patterns = repositoryPattern.split('/');
222+
const repoPattern = patterns.pop() || "";
223+
const ownerPattern = patterns.join('/');
224+
return [ownerPattern, repoPattern];
225+
}
220226
}
221227

222228
export interface GitpodToken {

0 commit comments

Comments
 (0)