From 6982fcc777a1cd31d344c7607f2eb3485db320bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Gr=C3=BCnwald?= Date: Fri, 3 Jan 2025 12:11:25 +0100 Subject: [PATCH] Undo breaking change to AzurePipelinesPullRequestInfo.Id property and 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 --- .../Data/AzurePipelinesPullRequestInfoTests.cs | 18 +++++++++++++++++- .../Data/AzurePipelinesPullRequestInfo.cs | 14 ++++++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/Cake.Common.Tests/Unit/Build/AzurePipelines/Data/AzurePipelinesPullRequestInfoTests.cs b/src/Cake.Common.Tests/Unit/Build/AzurePipelines/Data/AzurePipelinesPullRequestInfoTests.cs index e0b95cd2ed..83f832f0b7 100644 --- a/src/Cake.Common.Tests/Unit/Build/AzurePipelines/Data/AzurePipelinesPullRequestInfoTests.cs +++ b/src/Cake.Common.Tests/Unit/Build/AzurePipelines/Data/AzurePipelinesPullRequestInfoTests.cs @@ -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)] @@ -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); diff --git a/src/Cake.Common/Build/AzurePipelines/Data/AzurePipelinesPullRequestInfo.cs b/src/Cake.Common/Build/AzurePipelines/Data/AzurePipelinesPullRequestInfo.cs index cf1742e6c2..dea6c332fc 100644 --- a/src/Cake.Common/Build/AzurePipelines/Data/AzurePipelinesPullRequestInfo.cs +++ b/src/Cake.Common/Build/AzurePipelines/Data/AzurePipelinesPullRequestInfo.cs @@ -32,7 +32,7 @@ public AzurePipelinesPullRequestInfo(ICakeEnvironment environment) /// /// true if the current build was started by a pull request; otherwise, false. /// - public bool IsPullRequest => Id > 0; + public bool IsPullRequest => LongId > 0; /// /// Gets the ID of the pull request that caused this build. @@ -41,7 +41,17 @@ public AzurePipelinesPullRequestInfo(ICakeEnvironment environment) /// /// The ID of the pull request that caused this build. /// - 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"); + + /// + /// 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. + /// + /// + /// The ID of the pull request that caused this build. + /// + public long LongId => GetEnvironmentLongInteger("SYSTEM_PULLREQUEST_PULLREQUESTID"); /// /// Gets the number of the pull request that caused this build.