-
Notifications
You must be signed in to change notification settings - Fork 86
chore!: Add UnapproveMergeRequest, GetDiffsAsync with unidiff, and draft notes API #1123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
12cc6e5
feat: add UnapproveMergeRequest, GetDiffsAsync with unidiff, and draf…
louis-z b552103
test: add integration tests for UnapproveMergeRequest, GetDiffsAsync,…
louis-z 3d1d717
review
louis-z 37765ed
Fix timing issues
louis-z 5cc8a0c
Fix other issues
louis-z f5db31d
Get rid of CreateMergeRequest()
louis-z File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
| using NGitLab.Models; | ||
|
|
||
| namespace NGitLab.Mock.Clients; | ||
|
|
||
| internal sealed class MergeRequestDraftNoteClient : ClientBase, IMergeRequestDraftNoteClient | ||
| { | ||
| public MergeRequestDraftNoteClient(ClientContext context) | ||
| : base(context) | ||
| { | ||
| } | ||
|
|
||
| public IEnumerable<DraftNote> All => throw new NotImplementedException(); | ||
|
|
||
| public Task<DraftNote> CreateAsync(DraftNoteCreate draftNote, CancellationToken cancellationToken = default) | ||
| => throw new NotImplementedException(); | ||
|
|
||
| public Task PublishAllAsync(CancellationToken cancellationToken = default) | ||
| => throw new NotImplementedException(); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
NGitLab.Tests/MergeRequest/MergeRequestApprovalClientTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| using System; | ||
| using System.Threading.Tasks; | ||
| using NGitLab.Tests.Docker; | ||
| using NUnit.Framework; | ||
|
|
||
| namespace NGitLab.Tests; | ||
|
|
||
| public class MergeRequestApprovalClientTests | ||
| { | ||
| [Test] | ||
| [NGitLabRetry] | ||
| public async Task ApproveMergeRequest_and_UnapproveMergeRequest_roundtrip() | ||
| { | ||
| using var context = await GitLabTestContext.CreateAsync(); | ||
| var (project, mergeRequest) = await context.CreateMergeRequestAsync(); | ||
| var mrClient = context.Client.GetMergeRequest(project.Id); | ||
| var approvalClient = mrClient.ApprovalClient(mergeRequest.Iid); | ||
|
|
||
| // Approve | ||
| var approvals = approvalClient.ApproveMergeRequest(); | ||
| Assert.That(approvals, Is.Not.Null); | ||
| Assert.That(approvals.Approved, Is.True, "MR should be marked as approved after ApproveMergeRequest"); | ||
|
|
||
| // Unapprove — should not throw | ||
| Assert.DoesNotThrow((Action)(() => approvalClient.UnapproveMergeRequest())); | ||
|
|
||
| // After unapproval the approval state should show no approved-by entries | ||
| var state = approvalClient.Approvals; | ||
| Assert.That(state.ApprovedBy, Is.Empty.Or.Null, "No approvers should remain after unapproving"); | ||
| } | ||
|
|
||
| [Test] | ||
| [NGitLabRetry] | ||
| public async Task UnapproveMergeRequest_on_unapproved_mr_throws() | ||
| { | ||
| // Arrange | ||
| using var context = await GitLabTestContext.CreateAsync(); | ||
| var (project, mergeRequest) = await context.CreateMergeRequestAsync(); | ||
| var approvalClient = context.Client.GetMergeRequest(project.Id).ApprovalClient(mergeRequest.Iid); | ||
|
|
||
| // Act/Assert | ||
| Assert.That((Action)(() => approvalClient.UnapproveMergeRequest()), Throws.TypeOf<GitLabException>(), | ||
| "Unapproving an unapproved MR should throw a GitLabException"); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
NGitLab.Tests/MergeRequest/MergeRequestDiffsClientTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| using System.Linq; | ||
| using System.Threading.Tasks; | ||
| using NGitLab.Models; | ||
| using NGitLab.Tests.Docker; | ||
| using NUnit.Framework; | ||
|
|
||
| namespace NGitLab.Tests; | ||
|
|
||
| public class MergeRequestDiffsClientTests | ||
| { | ||
| [Test] | ||
| [NGitLabRetry] | ||
| public async Task GetDiffsAsync_returns_changed_files() | ||
| { | ||
| using var context = await GitLabTestContext.CreateAsync(); | ||
| var (project, mergeRequest) = await context.CreateMergeRequestAsync(); | ||
| var mrClient = context.Client.GetMergeRequest(project.Id); | ||
|
|
||
| var diffs = await mrClient.GetDiffsAsync(mergeRequest.Iid, query: null).ToListAsync(); | ||
|
|
||
| Assert.That(diffs, Has.Count.GreaterThan(0), "At least one diff should be returned"); | ||
| Assert.That(diffs[0].OldPath, Is.Not.Null.And.Not.Empty); | ||
| Assert.That(diffs[0].NewPath, Is.Not.Null.And.Not.Empty); | ||
| } | ||
|
|
||
| [Test] | ||
| [NGitLabRetry] | ||
| public async Task GetDiffsAsync_with_unidiff_returns_changed_files() | ||
| { | ||
| using var context = await GitLabTestContext.CreateAsync(); | ||
| var (project, mergeRequest) = await context.CreateMergeRequestAsync(); | ||
| var mrClient = context.Client.GetMergeRequest(project.Id); | ||
|
|
||
| var query = new MergeRequestDiffQuery { Unidiff = true }; | ||
| var diffs = await mrClient.GetDiffsAsync(mergeRequest.Iid, query).ToListAsync(); | ||
|
|
||
| Assert.That(diffs, Has.Count.GreaterThan(0), "At least one diff should be returned with unidiff=true"); | ||
| Assert.That(diffs[0].OldPath, Is.Not.Null.And.Not.Empty); | ||
| Assert.That(diffs[0].NewPath, Is.Not.Null.And.Not.Empty); | ||
| } | ||
|
|
||
| [Test] | ||
| [NGitLabRetry] | ||
| public async Task GetDiffsAsync_unidiff_format_starts_with_unified_diff_header() | ||
| { | ||
| using var context = await GitLabTestContext.CreateAsync(); | ||
| var (project, mergeRequest) = await context.CreateMergeRequestAsync(); | ||
| var mrClient = context.Client.GetMergeRequest(project.Id); | ||
|
|
||
| var plainDiffs = await mrClient.GetDiffsAsync(mergeRequest.Iid, query: null).ToListAsync(); | ||
| var unifiedDiffs = await mrClient.GetDiffsAsync(mergeRequest.Iid, new MergeRequestDiffQuery { Unidiff = true }).ToListAsync(); | ||
|
|
||
| Assert.That(plainDiffs, Has.Count.EqualTo(unifiedDiffs.Count), "Both queries should return the same number of files"); | ||
|
|
||
| // Unified diff format uses "--- a/..." / "+++ b/..." headers; the plain GitLab format does not. | ||
| var firstUnified = unifiedDiffs[0].Difference; | ||
| Assert.That(firstUnified, Does.StartWith("---").Or.StartWith("diff --git"), | ||
| "Unified diff content should start with standard unified-diff markers"); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.