示例#1
0
        private async Task <DateTime?> GetLastSignificantUpdateTime(
            IReadOnlyList <GitHubCommit> commits,
            Project project,
            string fileName,
            DateTime?lastKnownSignificantUpdateTime,
            DateTime documentCreationTime)
        {
            if (commits == null || !commits.Any())
            {
                return(null);
            }

            var fileCommitsAfterCreation = commits.Take(commits.Count - 1);

            var commitsToEvaluate = (lastKnownSignificantUpdateTime != null
                ? fileCommitsAfterCreation.Where(c => c.Commit.Author.Date.DateTime > lastKnownSignificantUpdateTime)
                : fileCommitsAfterCreation).Where(c => c.Commit.Author.Date.DateTime > DateTime.Now.AddDays(-14));

            foreach (var gitHubCommit in commitsToEvaluate)
            {
                var fullCommit = await _githubRepositoryManager.GetSingleCommitsAsync(
                    GetOwnerNameFromUrl(project.GetGitHubUrl()),
                    GetRepositoryNameFromUrl(project.GetGitHubUrl()),
                    gitHubCommit.Sha,
                    project.GetGitHubAccessTokenOrNull());

                if (_githubPatchAnalyzer.HasPatchSignificantChanges(fullCommit.Files.First(f => f.Filename == fileName).Patch))
                {
                    return(gitHubCommit.Commit.Author.Date.DateTime);
                }
            }

            return(null);
        }
示例#2
0
        public async Task <DocumentResource> GetResource(Project project, string resourceName, string languageCode, string version)
        {
            var rawRootUrl = CalculateRawRootUrlWithLanguageCode(project.GetGitHubUrl(version), languageCode);
            var content    = await DownloadWebContentAsByteArrayAsync(
                rawRootUrl + resourceName,
                project.GetGitHubAccessTokenOrNull(),
                project.GetGithubUserAgentOrNull()
                );

            return(new DocumentResource(content));
        }
示例#3
0
        private async Task <IReadOnlyList <GitHubCommit> > GetFileCommitsAsync(Project project, string version, string filename)
        {
            var url            = project.GetGitHubUrl();
            var ownerName      = GetOwnerNameFromUrl(url);
            var repositoryName = GetRepositoryNameFromUrl(url);

            return(await _githubRepositoryManager.GetFileCommitsAsync(
                       ownerName,
                       repositoryName,
                       version,
                       filename,
                       project.GetGitHubAccessTokenOrNull()
                       ));
        }
示例#4
0
        public async Task <LanguageConfig> GetLanguageListAsync(Project project, string version)
        {
            var token     = project.GetGitHubAccessTokenOrNull();
            var rootUrl   = project.GetGitHubUrl(version);
            var userAgent = project.GetGithubUserAgentOrNull();

            var url = CalculateRawRootUrl(rootUrl) + DocsDomainConsts.LanguageConfigFileName;

            var configAsJson = await DownloadWebContentAsStringAsync(url, token, userAgent);

            if (!JsonConvertExtensions.TryDeserializeObject <LanguageConfig>(configAsJson, out var languageConfig))
            {
                throw new UserFriendlyException($"Cannot validate language config file '{DocsDomainConsts.LanguageConfigFileName}' for the project {project.Name} - v{version}.");
            }

            return(languageConfig);
        }
示例#5
0
        public virtual async Task <Document> GetDocumentAsync(Project project, string documentName, string languageCode, string version, DateTime?lastKnownSignificantUpdateTime = null)
        {
            var token                = project.GetGitHubAccessTokenOrNull();
            var rootUrl              = project.GetGitHubUrl(version);
            var userAgent            = project.GetGithubUserAgentOrNull();
            var rawRootUrl           = CalculateRawRootUrlWithLanguageCode(rootUrl, languageCode);
            var rawDocumentUrl       = rawRootUrl + documentName;
            var isNavigationDocument = documentName == project.NavigationDocumentName;
            var isParameterDocument  = documentName == project.ParametersDocumentName;
            var editLink             = rootUrl.ReplaceFirst("/tree/", "/blob/") + languageCode + "/" + documentName;
            var localDirectory       = "";
            var fileName             = documentName;

            if (documentName.Contains("/"))
            {
                localDirectory = documentName.Substring(0, documentName.LastIndexOf('/'));
                fileName       = documentName.Substring(documentName.LastIndexOf('/') + 1);
            }

            var content = await DownloadWebContentAsStringAsync(rawDocumentUrl, token, userAgent);

            var commits = await GetGitHubCommitsOrNull(project, documentName, languageCode, version);

            var documentCreationTime      = GetFirstCommitDate(commits);
            var lastUpdateTime            = GetLastCommitDate(commits);
            var lastSignificantUpdateTime = await GetLastKnownSignificantUpdateTime(project, documentName, languageCode, version, lastKnownSignificantUpdateTime, isNavigationDocument, isParameterDocument, commits, documentCreationTime);

            var document = new Document
                           (
                GuidGenerator.Create(),
                project.Id,
                documentName,
                version,
                languageCode,
                fileName,
                content,
                project.Format,
                editLink,
                rootUrl,
                rawRootUrl,
                localDirectory,
                documentCreationTime,
                lastUpdateTime,
                DateTime.Now,
                lastSignificantUpdateTime
                           );

            if (isNavigationDocument || isParameterDocument)
            {
                return(document);
            }

            var authors = GetAuthors(commits);

            foreach (var author in authors)
            {
                document.AddContributor(author.Login, author.HtmlUrl, author.AvatarUrl);
            }

            return(document);
        }
示例#6
0
        private async Task <IReadOnlyList <Release> > GetReleasesAsync(Project project)
        {
            var url            = project.GetGitHubUrl();
            var ownerName      = GetOwnerNameFromUrl(url);
            var repositoryName = GetRepositoryNameFromUrl(url);

            return(await _githubRepositoryManager.GetReleasesAsync(ownerName, repositoryName, project.GetGitHubAccessTokenOrNull()));
        }