Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add source and target branch to GitLabCIPullRequestInfo (#4416) #4417

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Cake.Common.Tests/Fixtures/Build/GitLabCIInfoFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ public GitLabCIInfoFixture(bool versionNineOrNewer = false)
Environment.GetEnvironmentVariable("CI_SERVER_VERSION").Returns("8.9.0");
Environment.GetEnvironmentVariable("GITLAB_USER_ID").Returns("42");
Environment.GetEnvironmentVariable("GITLAB_USER_EMAIL").Returns("anthony@warwickcontrol.com");
Environment.GetEnvironmentVariable("CI_MERGE_REQUEST_SOURCE_BRANCH_NAME").Returns("source-branch");
Environment.GetEnvironmentVariable("CI_MERGE_REQUEST_TARGET_BRANCH_NAME").Returns("main");
}

public GitLabCIBuildInfo CreateBuildInfo()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,37 @@ public void Should_Return_Correct_Value()
Assert.Equal(1, result);
}
}

public sealed class TheSourceBranchProperty
{
[Fact]
public void Should_Return_Correct_Value()
{
// Given
var info = new GitLabCIInfoFixture().CreatePullRequestInfo();

// When
var result = info.SourceBranch;

// Then
Assert.Equal("source-branch", result);
}
}

public sealed class TheTargetBranchProperty
{
[Fact]
public void Should_Return_Correct_Value()
{
// Given
var info = new GitLabCIInfoFixture().CreatePullRequestInfo();

// When
var result = info.TargetBranch;

// Then
Assert.Equal("main", result);
}
}
}
}
16 changes: 16 additions & 0 deletions src/Cake.Common/Build/GitLabCI/Data/GitLabCIPullRequestInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,21 @@ public GitLabCIPullRequestInfo(ICakeEnvironment environment)
/// The pull request id.
/// </value>
public int IId => GetEnvironmentInteger("CI_MERGE_REQUEST_IID");

/// <summary>
/// Gets the source branch of the pull request.
/// </summary>
/// <value>
/// The source branch of the pull request.
/// </value>
public string SourceBranch => GetEnvironmentString("CI_MERGE_REQUEST_SOURCE_BRANCH_NAME");

/// <summary>
/// Gets the target branch of the pull request.
/// </summary>
/// <value>
/// The target branch name of the pull request.
/// </value>
public string TargetBranch => GetEnvironmentString("CI_MERGE_REQUEST_TARGET_BRANCH_NAME");
}
}
Loading