예제 #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="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));
        }
예제 #3
0
        private async Task <Uri?> TryGetIssueWebUriAsync(IGitLabClient gitlabClient, GitLabReference reference)
        {
            m_Logger.LogDebug($"Getting web uri for issue {reference.Id}");

            try
            {
                var issue = await gitlabClient.Issues.GetAsync(reference.Project.ProjectPath, reference.Id);

                return(new Uri(issue.WebUrl));
            }
            catch (Exception ex) when(ex is GitLabException gitlabException && gitlabException.HttpStatusCode == HttpStatusCode.NotFound)
            {
                return(null);
            }
        }
예제 #4
0
        private Task <Uri?> TryGetWebUriAsync(IGitLabClient gitlabClient, GitLabReference reference)
        {
            switch (reference.Type)
            {
            case GitLabReferenceType.Issue:
                return(TryGetIssueWebUriAsync(gitlabClient, reference));

            case GitLabReferenceType.MergeRequest:
                return(TryGetMergeRequestWebUriAsync(gitlabClient, reference));

            case GitLabReferenceType.Milestone:
                return(TryGetMilestoneWebUriAsync(gitlabClient, reference));

            default:
                throw new InvalidOperationException();
            }
        }
예제 #5
0
        private async Task <Uri?> TryGetMilestoneWebUriAsync(IGitLabClient gitlabClient, GitLabReference reference)
        {
            m_Logger.LogDebug($"Getting web uri for Milestone {reference.Id}");

            try
            {
                // use GetMilestonesAsync() instead of GetMilestoneAsync() because the id
                // we can pass to GetMilestoneAsync() is not the id of the milestone
                // within the project, but some other id.
                // Instead, use GetMilestonesAsync() and query for a single milestone id
                // for which we can use the id in the reference.
                var milestones = await gitlabClient.Projects.GetMilestonesAsync(reference.Project.ProjectPath, queryOptions =>
                {
                    queryOptions.MilestoneIds = new[] { reference.Id };
                    queryOptions.State        = MilestoneState.All;
                });

                if (milestones.Count == 1)
                {
                    return(new Uri(milestones.Single().WebUrl));
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception ex) when(ex is GitLabException gitlabException && gitlabException.HttpStatusCode == HttpStatusCode.NotFound)
            {
                return(null);
            }
        }
    }
예제 #6
0
        private async Task <Uri?> TryGetMergeRequestWebUriAsync(IGitLabClient gitlabClient, GitLabReference reference)
        {
            m_Logger.LogDebug($"Getting web uri for Merge Request {reference.Id}");

            try
            {
                var mergeRequests = await gitlabClient.MergeRequests.GetAsync(reference.Project.ProjectPath, queryOptions =>
                {
                    queryOptions.MergeRequestsIds = new[] { reference.Id };
                    queryOptions.State            = QueryMergeRequestState.All;
                });

                if (mergeRequests.Count == 1)
                {
                    return(new Uri(mergeRequests.Single().WebUrl));
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception ex) when(ex is GitLabException gitlabException && gitlabException.HttpStatusCode == HttpStatusCode.NotFound)
            {
                return(null);
            }
        }