From e918568b72c9bfe4c59ec53b32a3391a9e113b7e Mon Sep 17 00:00:00 2001 From: Pascal Berger Date: Mon, 8 Apr 2019 19:21:35 +0200 Subject: [PATCH 1/3] (GH-90) Build against Cake 0.33 --- src/Cake.Tfs.Tests/Cake.Tfs.Tests.csproj | 4 ++-- src/Cake.Tfs/Cake.Tfs.csproj | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Cake.Tfs.Tests/Cake.Tfs.Tests.csproj b/src/Cake.Tfs.Tests/Cake.Tfs.Tests.csproj index 75c78ef3..7b0d742d 100644 --- a/src/Cake.Tfs.Tests/Cake.Tfs.Tests.csproj +++ b/src/Cake.Tfs.Tests/Cake.Tfs.Tests.csproj @@ -15,8 +15,8 @@ - - + + diff --git a/src/Cake.Tfs/Cake.Tfs.csproj b/src/Cake.Tfs/Cake.Tfs.csproj index eefec70a..b278a3a2 100644 --- a/src/Cake.Tfs/Cake.Tfs.csproj +++ b/src/Cake.Tfs/Cake.Tfs.csproj @@ -22,7 +22,7 @@ - + From de42a743756375b61041196a40b9e064e0c0e299 Mon Sep 17 00:00:00 2001 From: Pascal Berger Date: Mon, 8 Apr 2019 19:18:39 +0200 Subject: [PATCH 2/3] (GH-89) Return pull request status --- .../Fakes/FakeAllSetGitClientFactory.cs | 2 + .../PullRequestStatusExtensionsTests.cs | 43 +++++++++++++++++++ .../PullRequest/TfsPullRequestTests.cs | 8 ++++ .../PullRequestStatusExtensions.cs | 33 ++++++++++++++ src/Cake.Tfs/PullRequest/TfsPullRequest.cs | 22 +++++++++- .../PullRequest/TfsPullRequestState.cs | 28 ++++++++++++ 6 files changed, 135 insertions(+), 1 deletion(-) create mode 100644 src/Cake.Tfs.Tests/PullRequest/PullRequestStatusExtensionsTests.cs create mode 100644 src/Cake.Tfs/PullRequest/PullRequestStatusExtensions.cs create mode 100644 src/Cake.Tfs/PullRequest/TfsPullRequestState.cs diff --git a/src/Cake.Tfs.Tests/PullRequest/Fakes/FakeAllSetGitClientFactory.cs b/src/Cake.Tfs.Tests/PullRequest/Fakes/FakeAllSetGitClientFactory.cs index ac010929..1e7bff99 100644 --- a/src/Cake.Tfs.Tests/PullRequest/Fakes/FakeAllSetGitClientFactory.cs +++ b/src/Cake.Tfs.Tests/PullRequest/Fakes/FakeAllSetGitClientFactory.cs @@ -18,6 +18,7 @@ public override GitHttpClient CreateGitClient(Uri collectionUrl, ITfsCredentials .ReturnsAsync((string project1, string repoId1, int prId, int i1, int i2, int i3, bool b1, bool b2, object o1, CancellationToken c1) => new GitPullRequest { PullRequestId = prId, + Status = PullRequestStatus.Active, Repository = new GitRepository { Id = Guid.NewGuid(), @@ -45,6 +46,7 @@ public override GitHttpClient CreateGitClient(Uri collectionUrl, ITfsCredentials new GitPullRequest { PullRequestId = 777, + Status = PullRequestStatus.Active, Repository = new GitRepository { Id = Guid.NewGuid(), diff --git a/src/Cake.Tfs.Tests/PullRequest/PullRequestStatusExtensionsTests.cs b/src/Cake.Tfs.Tests/PullRequest/PullRequestStatusExtensionsTests.cs new file mode 100644 index 00000000..2b48c5a0 --- /dev/null +++ b/src/Cake.Tfs.Tests/PullRequest/PullRequestStatusExtensionsTests.cs @@ -0,0 +1,43 @@ +namespace Cake.Tfs.Tests.PullRequest +{ + using Cake.Tfs.PullRequest; + using Microsoft.TeamFoundation.SourceControl.WebApi; + using Shouldly; + using Xunit; + + public sealed class PullRequestStatusExtensionsTests + { + public sealed class TheToTfsPullRequestState + { + [Theory] + [InlineData(PullRequestStatus.NotSet, TfsPullRequestState.NotSet)] + [InlineData(PullRequestStatus.Active, TfsPullRequestState.Active)] + [InlineData(PullRequestStatus.Completed, TfsPullRequestState.Completed)] + [InlineData(PullRequestStatus.Abandoned, TfsPullRequestState.Abandoned)] + public void Should_Return_Correct_Value(PullRequestStatus state, TfsPullRequestState expectedResult) + { + // Given + + // When + var result = state.ToTfsPullRequestState(); + + // Then + result.ShouldBe(expectedResult); + } + + [Theory] + [InlineData(PullRequestStatus.All)] + public void Should_Throw_If_Invalid_Value_Is_Passed(PullRequestStatus state) + { + // Given + + // When + var result = + Record.Exception(() => state.ToTfsPullRequestState()); + + // Then + result.IsArgumentOutOfRangeException("state"); + } + } + } +} diff --git a/src/Cake.Tfs.Tests/PullRequest/TfsPullRequestTests.cs b/src/Cake.Tfs.Tests/PullRequest/TfsPullRequestTests.cs index 49274a02..265918a4 100644 --- a/src/Cake.Tfs.Tests/PullRequest/TfsPullRequestTests.cs +++ b/src/Cake.Tfs.Tests/PullRequest/TfsPullRequestTests.cs @@ -123,6 +123,7 @@ public void Should_Return_Valid_Tfs_Pull_Request_By_Id() pullRequest.ShouldNotBe(null); pullRequest.HasPullRequestLoaded.ShouldBe(true); pullRequest.PullRequestId.ShouldBe(42); + pullRequest.PullRequestStatus.ShouldBe(TfsPullRequestState.Active); pullRequest.RepositoryName.ShouldBe("MyRepoName"); pullRequest.CollectionName.ShouldBe("MyCollection"); pullRequest.CodeReviewId.ShouldBe(123); @@ -146,6 +147,7 @@ public void Should_Return_Valid_Azure_DevOps_Pull_Request_By_Id() pullRequest.ShouldNotBe(null); pullRequest.HasPullRequestLoaded.ShouldBe(true); pullRequest.PullRequestId.ShouldBe(16); + pullRequest.PullRequestStatus.ShouldBe(TfsPullRequestState.Active); pullRequest.RepositoryName.ShouldBe("MyRepoName"); pullRequest.CollectionName.ShouldBe("DefaultCollection"); pullRequest.CodeReviewId.ShouldBe(123); @@ -169,6 +171,7 @@ public void Should_Return_Valid_Tfs_Pull_Request_By_Source_Branch() pullRequest.ShouldNotBe(null); pullRequest.HasPullRequestLoaded.ShouldBe(true); pullRequest.PullRequestId.ShouldBe(777); + pullRequest.PullRequestStatus.ShouldBe(TfsPullRequestState.Active); pullRequest.RepositoryName.ShouldBe("MyRepoName"); pullRequest.CollectionName.ShouldBe("MyCollection"); pullRequest.CodeReviewId.ShouldBe(123); @@ -192,6 +195,7 @@ public void Should_Return_Valid_Azure_DevOps_Pull_Request_By_Source_Branch() pullRequest.ShouldNotBe(null); pullRequest.HasPullRequestLoaded.ShouldBe(true); pullRequest.PullRequestId.ShouldBe(777); + pullRequest.PullRequestStatus.ShouldBe(TfsPullRequestState.Active); pullRequest.RepositoryName.ShouldBe("MyRepoName"); pullRequest.CollectionName.ShouldBe("DefaultCollection"); pullRequest.CodeReviewId.ShouldBe(123); @@ -223,6 +227,7 @@ public void Should_Return_Null_Tfs_Pull_Request_By_Id() pullRequest.CollectionName.ShouldBe("MyCollection"); pullRequest.ProjectName.ShouldBe("MyTeamProject"); pullRequest.PullRequestId.ShouldBe(0); + pullRequest.PullRequestStatus.ShouldBe(TfsPullRequestState.NotSet); pullRequest.CodeReviewId.ShouldBe(0); pullRequest.SourceRefName.ShouldBeEmpty(); pullRequest.TargetRefName.ShouldBeEmpty(); @@ -251,6 +256,7 @@ public void Should_Return_Null_Azure_DevOps_Pull_Request_By_Id() pullRequest.CollectionName.ShouldBe("DefaultCollection"); pullRequest.ProjectName.ShouldBe("MyProject"); pullRequest.PullRequestId.ShouldBe(0); + pullRequest.PullRequestStatus.ShouldBe(TfsPullRequestState.NotSet); pullRequest.CodeReviewId.ShouldBe(0); pullRequest.SourceRefName.ShouldBeEmpty(); pullRequest.TargetRefName.ShouldBeEmpty(); @@ -279,6 +285,7 @@ public void Should_Return_Null_Tfs_Pull_Request_By_Branch() pullRequest.CollectionName.ShouldBe("MyCollection"); pullRequest.ProjectName.ShouldBe("MyTeamProject"); pullRequest.PullRequestId.ShouldBe(0); + pullRequest.PullRequestStatus.ShouldBe(TfsPullRequestState.NotSet); pullRequest.CodeReviewId.ShouldBe(0); pullRequest.SourceRefName.ShouldBeEmpty(); pullRequest.TargetRefName.ShouldBeEmpty(); @@ -307,6 +314,7 @@ public void Should_Return_Null_Azure_DevOps_Pull_Request_By_Branch() pullRequest.CollectionName.ShouldBe("DefaultCollection"); pullRequest.ProjectName.ShouldBe("MyProject"); pullRequest.PullRequestId.ShouldBe(0); + pullRequest.PullRequestStatus.ShouldBe(TfsPullRequestState.NotSet); pullRequest.CodeReviewId.ShouldBe(0); pullRequest.SourceRefName.ShouldBeEmpty(); pullRequest.TargetRefName.ShouldBeEmpty(); diff --git a/src/Cake.Tfs/PullRequest/PullRequestStatusExtensions.cs b/src/Cake.Tfs/PullRequest/PullRequestStatusExtensions.cs new file mode 100644 index 00000000..6cd7152d --- /dev/null +++ b/src/Cake.Tfs/PullRequest/PullRequestStatusExtensions.cs @@ -0,0 +1,33 @@ +namespace Cake.Tfs.PullRequest +{ + using System; + using Microsoft.TeamFoundation.SourceControl.WebApi; + + /// + /// Extensions for the class. + /// + internal static class PullRequestStatusExtensions + { + /// + /// Converts a to a . + /// + /// State to convert. + /// Converted state. + public static TfsPullRequestState ToTfsPullRequestState(this PullRequestStatus state) + { + switch (state) + { + case PullRequestStatus.NotSet: + return TfsPullRequestState.NotSet; + case PullRequestStatus.Active: + return TfsPullRequestState.Active; + case PullRequestStatus.Abandoned: + return TfsPullRequestState.Abandoned; + case PullRequestStatus.Completed: + return TfsPullRequestState.Completed; + default: + throw new ArgumentOutOfRangeException(nameof(state)); + } + } + } +} diff --git a/src/Cake.Tfs/PullRequest/TfsPullRequest.cs b/src/Cake.Tfs/PullRequest/TfsPullRequest.cs index c81c400d..10ff6da9 100644 --- a/src/Cake.Tfs/PullRequest/TfsPullRequest.cs +++ b/src/Cake.Tfs/PullRequest/TfsPullRequest.cs @@ -88,7 +88,7 @@ public TfsPullRequest(ICakeLog log, TfsPullRequestSettings settings, IGitClientF var pullRequestSearchCriteria = new GitPullRequestSearchCriteria() { - Status = PullRequestStatus.Active, + Status = Microsoft.TeamFoundation.SourceControl.WebApi.PullRequestStatus.Active, SourceRefName = settings.SourceRefName }; @@ -197,6 +197,26 @@ public int PullRequestId } } + /// + /// Gets the status of the pull request. + /// Returns if no pull request could be found and + /// is set to false. + /// + /// If pull request could not be found and + /// is set to true. + public TfsPullRequestState PullRequestStatus + { + get + { + if (!this.ValidatePullRequest()) + { + return TfsPullRequestState.NotSet; + } + + return this.pullRequest.Status.ToTfsPullRequestState(); + } + } + /// /// Gets the ID of the code review. /// Returns 0 if no pull request could be found and diff --git a/src/Cake.Tfs/PullRequest/TfsPullRequestState.cs b/src/Cake.Tfs/PullRequest/TfsPullRequestState.cs new file mode 100644 index 00000000..023c2e23 --- /dev/null +++ b/src/Cake.Tfs/PullRequest/TfsPullRequestState.cs @@ -0,0 +1,28 @@ +namespace Cake.Tfs.PullRequest +{ + /// + /// Possible states of a pull request. + /// + public enum TfsPullRequestState : byte + { + /// + /// Status is not set. + /// + NotSet, + + /// + /// Pull request is active. + /// + Active, + + /// + /// Pull request is abandoned. + /// + Abandoned, + + /// + /// Pull request is completed. + /// + Completed + } +} From af959b71596981200d21197ecbc8e5edd206a858 Mon Sep 17 00:00:00 2001 From: Pascal Berger Date: Mon, 8 Apr 2019 19:44:23 +0200 Subject: [PATCH 3/3] Update release notes link --- nuspec/nuget/Cake.Tfs.nuspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nuspec/nuget/Cake.Tfs.nuspec b/nuspec/nuget/Cake.Tfs.nuspec index 8f1266e4..972145a9 100644 --- a/nuspec/nuget/Cake.Tfs.nuspec +++ b/nuspec/nuget/Cake.Tfs.nuspec @@ -17,7 +17,7 @@ Copyright © Pascal Berger Cake Script Team-Foundation-Server TFS Azure-DevOps - https://github.com/cake-contrib/Cake.Tfs/releases/tag/0.2.7 + https://github.com/cake-contrib/Cake.Tfs/releases/tag/0.3.0