示例#1
0
        private async Task ProcessEntryAsync(GitHubProjectInfo projectInfo, IGitHubClient githubClient, ChangeLogEntry entry)
        {
            m_Logger.LogDebug($"Adding links to entry {entry.Commit}");

            foreach (var footer in entry.Footers)
            {
                if (footer.Value is CommitReferenceTextElement commitReference)
                {
                    var uri = await TryGetWebUriAsync(githubClient, projectInfo, commitReference.CommitId);

                    if (uri is not null)
                    {
                        footer.Value = CommitReferenceTextElementWithWebLink.FromCommitReference(commitReference, uri);
                    }
                    else
                    {
                        m_Logger.LogWarning($"Failed to determine web uri for commit '{commitReference.CommitId}'");
                    }
                }
                else if (footer.Value is PlainTextElement && GitHubReference.TryParse(footer.Value.Text, projectInfo, out var reference))
                {
                    var uri = await TryGetWebUriAsync(githubClient, reference);

                    if (uri is not null)
                    {
                        footer.Value = new GitHubReferenceTextElement(footer.Value.Text, uri, projectInfo, reference);
                    }
                    else
                    {
                        m_Logger.LogWarning($"Failed to determine web uri for reference '{reference}'");
                    }
                }
            }
        }
示例#2
0
        /// <summary>
        /// Initializes a new instance of <see cref="GitHubReference"/>
        /// </summary>
        /// <param name="project">The project the Pull Request of Issue belongs to</param>
        /// <param name="id">The Pull Request or Issue number</param>
        /// <exception cref="ArgumentOutOfRangeException">Thrown when <paramref name="id"/> is 0 or a negative number</exception>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="project"/> is <c>null</c></exception>
        public GitHubReference(GitHubProjectInfo project, int id)
        {
            if (id < 1)
            {
                throw new ArgumentOutOfRangeException(nameof(id));
            }

            Project = project ?? throw new ArgumentNullException(nameof(project));
            Id      = id;
        }
示例#3
0
        /// <summary>
        /// Initializes a new instance of <see cref="GitHubReferenceTextElement"/>.
        /// </summary>
        public GitHubReferenceTextElement(string text, Uri uri, GitHubProjectInfo currentProject, GitHubReference reference)
        {
            if (String.IsNullOrWhiteSpace(text))
            {
                throw new ArgumentException("Value must not be null or whitespace", nameof(text));
            }

            Text           = text;
            Uri            = uri ?? throw new ArgumentNullException(nameof(uri));
            CurrentProject = currentProject ?? throw new ArgumentNullException(nameof(currentProject));
            Reference      = reference ?? throw new ArgumentNullException(nameof(reference));
        }
示例#4
0
        private async Task <Uri?> TryGetWebUriAsync(IGitHubClient githubClient, GitHubProjectInfo projectInfo, GitId commitId)
        {
            m_Logger.LogDebug($"Getting web uri for commit '{commitId}'");

            try
            {
                var commit = await githubClient.Repository.Commit.Get(projectInfo.Owner, projectInfo.Repository, commitId.Id);

                return(new Uri(commit.HtmlUrl));
            }
            catch (Exception ex) when(ex is ApiValidationException || ex is NotFoundException)
            {
                return(null);
            }
        }