Skip to content
This repository has been archived by the owner on Dec 28, 2017. It is now read-only.

Commit

Permalink
Merge branch 'release/0.2.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalberger committed Mar 28, 2017
2 parents 4e52b64 + a9c7b8b commit eb103bc
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 2 deletions.
2 changes: 1 addition & 1 deletion nuspec/nuget/Cake.Prca.PullRequests.Tfs.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<copyright>Copyright © 2017 BBT Software AG, Root/Zermatt, Switzerland</copyright>
<tags>Cake Script PullRequest CodeAnalysis Cake-Prca-PullRequestSystem TFS VSTS Linting</tags>
<releaseNotes>https://github.com/cake-contrib/Cake.Prca.PullRequests.Tfs/releases/tag/0.2.1</releaseNotes>
<releaseNotes>https://github.com/cake-contrib/Cake.Prca.PullRequests.Tfs/releases/tag/0.2.2</releaseNotes>
<dependencies>
<dependency id="Cake.Prca" version="[0.2,0.3)" />
</dependencies>
Expand Down
6 changes: 6 additions & 0 deletions src/Cake.Prca.PullRequests.Tfs/TfsPullRequestSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,11 @@ public TfsPullRequestSettings(Uri repositoryUrl, int pullRequestId, IPrcaCredent
/// Visual Studio Team Services.
/// </summary>
public IPrcaCredentials Credentials { get; private set; }

/// <summary>
/// Gets or sets a value indicating whether an exception should be thrown if no
/// pull request exists or not.
/// </summary>
public bool ThrowExceptionIfPulLRequestDoesNotExist { get; set; } = true;
}
}
45 changes: 44 additions & 1 deletion src/Cake.Prca.PullRequests.Tfs/TfsPullRequestSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,13 @@ public TfsPullRequestSystem(ICakeLog log, TfsPullRequestSettings settings)

if (this.pullRequest == null)
{
throw new PrcaException("Could not find pull request");
if (this.settings.ThrowExceptionIfPulLRequestDoesNotExist)
{
throw new PrcaException("Could not find pull request");
}

this.Log.Warning("Could not find pull request");
return;
}

this.Log.Verbose(
Expand All @@ -94,6 +100,11 @@ public TfsPullRequestSystem(ICakeLog log, TfsPullRequestSettings settings)
/// <inheritdoc/>
public override IEnumerable<IPrcaDiscussionThread> FetchActiveDiscussionThreads(string commentSource)
{
if (!this.ValidatePullRequest())
{
return new List<IPrcaDiscussionThread>();
}

using (var gitClient = this.CreateGitClient())
{
var request =
Expand Down Expand Up @@ -124,6 +135,11 @@ public override IEnumerable<IPrcaDiscussionThread> FetchActiveDiscussionThreads(
/// <inheritdoc/>
public override IEnumerable<FilePath> GetModifiedFilesInPullRequest()
{
if (!this.ValidatePullRequest())
{
return new List<FilePath>();
}

this.Log.Verbose("Computing the list of files changed in this pull request...");

var targetVersionDescriptor = new GitTargetVersionDescriptor
Expand Down Expand Up @@ -176,6 +192,11 @@ public override void MarkThreadsAsFixed(IEnumerable<IPrcaDiscussionThread> threa
// ReSharper disable once PossibleMultipleEnumeration
threads.NotNull(nameof(threads));

if (!this.ValidatePullRequest())
{
return;
}

using (var gitClient = this.CreateGitClient())
{
// ReSharper disable once PossibleMultipleEnumeration
Expand Down Expand Up @@ -203,6 +224,11 @@ public override void PostDiscussionThreads(IEnumerable<ICodeAnalysisIssue> issue
// ReSharper disable once PossibleMultipleEnumeration
issues.NotNull(nameof(issues));

if (!this.ValidatePullRequest())
{
return;
}

using (var gitClient = this.CreateGitClient())
{
// ReSharper disable once PossibleMultipleEnumeration
Expand Down Expand Up @@ -247,6 +273,23 @@ public override void PostDiscussionThreads(IEnumerable<ICodeAnalysisIssue> issue
properties.Add("Microsoft.VisualStudio.Services.CodeReview.ChangeTrackingId", changeTrackingId);
}

/// <summary>
/// Validates if a pull request could be found.
/// Depending on <see cref="TfsPullRequestSettings.ThrowExceptionIfPulLRequestDoesNotExist"/>
/// the pull request instance can be null for subsequent calls.
/// </summary>
/// <returns>True if a valid pull request instance exists.</returns>
private bool ValidatePullRequest()
{
if (this.pullRequest != null)
{
return true;
}

this.Log.Verbose("Skipping, since no pull request instance could be found.");
return false;
}

private GitHttpClient CreateGitClient()
{
var connection =
Expand Down

0 comments on commit eb103bc

Please sign in to comment.