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); } }
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); } } }
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}'"); } } } }
private async Task ProcessEntryAsync(IGitLabClient githubClient, ChangeLogEntry entry) { m_Logger.LogDebug($"Adding links to entry {entry.Commit}"); var webUri = await TryGetWebUriAsync(githubClient, entry.Commit); if (webUri != null) { entry.CommitWebUri = webUri; } else { m_Logger.LogWarning($"Failed to determine web uri for commit '{entry.Commit}'"); } foreach (var footer in entry.Footers) { if (TryParseReference(footer.Value, out var type, out var projectPath, out var id)) { var uri = await TryGetWebUriAsync(githubClient, type.Value, projectPath, id); if (uri != null) { footer.WebUri = uri; } else { m_Logger.LogWarning($"Failed to determine web uri for GitLab {type} reference '{footer.Value}'"); } } } }
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); } }
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); } }
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(); } }
private Task <Uri?> TryGetWebUriAsync(IGitLabClient gitlabClient, GitLabReferenceType type, string projectPath, int id) { switch (type) { case GitLabReferenceType.Issue: return(TryGetIssueWebUriAsync(gitlabClient, projectPath, id)); case GitLabReferenceType.MergeRequest: return(TryGetMergeRequestWebUriAsync(gitlabClient, projectPath, id)); case GitLabReferenceType.Milestone: return(TryGetMilestoneWebUriAsync(gitlabClient, projectPath, id)); default: throw new InvalidOperationException(); } }
public MergeRequestsProvider(IGitLabClient gitLabClient) { this.gitLabClient = gitLabClient; }
public static async Task <MergeRequest> CreateMergeRequestAsync(this GitLabTestContext context, IGitLabClient client, ProjectIdOrPathRef project, bool assignedToMe = false, bool hasConflict = false, Action <CreateMergeRequestRequest> configure = null) { var filePath = context.GetRandomString(); var branchName = context.GetRandomString(); var assignee = assignedToMe ? await client.Users.GetCurrentUserAsync() : null; await client.RepositoryFiles.CreateFileAsync(new CreateFileRepositoryFileRequest(project, filePath, "master", content : context.GetRandomString(), commitMessage : context.GetRandomString())); await client.RepositoryFiles.UpdateFileAsync(new UpdateFileRepositoryFileRequest(project, filePath, branchName, content : TextOrBinaryData.FromString(context.GetRandomString(), Encoding.UTF8), commitMessage : context.GetRandomString()) { StartBranch = "master", }); if (hasConflict) { await client.RepositoryFiles.UpdateFileAsync(new UpdateFileRepositoryFileRequest(project, filePath, "master", content : context.GetRandomString(), commitMessage : context.GetRandomString())); } // Create merge request var request = new CreateMergeRequestRequest(project, branchName, "master", title: context.GetRandomString()) { AssigneeId = assignee, }; configure?.Invoke(request); var mergeRequest = await client.MergeRequests.CreateMergeRequestAsync(request); return(mergeRequest); }