-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability to do a code compare. (#444)
* Add ability to do a code compare. * Rename classes, methods, add tests * Update NGitLab.Tests/CompareTests.cs Co-authored-by: Louis Zanella <[email protected]> * Update NGitLab.Tests/CompareTests.cs Co-authored-by: Louis Zanella <[email protected]> * Update NGitLab/Impl/RepositoryClient.cs Co-authored-by: Louis Zanella <[email protected]> * Fix spelling * Fixed tests * removed unnecessary variable --------- Co-authored-by: Markus Stein <[email protected]> Co-authored-by: Louis Zanella <[email protected]>
- Loading branch information
1 parent
97a0852
commit 613bee0
Showing
7 changed files
with
151 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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,70 @@ | ||
using System.Threading.Tasks; | ||
using NGitLab.Models; | ||
using NGitLab.Tests.Docker; | ||
using NUnit.Framework; | ||
|
||
namespace NGitLab.Tests | ||
{ | ||
public class CompareTests | ||
{ | ||
[Test] | ||
[NGitLabRetry] | ||
public async Task Test_compare_equal() | ||
{ | ||
using var context = await GitLabTestContext.CreateAsync(); | ||
var project = context.CreateProject(initializeWithCommits: true); | ||
var compareResults = context.Client.GetRepository(project.Id).Compare(new CompareQuery(project.DefaultBranch, project.DefaultBranch)); | ||
|
||
Assert.IsNotNull(compareResults); | ||
Assert.AreEqual(0, compareResults.Commits.Length); | ||
} | ||
|
||
[Test] | ||
[NGitLabRetry] | ||
public async Task Test_compare() | ||
{ | ||
using var context = await GitLabTestContext.CreateAsync(); | ||
var project = context.CreateProject(initializeWithCommits: true); | ||
|
||
var devTestBranchCreate = new BranchCreate(); | ||
devTestBranchCreate.Ref = project.DefaultBranch; | ||
devTestBranchCreate.Name = "devtest"; | ||
|
||
context.Client.GetRepository(project.Id).Branches.Create(devTestBranchCreate); | ||
|
||
context.Client.GetRepository(project.Id).Files.Create(new FileUpsert | ||
{ | ||
Branch = "devtest", | ||
CommitMessage = "file to be compared", | ||
Path = "compare1.txt", | ||
RawContent = "compare me", | ||
}); | ||
|
||
context.Client.GetRepository(project.Id).Files.Create(new FileUpsert | ||
{ | ||
Branch = "devtest", | ||
CommitMessage = "file to be compared, too", | ||
Path = "compare2.txt", | ||
RawContent = "compare me now", | ||
}); | ||
|
||
var compareResults = context.Client.GetRepository(project.Id).Compare(new CompareQuery(project.DefaultBranch, "devtest")); | ||
|
||
Assert.IsNotNull(compareResults); | ||
Assert.AreEqual(2, compareResults.Commits.Length); | ||
} | ||
|
||
[Test] | ||
[NGitLabRetry] | ||
public async Task Test_compare_invalid() | ||
{ | ||
using var context = await GitLabTestContext.CreateAsync(); | ||
var project = context.CreateProject(initializeWithCommits: true); | ||
|
||
Assert.Catch< GitLabException>(() => | ||
{ | ||
context.Client.GetRepository(project.Id).Compare(new CompareQuery(project.DefaultBranch, "testblub")); | ||
}, "404 Ref Not Found", null); | ||
} | ||
} | ||
} |
This file contains 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 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 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,24 @@ | ||
namespace NGitLab.Models | ||
{ | ||
/// <summary> | ||
/// Query details for comparison of branches/tags/commit hashes | ||
/// </summary> | ||
public class CompareQuery | ||
{ | ||
/// <summary> | ||
/// The source for comparison, can be a branch, tag or a commit hash. | ||
/// </summary> | ||
public string Source { get; set; } | ||
|
||
/// <summary> | ||
/// The target for comparison, can be a branch, tag or a commit hash. | ||
/// </summary> | ||
public string Target { get; set; } | ||
|
||
public CompareQuery(string source, string target) | ||
{ | ||
Source = source; | ||
Target = target; | ||
} | ||
} | ||
} |
This file contains 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,22 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace NGitLab.Models | ||
{ | ||
public class CompareResults | ||
{ | ||
[JsonPropertyName("commit")] | ||
public Commit Commit { get; set; } | ||
|
||
[JsonPropertyName("commits")] | ||
public Commit[] Commits { get; set; } | ||
|
||
[JsonPropertyName("diffs")] | ||
public Diff[] Diff { get; set; } | ||
|
||
[JsonPropertyName("compare_timeout")] | ||
public bool CompareTimeout { get; set; } | ||
|
||
[JsonPropertyName("compare_same_ref")] | ||
public bool CompareSameRefs { get; set; } | ||
} | ||
} |
This file contains 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