Skip to content

Commit a9294fc

Browse files
ap0llodevlead
authored andcommitted
Add source and target branch to GitLabCIPullRequestInfo
Add properties "SourceBranch" and "TargetBranch" to GitLabCIPullRequestInfo.
1 parent 0f21dfd commit a9294fc

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

src/Cake.Common.Tests/Fixtures/Build/GitLabCIInfoFixture.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ public GitLabCIInfoFixture(bool versionNineOrNewer = false)
6565
Environment.GetEnvironmentVariable("CI_SERVER_VERSION").Returns("8.9.0");
6666
Environment.GetEnvironmentVariable("GITLAB_USER_ID").Returns("42");
6767
Environment.GetEnvironmentVariable("GITLAB_USER_EMAIL").Returns("anthony@warwickcontrol.com");
68+
Environment.GetEnvironmentVariable("CI_MERGE_REQUEST_SOURCE_BRANCH_NAME").Returns("source-branch");
69+
Environment.GetEnvironmentVariable("CI_MERGE_REQUEST_TARGET_BRANCH_NAME").Returns("main");
6870
}
6971

7072
public GitLabCIBuildInfo CreateBuildInfo()

src/Cake.Common.Tests/Unit/Build/GitLabCI/Data/GitLabCIPullRequestInfoTests.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,37 @@ public void Should_Return_Correct_Value()
6161
Assert.Equal(1, result);
6262
}
6363
}
64+
65+
public sealed class TheSourceBranchProperty
66+
{
67+
[Fact]
68+
public void Should_Return_Correct_Value()
69+
{
70+
// Given
71+
var info = new GitLabCIInfoFixture().CreatePullRequestInfo();
72+
73+
// When
74+
var result = info.SourceBranch;
75+
76+
// Then
77+
Assert.Equal("source-branch", result);
78+
}
79+
}
80+
81+
public sealed class TheTargetBranchProperty
82+
{
83+
[Fact]
84+
public void Should_Return_Correct_Value()
85+
{
86+
// Given
87+
var info = new GitLabCIInfoFixture().CreatePullRequestInfo();
88+
89+
// When
90+
var result = info.TargetBranch;
91+
92+
// Then
93+
Assert.Equal("main", result);
94+
}
95+
}
6496
}
6597
}

src/Cake.Common/Build/GitLabCI/Data/GitLabCIPullRequestInfo.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,21 @@ public GitLabCIPullRequestInfo(ICakeEnvironment environment)
4343
/// The pull request id.
4444
/// </value>
4545
public int IId => GetEnvironmentInteger("CI_MERGE_REQUEST_IID");
46+
47+
/// <summary>
48+
/// Gets the source branch of the pull request.
49+
/// </summary>
50+
/// <value>
51+
/// The source branch of the pull request.
52+
/// </value>
53+
public string SourceBranch => GetEnvironmentString("CI_MERGE_REQUEST_SOURCE_BRANCH_NAME");
54+
55+
/// <summary>
56+
/// Gets the target branch of the pull request.
57+
/// </summary>
58+
/// <value>
59+
/// The target branch name of the pull request.
60+
/// </value>
61+
public string TargetBranch => GetEnvironmentString("CI_MERGE_REQUEST_TARGET_BRANCH_NAME");
4662
}
4763
}

0 commit comments

Comments
 (0)