Skip to content

Commit

Permalink
Undo breaking change to AzurePipelinesPullRequestInfo.Id property and…
Browse files Browse the repository at this point in the history
… introduce second property for the Id instead

As suggested during review, avoid a breaking change and revert the type of the AzurePipelinesPullRequestInfo.Id property back to int and instad introduce a second "LongId" property for ids exceeding int.MaxValue
  • Loading branch information
ap0llo committed Jan 3, 2025
1 parent e520060 commit 6982fcc
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,22 @@ public void Should_Return_Correct_Value(string value, bool expected)
}

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

// When
var result = info.Id;

// Then
Assert.Equal(1, result);
}
}

public sealed class TheLongIdProperty
{
[Theory]
[InlineData("1", 1)]
Expand All @@ -45,7 +61,7 @@ public void Should_Return_Correct_Value(string value, long expected)
var info = fixture.CreatePullRequestInfo();

// When
var result = info.Id;
var result = info.LongId;

// Then
Assert.Equal(expected, result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public AzurePipelinesPullRequestInfo(ICakeEnvironment environment)
/// <value>
/// <c>true</c> if the current build was started by a pull request; otherwise, <c>false</c>.
/// </value>
public bool IsPullRequest => Id > 0;
public bool IsPullRequest => LongId > 0;

/// <summary>
/// Gets the ID of the pull request that caused this build.
Expand All @@ -41,7 +41,17 @@ public AzurePipelinesPullRequestInfo(ICakeEnvironment environment)
/// <value>
/// The ID of the pull request that caused this build.
/// </value>
public long Id => GetEnvironmentLongInteger("SYSTEM_PULLREQUEST_PULLREQUESTID");
[Obsolete("Type will change in next major version to long, meanwhile use LongId to ensure proper value returned.")]
public int Id => GetEnvironmentInteger("SYSTEM_PULLREQUEST_PULLREQUESTID");

/// <summary>
/// Gets the ID of the pull request that caused this build.
/// This value is set only if the build ran because of a Git PR affected by a branch policy.
/// </summary>
/// <value>
/// The ID of the pull request that caused this build.
/// </value>
public long LongId => GetEnvironmentLongInteger("SYSTEM_PULLREQUEST_PULLREQUESTID");

/// <summary>
/// Gets the number of the pull request that caused this build.
Expand Down

0 comments on commit 6982fcc

Please sign in to comment.