Skip to content

Download schema file fails when the organization has only one project #621

@lordkiwiz

Description

@lordkiwiz

I'm experincing an error when automatically downloading the custom schema file.

(3/13/2025, 1:23:46 PM) [SchemaDetection] Detecting schema for workspace folder <foldername>
(3/13/2025, 1:23:46 PM) [SchemaDetection] Getting session for tenant default
(3/13/2025, 1:23:49 PM) [SchemaDetection] Retrieved session: <session id>
(3/13/2025, 1:23:51 PM) [SchemaDetection] Found remote URL for TeamCloud: https://dev.azure.com/organization/_git/repo
(3/13/2025, 1:23:51 PM) [SchemaDetection] repo is an Azure repo
(3/13/2025, 1:23:51 PM) [SchemaDetection] Error auto-detecting schema for workspace folder <foldername>: Error: Failed to determine Azure Repo details from remote url. Please ensure that the remote points to a valid 
Azure Repos url.

This issue occurs when you only have one project in your devops organization.
To determine the schema file url, the extension uses the function autoDetectSchema on line 114 in the file src/schema-association-service.ts. In the function on line 157 it calls the helper function getRepositoryDetailsFromRemoteUrl in the file src/helpers/azureDevOpsHelper.ts to determine the organization name. Below is you can see the part of the function handeling azure devops.

if (remoteUrl.includes(AzureReposUrl)) {
    const part = remoteUrl.substring(remoteUrl.indexOf(AzureReposUrl) + AzureReposUrl.length);
    const parts = part.split('/');
    if (parts.length !== 4) {
        throw new Error(Messages.failedToDetermineAzureRepoDetails);
    }

    return {
        organizationName: parts[0].trim(),
        projectName: parts[1].trim(),
        repositoryName: parts[3].trim()
    }
};

The function assumes that remote url is formatted like https://dev.azure.com/{organization}/{project}/_git/{reponame}.
However, if the devops organization only contains one porject, the repo url is returned in the format https://dev.azure.com/{organization}/_git/{reponame}, resulting in a parts.length == 3 and an error.
This means that anytime the devops project has only one project, the function will return an error.

I haven't tested anything, but maybe we can change the function to somthing like to prevent this issue:

if (remoteUrl.includes(AzureReposUrl)) {
   const part = remoteUrl.substring(remoteUrl.indexOf(AzureReposUrl) + AzureReposUrl.length);
   const parts = part.split('/');
   if (parts.length == 4) {
       return {
           organizationName: parts[0].trim(),
           projectName: parts[1].trim(),
           repositoryName: parts[3].trim()
       }
   } else if(parts.length == 3) {
       return {
           organizationName: parts[0].trim(),
           // Return empty project name, because the name isn't present in the url anyway.
           projectName: "",
           repositoryName: parts[2].trim()
       }
   } else {
       throw new Error(Messages.failedToDetermineAzureRepoDetails);
   }
};

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions