Skip to content

Commit

Permalink
Code review
Browse files Browse the repository at this point in the history
  • Loading branch information
begonaguereca committed Nov 4, 2024
1 parent f9b3bb4 commit 2805a72
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 15 deletions.
45 changes: 32 additions & 13 deletions src/OctoshiftCLI.IntegrationTests/GhesToGithub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ public sealed class GhesToGithub : IDisposable
private readonly GithubClient _sourceGithubClient;
private readonly GithubApi _sourceGithubApi;
private readonly BlobServiceClient _blobServiceClient;
private readonly Dictionary<string, string> _tokens;
private readonly DateTime _startTime;
private readonly ArchiveUploader _archiveUploader;
private readonly string _sourceGithubToken;
private readonly string _targetGithubToken;
private readonly string _azureStorageConnectionString;

public GhesToGithub(ITestOutputHelper output)
{
Expand All @@ -36,15 +38,9 @@ public GhesToGithub(ITestOutputHelper output)

var logger = new OctoLogger(_ => { }, x => _output.WriteLine(x), _ => { }, _ => { });

var sourceGithubToken = Environment.GetEnvironmentVariable("GHES_PAT");
var targetGithubToken = Environment.GetEnvironmentVariable("GHEC_PAT");
var azureStorageConnectionString = Environment.GetEnvironmentVariable($"AZURE_STORAGE_CONNECTION_STRING_GHES_{TestHelper.GetOsName().ToUpper()}");
_tokens = new Dictionary<string, string>
{
["GH_SOURCE_PAT"] = sourceGithubToken,
["GH_PAT"] = targetGithubToken,
["AZURE_STORAGE_CONNECTION_STRING"] = azureStorageConnectionString
};
_sourceGithubToken = Environment.GetEnvironmentVariable("GHES_PAT");
_targetGithubToken = Environment.GetEnvironmentVariable("GHEC_PAT");
_azureStorageConnectionString = Environment.GetEnvironmentVariable($"AZURE_STORAGE_CONNECTION_STRING_GHES_{TestHelper.GetOsName().ToUpper()}");

_versionClient = new HttpClient();
_archiveUploader = new ArchiveUploader(_targetGithubClient, logger);
Expand All @@ -57,7 +53,7 @@ public GhesToGithub(ITestOutputHelper output)
_targetGithubClient = new GithubClient(logger, _targetGithubHttpClient, new VersionChecker(_versionClient, logger), new RetryPolicy(logger), new DateTimeProvider(), targetGithubToken);
_targetGithubApi = new GithubApi(_targetGithubClient, "https://api.github.com", new RetryPolicy(logger), _archiveUploader);

_blobServiceClient = new BlobServiceClient(azureStorageConnectionString);
_blobServiceClient = new BlobServiceClient(_azureStorageConnectionString);

_sourceHelper = new TestHelper(_output, _sourceGithubApi, _sourceGithubClient) { GithubApiBaseUrl = GHES_API_URL };
_targetHelper = new TestHelper(_output, _targetGithubApi, _targetGithubClient, _blobServiceClient);
Expand All @@ -73,11 +69,34 @@ public async Task Basic(bool useGithubStorage)
const string repo1 = "repo-1";
const string repo2 = "repo-2";

var tokens = new Dictionary<string, string> { };

if (useGithubStorage)

Check warning on line 74 in src/OctoshiftCLI.IntegrationTests/GhesToGithub.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

'if' statement can be simplified

Check warning on line 74 in src/OctoshiftCLI.IntegrationTests/GhesToGithub.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

'if' statement can be simplified

Check warning on line 74 in src/OctoshiftCLI.IntegrationTests/GhesToGithub.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

'if' statement can be simplified
{
tokens = new Dictionary<string, string>
{
["GH_SOURCE_PAT"] = _sourceGithubToken,
["GH_PAT"] = _targetGithubToken,
};
}
else
{
tokens = new Dictionary<string, string>
{
["GH_SOURCE_PAT"] = _sourceGithubToken,
["GH_PAT"] = _targetGithubToken,
["AZURE_STORAGE_CONNECTION_STRING"] = _azureStorageConnectionString
};
}

var retryPolicy = new RetryPolicy(null);

await retryPolicy.Retry(async () =>
{
await _targetHelper.ResetBlobContainers();
if (!useGithubStorage)
{
await _targetHelper.ResetBlobContainers();
}
await _sourceHelper.ResetGithubTestEnvironment(githubSourceOrg);
await _targetHelper.ResetGithubTestEnvironment(githubTargetOrg);
Expand All @@ -93,7 +112,7 @@ await retryPolicy.Retry(async () =>
command += " --use-github-storage true";
}

await _targetHelper.RunGeiCliMigration(command, _tokens);
await _targetHelper.RunGeiCliMigration(command, tokens);

_targetHelper.AssertNoErrorInLogs(_startTime);

Expand Down
17 changes: 15 additions & 2 deletions src/gei/Commands/GenerateScript/GenerateScriptCommandArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,17 @@ public class GenerateScriptCommandArgs : CommandArgs

public override void Validate(OctoLogger log)
{
if (AwsBucketName.HasValue() && GhesApiUrl.IsNullOrWhiteSpace())
if (AwsBucketName.HasValue())
{
throw new OctoshiftCliException("--ghes-api-url must be specified when --aws-bucket-name is specified.");
if (GhesApiUrl.IsNullOrWhiteSpace())
{
throw new OctoshiftCliException("--ghes-api-url must be specified when --aws-bucket-name is specified.");
}

if (UseGithubStorage)
{
throw new OctoshiftCliException("The --use-github-storage flag was provided with an AWS S3 Bucket name. Archive cannot be uploaded to both locations.");
}
}

if (NoSslVerify && GhesApiUrl.IsNullOrWhiteSpace())
Expand All @@ -46,6 +54,11 @@ public override void Validate(OctoLogger log)
{
throw new OctoshiftCliException("--ghes-api-url is invalid. Please check URL before trying again.");
}

if (UseGithubStorage)
{
throw new OctoshiftCliException("--ghes-api-url must be specified when --use-github-storage is specified.");
}
}
}
}
Expand Down

0 comments on commit 2805a72

Please sign in to comment.