Skip to content

Commit 35f04aa

Browse files
committed
Merge branch 'release/0.2.4'
2 parents 6b13ff8 + dee1497 commit 35f04aa

File tree

11 files changed

+212
-21
lines changed

11 files changed

+212
-21
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# TFS / Azure DevOps support for Cake
1+
# Azure DevOps and Azure DevOps Server support for Cake
22

3-
This addin for Cake allows you to work with Team Foundation Server or Azure DevOps.
3+
This addin for Cake allows you to work with Azure DevOps or Azure DevOps Server.
44

55
[![License](http://img.shields.io/:license-mit-blue.svg)](https://github.com/cake-contrib/Cake.Tfs/blob/feature/build/LICENSE)
66

azure-pipelines.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
pool:
2+
vmImage: 'vs2017-win2016'
3+
4+
trigger:
5+
- develop
6+
- master
7+
- release/*
8+
- hotfix/*
9+
10+
pr:
11+
- develop
12+
13+
steps:
14+
- powershell: ./build.ps1
15+
displayName: 'Cake Build'

docs/input/docs/usage/vote-pullrequest.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Description: Example how to approve or vote for pull requests using the Cake.Tfs
55
---
66
The [Cake.Tfs addin] provides an alias for approving or voting on pull requests.
77

8-
The following example will approve a pull request on a Team Foundation Server:
8+
The following example will approve a pull request on a Azure DevOps Server:
99

1010
```csharp
1111
#addin "Cake.Tfs"

docs/input/index.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ NoGutter: true
88
<div class="container">
99
<h1>What is it?</h1>
1010
<p>
11-
The Tfs Addin for <a href="http://cakebuild.net/" target="_blank">Cake</a> allows you to access Team Foundation Server or Azure DevOps from Cake build scripts.
11+
The Azure DevOps Addin for <a href="http://cakebuild.net/" target="_blank">Cake</a> allows you to access Azure DevOps or Azure DevOps Server from Cake build scripts.
1212
</p>
1313
</div>

nuspec/nuget/Cake.Tfs.nuspec

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
<version>0.0.0</version>
77
<authors>Pascal Berger</authors>
88
<owners>pascalberger, cake-contrib</owners>
9-
<summary>Addin for working with Team Foundation Server or Azure DevOps for the Cake build automation system</summary>
9+
<summary>Addin for working with Azure DevOps or Azure DevOps Server for the Cake build automation system</summary>
1010
<description>
11-
This addin for Cake allows you to work with Team Foundation Server or Azure DevOps.
11+
This addin for Cake allows you to work with Azure DevOps or Azure DevOps Server.
1212
</description>
1313
<licenseUrl>https://github.com/cake-contrib/Cake.Tfs/blob/develop/LICENSE</licenseUrl>
1414
<projectUrl>http://cake-contrib.github.io/Cake.Tfs/</projectUrl>
@@ -17,7 +17,7 @@
1717
<repository type="git" url="https://github.com/cake-contrib/Cake.Tfs"/>
1818
<copyright>Copyright © Pascal Berger</copyright>
1919
<tags>Cake Script Team-Foundation-Server TFS Azure-DevOps</tags>
20-
<releaseNotes>https://github.com/cake-contrib/Cake.Tfs/releases/tag/0.2.3</releaseNotes>
20+
<releaseNotes>https://github.com/cake-contrib/Cake.Tfs/releases/tag/0.2.4</releaseNotes>
2121
</metadata>
2222
<files>
2323
<file src="net461\Cake.Tfs.dll" target="lib\net461" />

src/Cake.Tfs.Tests/Cake.Tfs.Tests.csproj

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,14 @@
1414
</PropertyGroup>
1515

1616
<ItemGroup>
17-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.8.0" />
17+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
1818
<PackageReference Include="Cake.Core" Version="0.28.0" />
1919
<PackageReference Include="Cake.Testing" Version="0.28.0" />
2020
<PackageReference Include="Moq" Version="4.10.0" />
21-
<PackageReference Include="Shouldly" Version="3.0.0" />
21+
<PackageReference Include="Shouldly" Version="3.0.2" />
2222
<PackageReference Include="StyleCop.Analyzers" Version="1.0.2" />
23-
<PackageReference Include="xunit" Version="2.4.0" />
24-
<PackageReference Include="xunit.abstractions" Version="2.0.2" />
25-
<PackageReference Include="xunit.assert" Version="2.4.0" />
26-
<PackageReference Include="xunit.core" Version="2.4.0" />
27-
<PackageReference Include="xunit.extensibility.core" Version="2.4.0" />
28-
<PackageReference Include="xunit.extensibility.execution" Version="2.4.0" />
29-
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
23+
<PackageReference Include="xunit" Version="2.4.1" />
24+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
3025
</ItemGroup>
3126

3227
<ItemGroup>

src/Cake.Tfs.Tests/PullRequest/Fakes/FakeAllSetGitClientFactory.cs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,43 @@ protected override Mock<GitHttpClient> Setup(Mock<GitHttpClient> m)
100100
State = status.State
101101
});
102102

103+
// Setup CommitDiffs object
104+
var gitChanges = new List<GitChange>
105+
{
106+
new GitChange
107+
{
108+
ChangeId = 1,
109+
ChangeType = VersionControlChangeType.Edit,
110+
Item = new GitItem("/src/project/myclass.cs", "ID1", GitObjectType.Commit, "6b13ff8", 0)
111+
},
112+
null,
113+
new GitChange
114+
{
115+
ChangeId = 2,
116+
ChangeType = VersionControlChangeType.Edit,
117+
Item = new GitItem("/tools/folder", "ID2", GitObjectType.Tree, "6b13ff8", 0)
118+
}
119+
};
120+
121+
var gitCommitDiffs = new GitCommitDiffs
122+
{
123+
ChangeCounts = new Dictionary<VersionControlChangeType, int> { { VersionControlChangeType.Edit, 2 } },
124+
Changes = gitChanges
125+
};
126+
127+
m.Setup(arg => arg.GetCommitDiffsAsync(
128+
It.IsAny<string>(),
129+
It.IsAny<Guid>(),
130+
true,
131+
null,
132+
null,
133+
It.IsAny<GitBaseVersionDescriptor>(),
134+
It.IsAny<GitTargetVersionDescriptor>(),
135+
null,
136+
CancellationToken.None))
137+
.ReturnsAsync((string prj, Guid rId, bool? b, int? t, int? s, GitBaseVersionDescriptor bvd, GitTargetVersionDescriptor tvd, object o1, CancellationToken c1)
138+
=> gitCommitDiffs);
139+
103140
return m;
104141
}
105142
}

src/Cake.Tfs.Tests/PullRequest/Fakes/FakeNullForMethodsGitClientFactory.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
namespace Cake.Tfs.Tests.PullRequest.Fakes
22
{
33
using System;
4+
using System.Collections.Generic;
45
using System.Threading;
56
using Microsoft.TeamFoundation.SourceControl.WebApi;
67
using Moq;
@@ -15,6 +16,10 @@ protected override Mock<GitHttpClient> Setup(Mock<GitHttpClient> m)
1516
m.Setup(arg => arg.CreatePullRequestStatusAsync(It.IsAny<GitPullRequestStatus>(), It.IsAny<Guid>(), It.IsAny<int>(), It.IsAny<object>(), It.IsAny<CancellationToken>()))
1617
.ReturnsAsync(() => null);
1718

19+
m.Setup(arg => arg.GetCommitDiffsAsync(It.IsAny<string>(), It.IsAny<Guid>(), true, null, null, It.IsAny<GitBaseVersionDescriptor>(), It.IsAny<GitTargetVersionDescriptor>(), null, CancellationToken.None))
20+
.ReturnsAsync(()
21+
=> new GitCommitDiffs { ChangeCounts = new Dictionary<VersionControlChangeType, int>(), Changes = new List<GitChange>() });
22+
1823
return m;
1924
}
2025
}

src/Cake.Tfs.Tests/PullRequest/TfsPullRequestTests.cs

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
namespace Cake.Tfs.Tests.PullRequest
22
{
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using Cake.Core.IO;
36
using Cake.Tfs.PullRequest;
47
using Cake.Tfs.Tests.PullRequest.Fakes;
58
using Microsoft.VisualStudio.Services.Common;
@@ -23,6 +26,19 @@ public void Should_Throw_If_Log_Is_Null()
2326
result.IsArgumentNullException("log");
2427
}
2528

29+
[Fact]
30+
public void Should_Throw_If_Log_Is_Null_Overload()
31+
{
32+
// Given
33+
var fixture = new PullRequestFixture(PullRequestFixture.ValidTfsUrl, "foo") { Log = null };
34+
35+
// When
36+
var result = Record.Exception(() => new TfsPullRequest(fixture.Log, fixture.Settings));
37+
38+
// Then
39+
result.IsArgumentNullException("log");
40+
}
41+
2642
[Fact]
2743
public void Should_Throw_If_Settings_Are_Null()
2844
{
@@ -36,6 +52,19 @@ public void Should_Throw_If_Settings_Are_Null()
3652
result.IsArgumentNullException("settings");
3753
}
3854

55+
[Fact]
56+
public void Should_Throw_If_Settings_Are_Null_Overload()
57+
{
58+
// Given
59+
var fixture = new PullRequestFixture(PullRequestFixture.ValidTfsUrl, 42) { Settings = null };
60+
61+
// When
62+
var result = Record.Exception(() => new TfsPullRequest(fixture.Log, fixture.Settings));
63+
64+
// Then
65+
result.IsArgumentNullException("settings");
66+
}
67+
3968
[Fact]
4069
public void Should_Throw_If_Git_Client_Factory_Is_Null()
4170
{
@@ -421,5 +450,46 @@ public void Should_Throw_If_Null_Is_Returned_On_Tfs_Pull_Request()
421450
result.IsTfsPullRequestNotFoundException();
422451
}
423452
}
453+
454+
public sealed class GetModifiedFiles
455+
{
456+
[Fact]
457+
public void Should_Return_Empty_Collection_If_No_Changes_Found()
458+
{
459+
// Given
460+
var fixture = new PullRequestFixture(PullRequestFixture.ValidTfsUrl, 42) { GitClientFactory = new FakeNullForMethodsGitClientFactory() };
461+
var pullRequest = new TfsPullRequest(fixture.Log, fixture.Settings, fixture.GitClientFactory);
462+
463+
// When
464+
var files = pullRequest.GetModifiedFiles();
465+
466+
// Then
467+
files.ShouldBeOfType<List<FilePath>>();
468+
files.ShouldNotBeNull();
469+
files.ShouldBeEmpty();
470+
}
471+
472+
[Fact]
473+
public void Should_Return_Valid_Collection_Of_Modified_Files()
474+
{
475+
// Given
476+
var fixture = new PullRequestFixture(PullRequestFixture.ValidTfsUrl, 42);
477+
var pullRequest = new TfsPullRequest(fixture.Log, fixture.Settings, fixture.GitClientFactory);
478+
479+
// When
480+
var files = pullRequest.GetModifiedFiles();
481+
482+
// Then
483+
files.ShouldNotBeNull();
484+
files.ShouldNotBeEmpty();
485+
files.ShouldHaveSingleItem();
486+
487+
var filePath = files.First();
488+
filePath.ShouldBeOfType<FilePath>();
489+
filePath.ShouldNotBeNull();
490+
filePath.FullPath.ShouldNotBeEmpty();
491+
filePath.FullPath.ShouldBe("src/project/myclass.cs");
492+
}
493+
}
424494
}
425495
}

src/Cake.Tfs/Cake.Tfs.csproj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@
2323

2424
<ItemGroup>
2525
<PackageReference Include="Cake.Core" Version="0.28.0" />
26-
<PackageReference Include="Costura.Fody" Version="3.1.0" />
27-
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.6.1" />
28-
<PackageReference Include="Microsoft.TeamFoundationServer.Client" Version="15.112.1" />
29-
<PackageReference Include="Microsoft.VisualStudio.Services.InteractiveClient" Version="15.112.1" />
26+
<PackageReference Include="Costura.Fody" Version="3.1.6" />
27+
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.6.2" />
28+
<PackageReference Include="Microsoft.TeamFoundationServer.Client" Version="15.131.1" />
29+
<PackageReference Include="Microsoft.VisualStudio.Services.InteractiveClient" Version="15.131.1" />
3030
<PackageReference Include="StyleCop.Analyzers" Version="1.0.2" />
31-
<PackageReference Include="TfsUrlParser" Version="1.2.0" />
31+
<PackageReference Include="TfsUrlParser" Version="1.3.0" />
3232
</ItemGroup>
3333

3434
</Project>

src/Cake.Tfs/PullRequest/TfsPullRequest.cs

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
namespace Cake.Tfs.PullRequest
22
{
33
using System;
4+
using System.Collections.Generic;
45
using System.Linq;
56
using System.Threading;
67
using Cake.Core.Diagnostics;
8+
using Cake.Core.IO;
79
using Cake.Tfs;
810
using Microsoft.TeamFoundation.SourceControl.WebApi;
911
using TfsUrlParser;
@@ -19,6 +21,18 @@ public sealed class TfsPullRequest
1921
private readonly RepositoryDescription repositoryDescription;
2022
private readonly GitPullRequest pullRequest;
2123

24+
/// <summary>
25+
/// Initializes a new instance of the <see cref="TfsPullRequest"/> class.
26+
/// </summary>
27+
/// <param name="log">The Cake log context.</param>
28+
/// <param name="settings">Settings for accessing TFS.</param>
29+
/// <exception cref="TfsPullRequestNotFoundException">If <see cref="TfsPullRequestSettings.ThrowExceptionIfPullRequestCouldNotBeFound"/>
30+
/// is set to <c>true</c> and no pull request could be found.</exception>
31+
public TfsPullRequest(ICakeLog log, TfsPullRequestSettings settings)
32+
: this(log, settings, new GitClientFactory())
33+
{
34+
}
35+
2236
/// <summary>
2337
/// Initializes a new instance of the <see cref="TfsPullRequest"/> class.
2438
/// </summary>
@@ -380,6 +394,61 @@ public void SetStatus(TfsPullRequestStatus status)
380394
}
381395
}
382396

397+
/// <summary>
398+
/// Gets the files modified by the pull request.
399+
/// </summary>
400+
/// <returns>The collection of the modified files paths.</returns>
401+
public IEnumerable<FilePath> GetModifiedFiles()
402+
{
403+
if (!this.ValidatePullRequest())
404+
{
405+
return new List<FilePath>();
406+
}
407+
408+
var targetVersionDescriptor = new GitTargetVersionDescriptor
409+
{
410+
VersionType = GitVersionType.Commit,
411+
Version = this.LastSourceCommitId
412+
};
413+
414+
var baseVersionDescriptor = new GitBaseVersionDescriptor
415+
{
416+
VersionType = GitVersionType.Commit,
417+
Version = this.LastTargetCommitId
418+
};
419+
420+
using (var gitClient = this.gitClientFactory.CreateGitClient(this.CollectionUrl, this.settings.Credentials))
421+
{
422+
var commitDiffs = gitClient.GetCommitDiffsAsync(
423+
this.ProjectName,
424+
this.RepositoryId,
425+
true, // bool? diffCommonCommit
426+
null, // int? top
427+
null, // int? skip
428+
baseVersionDescriptor,
429+
targetVersionDescriptor,
430+
null, // object userState
431+
CancellationToken.None).Result;
432+
433+
this.log.Verbose(
434+
"Found {0} changed file(s) in the pull request",
435+
commitDiffs.Changes.Count());
436+
437+
if (!commitDiffs.ChangeCounts.Any())
438+
{
439+
return new List<FilePath>();
440+
}
441+
442+
return
443+
from change in commitDiffs.Changes
444+
where
445+
change != null &&
446+
!change.Item.IsFolder
447+
select
448+
new FilePath(change.Item.Path.TrimStart('/'));
449+
}
450+
}
451+
383452
/// <summary>
384453
/// Validates if a pull request could be found.
385454
/// Depending on <see cref="TfsPullRequestSettings.ThrowExceptionIfPullRequestCouldNotBeFound"/>

0 commit comments

Comments
 (0)