Skip to content

Commit 461ac95

Browse files
authored
Merge branch 'main' into brianaj/external-pr-1452
2 parents a48c5f0 + 7f43924 commit 461ac95

File tree

7 files changed

+86
-21
lines changed

7 files changed

+86
-21
lines changed

RELEASENOTES.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
- Added support for linux-arm64 architecture for all CLI binaries (gei, ado2gh, bbs2gh), enabling users to run GEI on ARM-based systems including MacOS with Apple Silicon inside ARC runners
2-
- Added support for configurable multipart upload chunk size for GitHub-owned storage uploads via `GITHUB_OWNED_STORAGE_MULTIPART_MEBIBYTES` environment variable (minimum 5 MiB, default 100 MiB) to improve upload reliability in environments with proxies or slow connections
2+
- Fixed issue where alert migration commands (migrate-code-scanning-alerts, migrate-secret-alerts) required GH_PAT environment variable even when GitHub tokens were provided via command-line arguments (--github-source-pat, --github-target-pat). These commands now work correctly with CLI-only token authentication.
3+
- Added support for configurable multipart upload chunk size for GitHub-owned storage uploads via `GITHUB_OWNED_STORAGE_MULTIPART_MEBIBYTES` environment variable (minimum 5 MiB, default 100 MiB) to improve upload reliability in environments with proxies or slow connections

src/OctoshiftCLI.Tests/gei/Commands/MigrateCodeScanningAlerts/MigrateCodeScanningAlertsCommandTests.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public void Should_Have_Options()
4949
}
5050

5151
[Fact]
52-
public void Source_Pat_Should_Default_To_Target_Pat()
52+
public void Should_Pass_Target_Pat_From_Cli_Args_To_Factory()
5353
{
5454
var targetToken = "target-token";
5555

@@ -66,4 +66,25 @@ public void Source_Pat_Should_Default_To_Target_Pat()
6666

6767
_mockCodeScanningAlertServiceFactory.Verify(m => m.Create(It.IsAny<string>(), targetToken, It.IsAny<string>(), targetToken, It.IsAny<bool>()));
6868
}
69+
70+
[Fact]
71+
public void Should_Pass_Source_Pat_From_Cli_Args_To_Factory()
72+
{
73+
var sourceToken = "source-token";
74+
var targetToken = "target-token";
75+
76+
var args = new MigrateCodeScanningAlertsCommandArgs()
77+
{
78+
SourceOrg = "source-org",
79+
SourceRepo = "source-repo",
80+
TargetOrg = "target-org",
81+
TargetRepo = "target-repo",
82+
GithubSourcePat = sourceToken,
83+
GithubTargetPat = targetToken,
84+
};
85+
86+
_command.BuildHandler(args, _serviceProvider);
87+
88+
_mockCodeScanningAlertServiceFactory.Verify(m => m.Create(It.IsAny<string>(), sourceToken, It.IsAny<string>(), targetToken, It.IsAny<bool>()));
89+
}
6990
}

src/OctoshiftCLI.Tests/gei/Commands/MigrateSecretAlerts/MigrateSecretAlertsCommandTests.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public void Should_Have_Options()
4949
}
5050

5151
[Fact]
52-
public void Source_Pat_Should_Default_To_Target_Pat()
52+
public void Should_Pass_Target_Pat_From_Cli_Args_To_Factory()
5353
{
5454
var targetToken = "target-token";
5555

@@ -66,4 +66,25 @@ public void Source_Pat_Should_Default_To_Target_Pat()
6666

6767
_mockSecretScanningAlertServiceFactory.Verify(m => m.Create(It.IsAny<string>(), targetToken, It.IsAny<string>(), targetToken, It.IsAny<bool>()));
6868
}
69+
70+
[Fact]
71+
public void Should_Pass_Source_Pat_From_Cli_Args_To_Factory()
72+
{
73+
var sourceToken = "source-token";
74+
var targetToken = "target-token";
75+
76+
var args = new MigrateSecretAlertsCommandArgs()
77+
{
78+
SourceOrg = "source-org",
79+
SourceRepo = "source-repo",
80+
TargetOrg = "target-org",
81+
TargetRepo = "target-repo",
82+
GithubSourcePat = sourceToken,
83+
GithubTargetPat = targetToken,
84+
};
85+
86+
_command.BuildHandler(args, _serviceProvider);
87+
88+
_mockSecretScanningAlertServiceFactory.Verify(m => m.Create(It.IsAny<string>(), sourceToken, It.IsAny<string>(), targetToken, It.IsAny<bool>()));
89+
}
6990
}

src/gei/Commands/MigrateCodeScanningAlerts/MigrateCodeScanningAlertsCommand.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,7 @@ public override MigrateCodeScanningAlertsCommandHandler BuildHandler(MigrateCode
7878
throw new ArgumentNullException(nameof(sp));
7979
}
8080

