internal static bool TryParseEnterpriseUrl(string relativeUrl, out string relativeBaseUrl, out string projectName, out string repositoryName)
        {
            // HTTP: {baseUrl}/scm/{projectName}/{repositoryName}
            // SSH: {baseUrl}/{projectName}/{repositoryName}

            if (!UriUtilities.TrySplitRelativeUrl(relativeUrl, out var parts) || parts.Length < 2)
            {
                relativeBaseUrl = projectName = repositoryName = null;
                return(false);
            }

            var i = parts.Length - 1;

            repositoryName = parts[i--];
            projectName    = parts[i--];

            if (i >= 0 && parts[i] == "scm")
            {
                i--;
            }

            Debug.Assert(i >= -1);
            relativeBaseUrl = string.Join("/", parts, 0, i + 1);
            return(true);
        }
Esempio n. 2
0
        public static bool TryParseOnPremHttp(string relativeUrl, string virtualDirectory, out string projectPath, out string repositoryName)
        {
            projectPath = repositoryName = null;

            if (!UriUtilities.TrySplitRelativeUrl(relativeUrl, out var parts) || parts.Length == 0 ||
                !UriUtilities.TrySplitRelativeUrl(virtualDirectory, out var virtualDirectoryParts))
            {
                return(false);
            }

            // skip virtual directory:
            if (!parts.Take(virtualDirectoryParts.Length).SequenceEqual(virtualDirectoryParts, StringComparer.OrdinalIgnoreCase))
            {
                return(false);
            }

            // collection:
            int i          = virtualDirectoryParts.Length;
            var collection = parts[i++];

            if (!TryParsePath(parts, i, "_git", out var projectName, out _, out repositoryName))
            {
                return(false);
            }

            projectPath = string.Join("/", parts, 0, virtualDirectoryParts.Length) + "/" + collection + "/" + (projectName ?? repositoryName);
            return(true);
        }
Esempio n. 3
0
        public static bool TryParseHostedHttp(string host, string relativeUrl, [NotNullWhen(true)] out string?projectPath, [NotNullWhen(true)] out string?repositoryName)
        {
            projectPath = repositoryName = null;

            if (!UriUtilities.TrySplitRelativeUrl(relativeUrl, out var parts) || parts.Length == 0)
            {
                return(false);
            }

            int    index = 0;
            string?account;
            bool   isVisualStudioHost = IsVisualStudioHostedServer(host);

            if (isVisualStudioHost)
            {
                // account is stored in the domain, not in the path:
                account = null;

                // Trim optional "DefaultCollection" from path:
                if (StringComparer.OrdinalIgnoreCase.Equals(parts[index], "DefaultCollection"))
                {
                    index++;
                }
            }
            else
            {
                // Check this is not an 'enterprise' discovery page URL
                if (StringComparer.OrdinalIgnoreCase.Equals(parts[0], "e"))
                {
                    return(false);
                }

                // Account is first part of path:
                account = parts[index++];
            }

            if (index == parts.Length)
            {
                return(false);
            }

            if (!TryParsePath(parts, index, "_git", out var projectName, out var teamName, out repositoryName))
            {
                return(false);
            }

            projectPath = projectName ?? repositoryName;

            if (!isVisualStudioHost)
            {
                if (teamName != null)
                {
                    return(false);
                }

                projectPath = account + "/" + projectPath;
            }

            return(true);
        }
Esempio n. 4
0
        public void TrySplitRelativeUrl(string url, string[] parts)
        {
            if (!UriUtilities.TrySplitRelativeUrl(url, out var actualParts))
            {
                actualParts = null;
            }

            AssertEx.Equal(parts, actualParts);
        }
Esempio n. 5
0
        public static bool TryParseHostedSsh(Uri uri, out string account, out string repositoryPath, out string repositoryName)
        {
            Debug.Assert(uri != null);

            account = repositoryPath = repositoryName = null;

            // {"DefaultCollection"|""}/{repositoryPath}/"_ssh"/{"_full"|"_optimized"}/{repositoryName}
            if (!UriUtilities.TrySplitRelativeUrl(uri.GetPath(), out var parts) || parts.Length == 0)
            {
                return(false);
            }

            // Check for v3 url format
            if (parts[0] == "v3" &&
                parts.Length >= 3 &&
                TryParsePath(parts, 2, type: null, out repositoryPath, out repositoryName) &&
                repositoryPath != "")
            {
                // ssh://{user}@{domain}:{port}/v3/{account}/{repositoryPath}/{'_full'|'_optimized'|''}/{repositoryName}
                account = parts[1];
            }
            else
            {
                // ssh v1/v2 url formats
                // ssh://{account}@vs-ssh.visualstudio.com/

                account = uri.UserInfo;

                int index = 0;
                if (StringComparer.OrdinalIgnoreCase.Equals(parts[0], "DefaultCollection"))
                {
                    index++;
                }

                if (!TryParsePath(parts, index, "_ssh", out repositoryPath, out repositoryName))
                {
                    // Failed to parse path
                    return(false);
                }
            }

            if (account.Length == 0)
            {
                return(false);
            }

            return(true);
        }
Esempio n. 6
0
        public static bool TryParseOnPremSsh(Uri uri, out string repositoryPath, out string repositoryName)
        {
            repositoryPath = repositoryName = null;

            if (!UriUtilities.TrySplitRelativeUrl(uri.GetPath(), out var parts))
            {
                return(false);
            }

            if (!TryParseRepositoryName(parts, out int teamNameIndex, "_ssh", out repositoryName))
            {
                return(false);
            }

            repositoryPath = string.Join("/", parts, 0, teamNameIndex + 1);
            return(true);
        }
Esempio n. 7
0
 public void TrySplitRelativeUrl(string url, string[]?parts)
 {
     if (!UriUtilities.TrySplitRelativeUrl(url, out string[]? actualParts))