private void InitializeRepositoryMetadata(string repositoryUrl, string repositoryType)
        {
            RepositoryType = RepositoryKind.Unknown;

            if (Uri.TryCreate(repositoryUrl, UriKind.Absolute, out var repoUri))
            {
                if (repoUri.IsHttpsProtocol())
                {
                    RepositoryUrl = repositoryUrl;
                }

                if (repoUri.IsGitHubUri())
                {
                    RepositoryType = RepositoryKind.GitHub;

                    // Fix-up git:// to https:// for GitHub URLs (we should add this fix-up to other repos in the future)
                    if (repoUri.IsGitProtocol())
                    {
                        RepositoryUrl = repoUri.ToHttps().ToString();
                    }
                }
                else if (PackageHelper.IsGitRepositoryType(repositoryType))
                {
                    RepositoryType = RepositoryKind.Git;
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Validate repository metadata:
        /// 1. If the type is "git" - allow the URL scheme "git://" or "https://". We will translate "git://" to "https://" at display time for known domains.
        /// 2. For types other then "git" - URL scheme should be "https://"
        /// </summary>
        private PackageValidationResult CheckRepositoryMetadata(PackageMetadata packageMetadata, List <IValidationMessage> warnings)
        {
            if (packageMetadata.RepositoryUrl == null)
            {
                return(null);
            }

            // git repository type
            if (PackageHelper.IsGitRepositoryType(packageMetadata.RepositoryType))
            {
                if (!packageMetadata.RepositoryUrl.IsGitProtocol() && !packageMetadata.RepositoryUrl.IsHttpsProtocol())
                {
                    warnings.Add(new PlainTextOnlyValidationMessage(Strings.WarningNotHttpsOrGitRepositoryUrlScheme));
                }
            }
            else
            {
                if (!packageMetadata.RepositoryUrl.IsHttpsProtocol())
                {
                    warnings.Add(new PlainTextOnlyValidationMessage(Strings.WarningNotHttpsRepositoryUrlScheme));
                }
            }

            return(null);
        }