Skip to content

Commit 3815de8

Browse files
committed
Fixing b dependencies update.
1 parent 4b27b8a commit 3815de8

File tree

3 files changed

+40
-24
lines changed

3 files changed

+40
-24
lines changed

src/PostSharp.Engineering.BuildTools/ContinuousIntegration/TeamCityClient.cs

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,6 @@ public bool TryGetBranchFromBuildNumber( ConsoleHelper console, CiBuildId buildI
9393

9494
branch = build.Attribute( "branchName" )!.Value;
9595

96-
const string prefix = "refs/heads/";
97-
98-
if ( branch.StartsWith( prefix, StringComparison.OrdinalIgnoreCase ) )
99-
{
100-
branch = branch.Substring( prefix.Length );
101-
}
102-
10396
if ( string.IsNullOrEmpty( branch ) )
10497
{
10598
console.WriteError( $"Cannot determine the branch of '{buildId}': the branch name is empty." );
@@ -150,11 +143,10 @@ IEnumerable<DownloadedFile> GetFiles( string urlOrPath, string targetDirectory )
150143
.ToArray();
151144

152145
IEnumerable<(string Name, string Url, long Size)> files = artifacts
153-
.Select(
154-
a => (
155-
a.Name,
156-
a.Element.Element( "content" )?.Attribute( "href" )?.Value,
157-
long.Parse( a.Element.Attribute( "size" )?.Value ?? "0", NumberStyles.Integer, CultureInfo.InvariantCulture )) )
146+
.Select( a => (
147+
a.Name,
148+
a.Element.Element( "content" )?.Attribute( "href" )?.Value,
149+
long.Parse( a.Element.Attribute( "size" )?.Value ?? "0", NumberStyles.Integer, CultureInfo.InvariantCulture )) )
158150
.Where( a => a.Value != null )
159151
.Select( a => (a.Name, a.Value!, a.Item3) );
160152

@@ -347,10 +339,13 @@ private bool TryGetDetails( ConsoleHelper console, string path )
347339

348340
public bool TryGetProjectDetails( ConsoleHelper console, string id ) => this.TryGetDetails( console, $"/app/rest/projects/id:{id}" );
349341

350-
public bool TryGetOrderedSubprojectsRecursively( ConsoleHelper console, string projectId, [NotNullWhen( true )] out IReadOnlyList<(string Id, string Name)>? subprojects )
342+
public bool TryGetOrderedSubprojectsRecursively(
343+
ConsoleHelper console,
344+
string projectId,
345+
[NotNullWhen( true )] out IReadOnlyList<(string Id, string Name)>? subprojects )
351346
{
352347
subprojects = null;
353-
348+
354349
if ( !this.TryGet( $"/app/rest/projects/id:{projectId}", console, out var projectResponse ) )
355350
{
356351
return false;
@@ -362,7 +357,7 @@ public bool TryGetOrderedSubprojectsRecursively( ConsoleHelper console, string p
362357
projectRootElement.Element( "projects" )!.Attribute( "count" )!.Value,
363358
NumberStyles.Integer,
364359
CultureInfo.InvariantCulture );
365-
360+
366361
var subprojectsList = new List<(string, string)>();
367362

368363
if ( expectedCount > 0 )
@@ -419,13 +414,16 @@ public bool TryGetOrderedSubprojectsRecursively( ConsoleHelper console, string p
419414
{
420415
throw new InvalidOperationException( "Not all subprojects have been retrieved." );
421416
}
422-
417+
423418
subprojects = subprojectsList.ToImmutableArray();
424419

425420
return true;
426421
}
427422

428-
public bool TryGetProjectsBuildConfigurations( ConsoleHelper console, string projectId, [NotNullWhen( true )] out ImmutableArray<string>? buildConfigurations )
423+
public bool TryGetProjectsBuildConfigurations(
424+
ConsoleHelper console,
425+
string projectId,
426+
[NotNullWhen( true )] out ImmutableArray<string>? buildConfigurations )
429427
{
430428
int? expectedCount = null;
431429
buildConfigurations = null;
@@ -442,7 +440,10 @@ public bool TryGetProjectsBuildConfigurations( ConsoleHelper console, string pro
442440

443441
var buildConfigurationsRootsElement = buildConfigurationsResponse.Content.ReadAsXDocument().Root!;
444442

445-
var newExpectedCount = int.Parse( buildConfigurationsRootsElement.Attribute( "count" )!.Value, NumberStyles.Integer, CultureInfo.InvariantCulture );
443+
var newExpectedCount = int.Parse(
444+
buildConfigurationsRootsElement.Attribute( "count" )!.Value,
445+
NumberStyles.Integer,
446+
CultureInfo.InvariantCulture );
446447

447448
if ( expectedCount == null )
448449
{
@@ -476,8 +477,11 @@ public bool TryGetProjectsBuildConfigurations( ConsoleHelper console, string pro
476477

477478
return true;
478479
}
479-
480-
public bool TryGetBuildConfigurationsSnapshotDependencies( ConsoleHelper console, string buildConfigurationId, [NotNullWhen( true )] out ImmutableArray<string>? snapshotDependencies )
480+
481+
public bool TryGetBuildConfigurationsSnapshotDependencies(
482+
ConsoleHelper console,
483+
string buildConfigurationId,
484+
[NotNullWhen( true )] out ImmutableArray<string>? snapshotDependencies )
481485
{
482486
int? expectedCount = null;
483487
snapshotDependencies = null;
@@ -494,7 +498,10 @@ public bool TryGetBuildConfigurationsSnapshotDependencies( ConsoleHelper console
494498

495499
var snapshotDependenciesRootsElement = snapshotDependenciesResponse.Content.ReadAsXDocument().Root!;
496500

497-
var newExpectedCount = int.Parse( snapshotDependenciesRootsElement.Attribute( "count" )!.Value, NumberStyles.Integer, CultureInfo.InvariantCulture );
501+
var newExpectedCount = int.Parse(
502+
snapshotDependenciesRootsElement.Attribute( "count" )!.Value,
503+
NumberStyles.Integer,
504+
CultureInfo.InvariantCulture );
498505

499506
if ( expectedCount == null )
500507
{
@@ -528,7 +535,7 @@ public bool TryGetBuildConfigurationsSnapshotDependencies( ConsoleHelper console
528535

529536
return true;
530537
}
531-
538+
532539
public bool TryCreateProject( ConsoleHelper console, string name, string id, string? parentId = null )
533540
{
534541
parentId ??= "_Root";

src/PostSharp.Engineering.BuildTools/Dependencies/DependenciesHelper.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ private static bool ResolveBuildNumbersFromBranches(
330330
}
331331
else if ( buildId != null )
332332
{
333-
// We already have an resolved reference, but we need to update.
333+
// We already have a resolved reference, but we need to update.
334334
// In this case, we do not change the BuildIdType.
335335

336336
ciBuildType = buildId.BuildTypeId ?? dependency.Dependency.CiConfiguration.BuildTypes[configuration];
@@ -340,6 +340,15 @@ private static bool ResolveBuildNumbersFromBranches(
340340
return false;
341341
}
342342

343+
// Normalize the branch prefix.
344+
const string prefix = "refs/heads/";
345+
346+
if ( previousBranchName.StartsWith( prefix, StringComparison.OrdinalIgnoreCase )
347+
&& !dependency.Dependency.Branch.StartsWith( prefix, StringComparison.OrdinalIgnoreCase ) )
348+
{
349+
previousBranchName = previousBranchName.Substring( prefix.Length );
350+
}
351+
343352
branchName = previousBranchName;
344353
}
345354
else

src/PostSharp.Engineering.BuildTools/Dependencies/Model/DependencyDefinition.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public class DependencyDefinition
6060
public VcsRepository VcsRepository { get; }
6161

6262
public ParametricString PrivateArtifactsDirectory { get; init; } = Path.Combine( "artifacts", "publish", "private" );
63-
63+
6464
public ParametricString PublicArtifactsDirectory { get; init; } = Path.Combine( "artifacts", "publish", "public" );
6565

6666
/// <summary>

0 commit comments

Comments
 (0)