Пример #1
0
        private async Task ProcessEntryAsync(IGitLabClient gitlabClient, GitLabProjectInfo projectInfo, 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(gitlabClient, 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 '{entry.Commit}'");
                    }
                }
                else if (footer.Value is PlainTextElement && GitLabReference.TryParse(footer.Value.Text, projectInfo, out var reference))
                {
                    var uri = await TryGetWebUriAsync(gitlabClient, reference);

                    if (uri is not null)
                    {
                        footer.Value = new GitLabReferenceTextElement(footer.Value.Text, uri, projectInfo, reference);
                    }
                    else
                    {
                        m_Logger.LogWarning($"Failed to determine web uri for GitLab reference '{reference}'");
                    }
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Initializes a new instance of <see cref="GitLabReference"/>
        /// </summary>
        /// <param name="project">The project the referenced item belong to.</param>
        /// <param name="type">The type of the referenced item.</param>
        /// <param name="id">The referenced item's id.</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 GitLabReference(GitLabProjectInfo project, GitLabReferenceType type, int id)
        {
            if (id < 1)
            {
                throw new ArgumentOutOfRangeException(nameof(id));
            }

            Project = project ?? throw new ArgumentNullException(nameof(project));
            Type    = type;
            Id      = id;
        }
Пример #3
0
        /// <summary>
        /// Initializes a new instance of <see cref="GitLabReferenceTextElement"/>.
        /// </summary>
        public GitLabReferenceTextElement(string text, Uri uri, GitLabProjectInfo currentProject, GitLabReference 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(IGitLabClient gitlabClient, GitLabProjectInfo projectInfo, GitId commitId)
        {
            m_Logger.LogDebug($"Getting web uri for commit '{commitId}'");

            try
            {
                var commit = await gitlabClient.Commits.GetAsync(projectInfo.ProjectPath, commitId.Id);

                return(new Uri(commit.WebUrl));
            }
            catch (Exception ex) when(ex is GitLabException gitlabException && gitlabException.HttpStatusCode == HttpStatusCode.NotFound)
            {
                return(null);
            }
        }