Skip to content

Commit

Permalink
Merge branch 'release/0.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalberger committed Apr 8, 2019
2 parents 08ef159 + af959b7 commit 0dde3e0
Show file tree
Hide file tree
Showing 9 changed files with 139 additions and 5 deletions.
2 changes: 1 addition & 1 deletion nuspec/nuget/Cake.Tfs.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<repository type="git" url="https://github.com/cake-contrib/Cake.Tfs"/>
<copyright>Copyright © Pascal Berger</copyright>
<tags>Cake Script Team-Foundation-Server TFS Azure-DevOps</tags>
<releaseNotes>https://github.com/cake-contrib/Cake.Tfs/releases/tag/0.2.7</releaseNotes>
<releaseNotes>https://github.com/cake-contrib/Cake.Tfs/releases/tag/0.3.0</releaseNotes>
</metadata>
<files>
<file src="net461\Cake.Tfs.dll" target="lib\net461" />
Expand Down
4 changes: 2 additions & 2 deletions src/Cake.Tfs.Tests/Cake.Tfs.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.0.1" />
<PackageReference Include="Cake.Core" Version="0.28.0" />
<PackageReference Include="Cake.Testing" Version="0.28.0" />
<PackageReference Include="Cake.Core" Version="0.33.0" />
<PackageReference Include="Cake.Testing" Version="0.33.0" />
<PackageReference Include="Moq" Version="4.10.1" />
<PackageReference Include="Shouldly" Version="3.0.2" />
<PackageReference Include="StyleCop.Analyzers" Version="1.0.2" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -45,6 +46,7 @@ public override GitHttpClient CreateGitClient(Uri collectionUrl, ITfsCredentials
new GitPullRequest
{
PullRequestId = 777,
Status = PullRequestStatus.Active,
Repository = new GitRepository
{
Id = Guid.NewGuid(),
Expand Down
43 changes: 43 additions & 0 deletions src/Cake.Tfs.Tests/PullRequest/PullRequestStatusExtensionsTests.cs
Original file line number Diff line number Diff line change
@@ -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");
}
}
}
}
8 changes: 8 additions & 0 deletions src/Cake.Tfs.Tests/PullRequest/TfsPullRequestTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/Cake.Tfs/Cake.Tfs.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Cake.Core" Version="0.28.0" />
<PackageReference Include="Cake.Core" Version="0.33.0" />
<PackageReference Include="Costura.Fody" Version="3.3.3" />
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.1" />
<PackageReference Include="Microsoft.TeamFoundationServer.Client" Version="15.131.1" />
Expand Down
33 changes: 33 additions & 0 deletions src/Cake.Tfs/PullRequest/PullRequestStatusExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
namespace Cake.Tfs.PullRequest
{
using System;
using Microsoft.TeamFoundation.SourceControl.WebApi;

/// <summary>
/// Extensions for the <see cref="PullRequestStatus"/> class.
/// </summary>
internal static class PullRequestStatusExtensions
{
/// <summary>
/// Converts a <see cref="PullRequestStatus"/> to a <see cref="TfsPullRequestState"/>.
/// </summary>
/// <param name="state">State to convert.</param>
/// <returns>Converted state.</returns>
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));
}
}
}
}
22 changes: 21 additions & 1 deletion src/Cake.Tfs/PullRequest/TfsPullRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

Expand Down Expand Up @@ -197,6 +197,26 @@ public int PullRequestId
}
}

/// <summary>
/// Gets the status of the pull request.
/// Returns <see cref="TfsPullRequestState.NotSet"/> if no pull request could be found and
/// <see cref="TfsPullRequestSettings.ThrowExceptionIfPullRequestCouldNotBeFound"/> is set to <c>false</c>.
/// </summary>
/// <exception cref="TfsPullRequestNotFoundException">If pull request could not be found and
/// <see cref="TfsPullRequestSettings.ThrowExceptionIfPullRequestCouldNotBeFound"/> is set to <c>true</c>.</exception>
public TfsPullRequestState PullRequestStatus
{
get
{
if (!this.ValidatePullRequest())
{
return TfsPullRequestState.NotSet;
}

return this.pullRequest.Status.ToTfsPullRequestState();
}
}

/// <summary>
/// Gets the ID of the code review.
/// Returns 0 if no pull request could be found and
Expand Down
28 changes: 28 additions & 0 deletions src/Cake.Tfs/PullRequest/TfsPullRequestState.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
namespace Cake.Tfs.PullRequest
{
/// <summary>
/// Possible states of a pull request.
/// </summary>
public enum TfsPullRequestState : byte
{
/// <summary>
/// Status is not set.
/// </summary>
NotSet,

/// <summary>
/// Pull request is active.
/// </summary>
Active,

/// <summary>
/// Pull request is abandoned.
/// </summary>
Abandoned,

/// <summary>
/// Pull request is completed.
/// </summary>
Completed
}
}

0 comments on commit 0dde3e0

Please sign in to comment.