81-
var environmentVariableProvider = sp.GetRequiredService<EnvironmentVariableProvider>();
82-
args.GithubSourcePat ??= environmentVariableProvider.SourceGithubPersonalAccessToken(false);
83-
args.GithubTargetPat ??= environmentVariableProvider.TargetGithubPersonalAccessToken();
84-
81+
// The factory handles environment variable resolution
8582
if (args.GithubSourcePat.IsNullOrWhiteSpace())
8683
{
8784
args.GithubSourcePat = args.GithubTargetPat;

src/gei/Commands/MigrateSecretAlerts/MigrateSecretAlertsCommand.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,7 @@ public override MigrateSecretAlertsCommandHandler BuildHandler(MigrateSecretAler
7878
throw new ArgumentNullException(nameof(sp));
7979
}
8080

81-
var environmentVariableProvider = sp.GetRequiredService<EnvironmentVariableProvider>();
82-
args.GithubSourcePat ??= environmentVariableProvider.SourceGithubPersonalAccessToken(false);
83-
args.GithubTargetPat ??= environmentVariableProvider.TargetGithubPersonalAccessToken();
84-
81+
// The factory handles environment variable resolution
8582
if (args.GithubSourcePat.IsNullOrWhiteSpace())
8683
{
8784
args.GithubSourcePat = args.GithubTargetPat;

src/gei/Factories/CodeScanningAlertServiceFactory.cs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,27 @@ public CodeScanningAlertServiceFactory(
2525
public virtual CodeScanningAlertService
2626
Create(string sourceApi, string sourceToken, string targetApi, string targetToken, bool sourceApiNoSsl = false)
2727
{
28-
sourceToken ??= _environmentVariableProvider.SourceGithubPersonalAccessToken();
29-
targetToken ??= _environmentVariableProvider.TargetGithubPersonalAccessToken();
28+
// Only resolve from environment if tokens are explicitly null
29+
// Use consistent throwIfNotFound=false to prevent exceptions when CLI args are preferred
30+
sourceToken ??= _environmentVariableProvider.SourceGithubPersonalAccessToken(false);
31+
32+
targetToken ??= _environmentVariableProvider.TargetGithubPersonalAccessToken(false);
33+
34+
// Validate that we have tokens after all resolution attempts
35+
if (string.IsNullOrWhiteSpace(sourceToken))
36+
{
37+
throw new OctoshiftCliException("Source GitHub Personal Access Token is required. Provide it via --github-source-pat argument or GH_SOURCE_PAT/GH_PAT environment variable.");
38+
}
39+
40+
if (string.IsNullOrWhiteSpace(targetToken))
41+
{
42+
throw new OctoshiftCliException("Target GitHub Personal Access Token is required. Provide it via --github-target-pat argument or GH_PAT environment variable.");
43+
}
3044

3145
var sourceGithubApi = sourceApiNoSsl
32-
? _sourceGithubApiFactory.CreateClientNoSsl(sourceApi, sourceToken)
33-
: _sourceGithubApiFactory.Create(sourceApi, sourceToken);
46+
? _sourceGithubApiFactory.CreateClientNoSsl(sourceApi, null, sourceToken)
47+
: _sourceGithubApiFactory.Create(sourceApi, null, sourceToken);
3448

35-
return new(sourceGithubApi, _targetGithubApiFactory.Create(targetApi, targetToken), _octoLogger);
49+
return new(sourceGithubApi, _targetGithubApiFactory.Create(targetApi, null, targetToken), _octoLogger);
3650
}
3751
}

src/gei/Factories/SecretScanningAlertServiceFactory.cs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,27 @@ public SecretScanningAlertServiceFactory(
2525
public virtual SecretScanningAlertService
2626
Create(string sourceApi, string sourceToken, string targetApi, string targetToken, bool sourceApiNoSsl = false)
2727
{
28-
sourceToken ??= _environmentVariableProvider.SourceGithubPersonalAccessToken();
29-
targetToken ??= _environmentVariableProvider.TargetGithubPersonalAccessToken();
28+
// Only resolve from environment if tokens are explicitly null
29+
// Use consistent throwIfNotFound=false to prevent exceptions when CLI args are preferred
30+
sourceToken ??= _environmentVariableProvider.SourceGithubPersonalAccessToken(false);
31+
32+
targetToken ??= _environmentVariableProvider.TargetGithubPersonalAccessToken(false);
33+
34+
// Validate that we have tokens after all resolution attempts
35+
if (string.IsNullOrWhiteSpace(sourceToken))
36+
{
37+
throw new OctoshiftCliException("Source GitHub Personal Access Token is required. Provide it via --github-source-pat argument or GH_SOURCE_PAT/GH_PAT environment variable.");
38+
}
39+
40+
if (string.IsNullOrWhiteSpace(targetToken))
41+
{
42+
throw new OctoshiftCliException("Target GitHub Personal Access Token is required. Provide it via --github-target-pat argument or GH_PAT environment variable.");
43+
}
3044

3145
var sourceGithubApi = sourceApiNoSsl
32-
? _sourceGithubApiFactory.CreateClientNoSsl(sourceApi, sourceToken)
33-
: _sourceGithubApiFactory.Create(sourceApi, sourceToken);
46+
? _sourceGithubApiFactory.CreateClientNoSsl(sourceApi, null, sourceToken)
47+
: _sourceGithubApiFactory.Create(sourceApi, null, sourceToken);
3448

35-
return new(sourceGithubApi, _targetGithubApiFactory.Create(targetApi, targetToken), _octoLogger);
49+
return new(sourceGithubApi, _targetGithubApiFactory.Create(targetApi, null, targetToken), _octoLogger);
3650
}
3751
}

0 commit comments

Comments
 (0)