Skip to content
This repository has been archived by the owner on Apr 6, 2024. It is now read-only.

Commit

Permalink
Merge pull request #9 from bbtsoftware/LastSourceCommit
Browse files Browse the repository at this point in the history
New alias TfsPullRequestLastSourceCommit
  • Loading branch information
stffabi authored Dec 20, 2017
2 parents 436e0f5 + dce9c71 commit 714cb2c
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 2 deletions.
3 changes: 3 additions & 0 deletions cake.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[Nuget]
; Use the new InProcess client, because some packages have long file paths.
UseInProcessClient=true
3 changes: 2 additions & 1 deletion setup.cake
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ BuildParameters.SetParameters(
title: "Cake.Issues.PullRequests.Tfs",
repositoryOwner: "cake-contrib",
repositoryName: "Cake.Issues.PullRequests.Tfs",
appVeyorAccountName: "cakecontrib");
appVeyorAccountName: "cakecontrib",
shouldRunCodecov: false);

BuildParameters.PrintParameters(Context);

Expand Down
17 changes: 17 additions & 0 deletions src/Cake.Issues.PullRequests.Tfs/TfsPullRequestSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,23 @@ public TfsPullRequestSystem(ICakeLog log, TfsPullRequestSettings settings)
this.pullRequest.SourceRefName);
}

/// <summary>
/// Gets the hash of the latest commit on the source branch.
/// Returns <see cref="string.Empty"/> if no pull request could be found.
/// </summary>
public string LastSourceCommitId
{
get
{
if (!this.ValidatePullRequest())
{
return string.Empty;
}

return this.pullRequest.LastMergeSourceCommit.CommitId;
}
}

/// <summary>
/// Votes for the pullrequest.
/// </summary>
Expand Down
37 changes: 37 additions & 0 deletions src/Cake.Issues.PullRequests.Tfs/TfsPullRequestSystemAliases.cs
Original file line number Diff line number Diff line change
Expand Up @@ -273,5 +273,42 @@ public static void TfsVotePullRequest(
var pullRequest = new TfsPullRequestSystem(context.Log, settings);
pullRequest.Vote(vote);
}

/// <summary>
/// Gets the last commit hash on the source branch of the Team Foundation Server or
/// Visual Studio Team Services pull request using the specified settings.
/// </summary>
/// <param name="context">The context.</param>
/// <param name="settings">Settings for accessing the pull request system.</param>
/// <example>
/// <para>Get the hash of the last commit:</para>
/// <code>
/// <![CDATA[
/// var pullRequestSettings =
/// new TfsPullRequestSettings(
/// new Uri("http://myserver:8080/tfs/defaultcollection/myproject/_git/myrepository"),
/// "refs/heads/feature/myfeature",
/// TfsAuthenticationNtlm());
///
/// var hash =
/// TfsPullRequestLastSourceCommit(
/// pullRequestSettings);
/// ]]>
/// </code>
/// </example>
/// <returns>The hash of the last commit on the source branch or <see cref="string.Empty"/>
/// if no pull request could be found.</returns>
[CakeMethodAlias]
[CakeAliasCategory(PullRequestsAliasConstants.PullRequestSystemCakeAliasCategory)]
public static string TfsPullRequestLastSourceCommit(
this ICakeContext context,
TfsPullRequestSettings settings)
{
context.NotNull(nameof(context));
settings.NotNull(nameof(settings));

var pullRequest = new TfsPullRequestSystem(context.Log, settings);
return pullRequest.LastSourceCommitId;
}
}
}
2 changes: 1 addition & 1 deletion tools/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Cake" version="0.21.1" />
<package id="Cake" version="0.23.0" />
</packages>

0 comments on commit 714cb2c

Please sign in to comment.