Skip to content

Commit

Permalink
Add project context supports
Browse files Browse the repository at this point in the history
  • Loading branch information
mustard-mh committed Sep 27, 2024
1 parent 8a0e87f commit e621899
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 19 deletions.
19 changes: 19 additions & 0 deletions components/server/src/azure-devops/azure-context-parser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,25 @@ class TestAzureDevOpsContextParser {
});
}

@test public async testEmptyProjectWithoutGitSegment() {
const result = await this.parser.handle({}, this.user, "https://dev.azure.com/services-azure/empty-project");
expect(result).to.deep.include({
path: "",
isFile: false,
title: "empty-project/empty-project",
repository: {
host: "dev.azure.com",
owner: "services-azure/empty-project",
name: "empty-project",
cloneUrl: "https://[email protected]/services-azure/empty-project/_git/empty-project",
description: "main",
webUrl: "https://dev.azure.com/services-azure/empty-project/_git/empty-project",
defaultBranch: "main",
},
revision: "",
});
}

@test public async testDefault() {
const result = await this.parser.handle(
{},
Expand Down
42 changes: 23 additions & 19 deletions components/server/src/azure-devops/azure-context-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,31 +113,35 @@ export class AzureDevOpsContextParser extends AbstractContextParser implements I
const pathname = url.pathname.replace(/^\//, "").replace(/\/$/, "");
const segments = pathname.split("/").filter((e) => e !== "");
const host = this.host;
// case when there is only one repository in the project
// https://dev.azure.com/services-azure/_git/project2
if (segments.length === 3 && segments[1] === "_git") {
const azOrganization = segments[0];
const azProject = segments[2];
const repo = azProject;
return {
host,
owner: `${azOrganization}/${azProject}`,
repoName: repo,
moreSegments: segments.slice(3),
searchParams: url.searchParams,
};
}
if (segments.length < 4 || segments[2] !== "_git") {
let azOrganization = "";
let azProject = "";
let repo = "";
let moreSegments: string[] = [];
if (segments.length === 2) {
// https://dev.azure.com/services-azure/empty-project
azOrganization = segments[0];
azProject = segments[1];
repo = azProject;
} else if (segments.length === 3 && segments[1] === "_git") {
// https://dev.azure.com/services-azure/_git/project2
azOrganization = segments[0];
azProject = segments[2];
repo = azProject;
moreSegments = segments.slice(3);
} else if (segments.length < 4 || segments[2] !== "_git") {
// https://dev.azure.com/services-azure/project2/_git/project2
throw new ApplicationError(ErrorCodes.BAD_REQUEST, "Invalid Azure DevOps repository URL");
} else {
moreSegments = segments.slice(4);
azOrganization = segments[0];
azProject = segments[1];
repo = segments[3];
}
const azOrganization = segments[0];
const azProject = segments[1];
const repo = segments[3];
return {
host,
owner: `${azOrganization}/${azProject}`,
repoName: repo,
moreSegments: segments.slice(4),
moreSegments,
searchParams: url.searchParams,
};
}
Expand Down

0 comments on commit e621899

Please sign in to comment.