Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FINAL: Git storage option feature #1279

Open
wants to merge 112 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
112 commits
Select commit Hold shift + click to select a range
781b6de
Add use-github-storage option
begonaguereca Sep 25, 2024
5d36e96
Add validation to useGitHubStorage option
begonaguereca Sep 25, 2024
aab0557
Add UploadArchiveToGithubStorageWithMultiPart method
begonaguereca Sep 25, 2024
a8797ca
Update src/bbs2gh/Commands/MigrateRepo/MigrateRepoCommand.cs
begonaguereca Sep 27, 2024
95844ea
Update src/gei/Commands/MigrateRepo/MigrateRepoCommand.cs
begonaguereca Sep 27, 2024
1a5e198
Merge pull request #1269 from github/gso-option
begonaguereca Sep 27, 2024
420db29
Updated logic to account for Azure storage connection string
begonaguereca Sep 30, 2024
ffc3e21
Merge pull request #1270 from github/gso-option-validation
begonaguereca Sep 30, 2024
1fca83d
Make changes to SendAsync command
begonaguereca Oct 8, 2024
f81e02a
remove backslashed
begonaguereca Oct 8, 2024
2c8de4a
Escape string
begonaguereca Oct 8, 2024
619e6da
Merge branch 'main' into github-api-upload
begonaguereca Oct 8, 2024
bf5eef2
Fixing unit tests
begonaguereca Oct 8, 2024
60e9ed1
alphabetical order
begonaguereca Oct 8, 2024
cd88309
clean up
begonaguereca Oct 8, 2024
c161de8
Merge branch 'main' into git-storage-option-feature
begonaguereca Oct 8, 2024
cd6311a
Merge branch 'github-api-upload' into git-storage-option-feature
begonaguereca Oct 8, 2024
d4e2344
Add logic for UploadArchiveToGithub
begonaguereca Oct 8, 2024
4becd72
Add AreBlobCredentialsRequired method
begonaguereca Oct 8, 2024
abd757c
formatting
begonaguereca Oct 8, 2024
adac212
formatting
begonaguereca Oct 8, 2024
a121256
formatting
begonaguereca Oct 8, 2024
5f67714
Update specs
begonaguereca Oct 8, 2024
f7ffcef
cleaned up PR
begonaguereca Oct 8, 2024
d9e9149
Add unit test for http data types
begonaguereca Oct 9, 2024
c959ccc
clean up
begonaguereca Oct 9, 2024
d9a3d0a
clean up
begonaguereca Oct 9, 2024
08fc506
remove linter ignorer
begonaguereca Oct 9, 2024
ffaf1e8
Add logic back in
begonaguereca Oct 9, 2024
c8b1d3b
Update src/Octoshift/Services/GithubApi.cs
begonaguereca Oct 9, 2024
a2784b6
Update src/Octoshift/Services/GithubClient.cs
begonaguereca Oct 9, 2024
5a61216
Update src/Octoshift/Services/GithubApi.cs
begonaguereca Oct 9, 2024
947fcab
Update src/OctoshiftCLI.Tests/Octoshift/Services/GithubClientTests.cs
begonaguereca Oct 9, 2024
ec9011c
Update src/OctoshiftCLI.Tests/Octoshift/Services/GithubClientTests.cs
begonaguereca Oct 9, 2024
f66f34a
Update src/gei/Services/GhesVersionChecker.cs
begonaguereca Oct 9, 2024
230503f
Update src/gei/Commands/MigrateRepo/MigrateRepoCommandHandler.cs
begonaguereca Oct 9, 2024
61726e2
Update src/gei/Commands/MigrateRepo/MigrateRepoCommandHandler.cs
begonaguereca Oct 9, 2024
7d85f23
Update src/gei/Commands/MigrateRepo/MigrateRepoCommandHandler.cs
begonaguereca Oct 9, 2024
b03be62
Update src/bbs2gh/Commands/MigrateRepo/MigrateRepoCommandHandler.cs
begonaguereca Oct 9, 2024
006e188
Update src/bbs2gh/Commands/MigrateRepo/MigrateRepoCommandHandler.cs
begonaguereca Oct 9, 2024
da59731
Update src/bbs2gh/Commands/MigrateRepo/MigrateRepoCommandHandler.cs
begonaguereca Oct 9, 2024
ca6c476
fix linter errors
begonaguereca Oct 9, 2024
121319c
Merge pull request #1281 from github/clean-up-specs
begonaguereca Oct 9, 2024
ffc219e
Merge branch 'git-storage-option-feature' into command-handler
begonaguereca Oct 9, 2024
85190e8
Add conditionals for clarity
begonaguereca Oct 9, 2024
2894bb8
Refactor to increase simplicity
begonaguereca Oct 10, 2024
abbbaaf
Clean up
begonaguereca Oct 10, 2024
981cd15
Clean up
begonaguereca Oct 10, 2024
e538d00
Update src/bbs2gh/Commands/MigrateRepo/MigrateRepoCommandHandler.cs
begonaguereca Oct 11, 2024
2d0a63d
Update src/OctoshiftCLI.Tests/bbs2gh/Commands/MigrateRepo/MigrateRepo…
begonaguereca Oct 11, 2024
0821922
clean up
begonaguereca Oct 11, 2024
ad111f0
Merge branch 'command-handler' of https://github.com/github/gh-gei in…
begonaguereca Oct 11, 2024
550f4b8
Update UploadArchiveToGithub method for BBS
begonaguereca Oct 11, 2024
2d06def
Update src/OctoshiftCLI.Tests/bbs2gh/Commands/MigrateRepo/MigrateRepo…
begonaguereca Oct 11, 2024
fe78726
Fix unit tests
begonaguereca Oct 11, 2024
0e532f1
Merge branch 'command-handler' of https://github.com/github/gh-gei in…
begonaguereca Oct 11, 2024
18b3c34
Test is still failing
begonaguereca Oct 11, 2024
e97303b
Fix tests
begonaguereca Oct 14, 2024
54d09b2
current
begonaguereca Oct 14, 2024
ebc9f65
Update test
begonaguereca Oct 14, 2024
92633b0
Fix GEI test
ArinGhazarian Oct 14, 2024
67f39b1
Clean up
begonaguereca Oct 14, 2024
80d5355
Update src/Octoshift/Services/GithubApi.cs
begonaguereca Oct 15, 2024
460a525
Update src/Octoshift/Services/GithubApi.cs
begonaguereca Oct 15, 2024
015ed9c
Update src/OctoshiftCLI.Tests/Octoshift/Services/GithubApiTests.cs
begonaguereca Oct 15, 2024
ae4b940
Update src/OctoshiftCLI.Tests/Octoshift/Services/GithubApiTests.cs
begonaguereca Oct 15, 2024
0099104
Addressing Arins comments
begonaguereca Oct 15, 2024
64223bb
Resolve conflicts
begonaguereca Oct 15, 2024
dbe7db2
clean up
begonaguereca Oct 15, 2024
03b7266
Update UploadArchiveToGithubStorage to have real values
begonaguereca Oct 15, 2024
fead8a7
Remove ArchiveUrl from args to be able to execute upload to github ar…
ArinGhazarian Oct 15, 2024
1d65610
Check for null argument and its unit test
ArinGhazarian Oct 15, 2024
3f04d2c
Use orgDatabaseId to avoid confusion
ArinGhazarian Oct 15, 2024
2b241a6
Merge pull request #1280 from github/command-handler
begonaguereca Oct 15, 2024
e84134e
Update to account for new payload from git storage
begonaguereca Oct 16, 2024
fb3ccd4
Got brute force multipart working
begonaguereca Oct 22, 2024
6a24f7a
Created sepreate class for multipart upload methods
begonaguereca Oct 22, 2024
99cc3fc
Address Arins comments
begonaguereca Oct 23, 2024
e2585dc
Fix build errors
begonaguereca Oct 23, 2024
6e58b5f
Add more error handling
begonaguereca Oct 24, 2024
3b3a301
Update async method names
begonaguereca Oct 24, 2024
e1eabc5
Code review
begonaguereca Oct 24, 2024
e3fff28
Commits
begonaguereca Oct 24, 2024
8fce586
Merge branch 'git-storage-multi-part' of https://github.com/github/gh…
begonaguereca Oct 24, 2024
60d6f83
Adding octet-stream logic back in
begonaguereca Oct 24, 2024
c949795
Fix multipart upload test
begonaguereca Oct 25, 2024
ffaf286
Update src/Octoshift/Services/GithubApi.cs
begonaguereca Oct 25, 2024
cbc0d1b
Update src/Octoshift/Services/MultipartUploaderService.cs
begonaguereca Oct 25, 2024
a7eae8b
Added logging to the multipart logic
begonaguereca Oct 25, 2024
099cfda
Refactor mutlipartuploaderserice to include logic for all uploads
begonaguereca Oct 25, 2024
066bd38
Add integration tests
begonaguereca Oct 28, 2024
502d7a2
Update src/Octoshift/Services/MultipartUploaderService.cs
begonaguereca Oct 28, 2024
8d594a3
Update src/Octoshift/Services/MultipartUploaderService.cs
begonaguereca Oct 28, 2024
156cc07
PR review
begonaguereca Oct 28, 2024
4b4d605
Passing in null to methods that dont need archive uploader logic
begonaguereca Oct 28, 2024
0e8093b
Add archive uploader tests
begonaguereca Oct 29, 2024
6533c7a
read as buffer and dont convert to memory
begonaguereca Oct 29, 2024
090547a
Merge pull request #1288 from github/git-storage-option-integration-t…
begonaguereca Oct 29, 2024
0cba519
Simpligy GithubApiTests for multipart logic
begonaguereca Oct 29, 2024
c93e44d
Add a test for multipart upload
ArinGhazarian Oct 29, 2024
ce20d20
Linting
ArinGhazarian Oct 29, 2024
ede2cd8
Code reiview + bug fix
begonaguereca Oct 30, 2024
958007b
Fix unit test
begonaguereca Oct 30, 2024
c37a19c
Update src/Octoshift/Services/ArchiveUploader.cs
begonaguereca Oct 30, 2024
2bade7a
Update src/OctoshiftCLI.Tests/Octoshift/Services/GithubApiTests.cs
begonaguereca Oct 30, 2024
eae73c0
Update name of test
begonaguereca Oct 30, 2024
e50309b
remove extra test
begonaguereca Oct 30, 2024
451ed8d
Merge pull request #1285 from github/git-storage-multi-part
begonaguereca Oct 30, 2024
8167f2f
linter
begonaguereca Oct 30, 2024
47dbcb4
Modify BBS int test
begonaguereca Oct 30, 2024
0b3948d
test GHES
begonaguereca Oct 30, 2024
1478850
pop changes back in
begonaguereca Oct 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
162 changes: 162 additions & 0 deletions src/Octoshift/Services/ArchiveUploader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
using System.Web;
using Newtonsoft.Json.Linq;
using OctoshiftCLI.Extensions;

namespace OctoshiftCLI.Services;

public class ArchiveUploader
{
private readonly GithubClient _client;
private readonly OctoLogger _log;
internal int _streamSizeLimit = 100 * 1024 * 1024; // 100 MiB

private const string BASE_URL = "https://uploads.github.com";

public ArchiveUploader(GithubClient client, OctoLogger log)
{
_client = client;
_log = log;
}
public virtual async Task<string> Upload(Stream archiveContent, string archiveName, string orgDatabaseId)
{
if (archiveContent == null)
{
throw new ArgumentNullException(nameof(archiveContent), "The archive content stream cannot be null.");
}

using var streamContent = new StreamContent(archiveContent);
streamContent.Headers.ContentType = new("application/octet-stream");

var isMultipart = archiveContent.Length > _streamSizeLimit; // Determines if stream size is greater than 100MB

string response;

if (isMultipart)
{
var url = $"{BASE_URL}/organizations/{orgDatabaseId.EscapeDataString()}/gei/archive/blobs/uploads";

response = await UploadMultipart(archiveContent, archiveName, url);
return response;
}
else
{
var url = $"{BASE_URL}/organizations/{orgDatabaseId.EscapeDataString()}/gei/archive?name={archiveName.EscapeDataString()}";

response = await _client.PostAsync(url, streamContent);
var data = JObject.Parse(response);
return (string)data["uri"];
}
}

private async Task<string> UploadMultipart(Stream archiveContent, string archiveName, string uploadUrl)
{
var buffer = new byte[_streamSizeLimit];

try
{
// 1. Start the upload
var startHeaders = await StartUpload(uploadUrl, archiveName, archiveContent.Length);

var nextUrl = GetNextUrl(startHeaders);

var guid = HttpUtility.ParseQueryString(nextUrl.Query)["guid"];

// 2. Upload parts
int bytesRead;
var partsRead = 0;
var totalParts = (long)Math.Ceiling((double)archiveContent.Length / _streamSizeLimit);
while ((bytesRead = await archiveContent.ReadAsync(buffer)) > 0)
{
nextUrl = await UploadPart(buffer, bytesRead, nextUrl.ToString(), partsRead, totalParts);
partsRead++;
}

// 3. Complete the upload
await CompleteUpload(nextUrl.ToString());

return $"gei://archive/{guid}";
}
catch (Exception ex)
{
throw new OctoshiftCliException("Failed during multipart upload.", ex);
}
Comment on lines +85 to +88

Check notice

Code scanning / CodeQL

Generic catch clause Note

Generic catch clause.
}

private async Task<IEnumerable<KeyValuePair<string, IEnumerable<string>>>> StartUpload(string uploadUrl, string archiveName, long contentSize)
{
_log.LogInformation($"Starting archive upload into GitHub owned storage: {archiveName}...");

var body = new
{
content_type = "application/octet-stream",
name = archiveName,
size = contentSize
};

try
{
var (responseContent, headers) = await _client.PostWithFullResponseAsync(uploadUrl, body);

Check warning

Code scanning / CodeQL

Useless assignment to local variable Warning

This assignment to
responseContent
is useless, since its value is never read.
return headers.ToList();
}
catch (Exception ex)
{
throw new OctoshiftCliException("Failed to start upload.", ex);
}
Comment on lines +107 to +110

Check notice

Code scanning / CodeQL

Generic catch clause Note

Generic catch clause.
}

private async Task<Uri> UploadPart(byte[] body, int bytesRead, string nextUrl, int partsRead, long totalParts)
{
_log.LogInformation($"Uploading part {partsRead + 1}/{totalParts}...");
using var content = new ByteArrayContent(body, 0, bytesRead);
content.Headers.ContentType = new("application/octet-stream");

try
{
// Make the PATCH request and retrieve headers
var (responseContent, headers) = await _client.PatchWithFullResponseAsync(nextUrl, content);

Check warning

Code scanning / CodeQL

Useless assignment to local variable Warning

This assignment to
responseContent
is useless, since its value is never read.

// Retrieve the next URL from the response headers
return GetNextUrl(headers.ToList());
}
catch (Exception ex)
{
throw new OctoshiftCliException("Failed to upload part.", ex);
}
Comment on lines +127 to +130

Check notice

Code scanning / CodeQL

Generic catch clause Note

Generic catch clause.
}

private async Task CompleteUpload(string lastUrl)
{
try
{
await _client.PutAsync(lastUrl, "");
_log.LogInformation("Finished uploading archive");
}
catch (Exception ex)
{
throw new OctoshiftCliException("Failed to complete upload.", ex);
}
Comment on lines +140 to +143

Check notice

Code scanning / CodeQL

Generic catch clause Note

Generic catch clause.
}

private Uri GetNextUrl(IEnumerable<KeyValuePair<string, IEnumerable<string>>> headers)
{
// Use FirstOrDefault to safely handle missing Location headers
var locationHeader = headers.First(header => header.Key.Equals("Location", StringComparison.OrdinalIgnoreCase));

if (!string.IsNullOrEmpty(locationHeader.Key))
{
var locationValue = locationHeader.Value.FirstOrDefault();
if (locationValue.HasValue())
{
var fullUrl = $"{BASE_URL}{locationValue}";
return new Uri(fullUrl);
}
}
throw new OctoshiftCliException("Location header is missing in the response, unable to retrieve next URL for multipart upload.");
}
}
17 changes: 16 additions & 1 deletion src/Octoshift/Services/GithubApi.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
Expand All @@ -16,12 +17,14 @@ public class GithubApi
private readonly GithubClient _client;
private readonly string _apiUrl;
private readonly RetryPolicy _retryPolicy;
private readonly ArchiveUploader _multipartUploader;

public GithubApi(GithubClient client, string apiUrl, RetryPolicy retryPolicy)
public GithubApi(GithubClient client, string apiUrl, RetryPolicy retryPolicy, ArchiveUploader multipartUploader)
{
_client = client;
_apiUrl = apiUrl;
_retryPolicy = retryPolicy;
_multipartUploader = multipartUploader;
}

public virtual async Task AddAutoLink(string org, string repo, string keyPrefix, string urlTemplate)
Expand Down Expand Up @@ -1071,6 +1074,18 @@ mutation abortRepositoryMigration(
}
}

public virtual async Task<string> UploadArchiveToGithubStorage(string orgDatabaseId, string archiveName, Stream archiveContent)
{
if (archiveContent is null)
{
throw new ArgumentNullException(nameof(archiveContent));
}

var uri = await _multipartUploader.Upload(archiveContent, archiveName, orgDatabaseId);

return uri;
}

private static object GetMannequinsPayload(string orgId)
{
var query = "query($id: ID!, $first: Int, $after: String)";
Expand Down
20 changes: 18 additions & 2 deletions src/Octoshift/Services/GithubClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ public virtual async IAsyncEnumerable<JToken> GetAllAsync(
public virtual async Task<string> PostAsync(string url, object body, Dictionary<string, string> customHeaders = null) =>
(await SendAsync(HttpMethod.Post, url, body, customHeaders: customHeaders)).Content;

public virtual async Task<(string Content, KeyValuePair<string, IEnumerable<string>>[] ResponseHeaders)> PostWithFullResponseAsync(string url, object body, Dictionary<string, string> customHeaders = null) =>
await SendAsync(HttpMethod.Post, url, body, customHeaders: customHeaders);

public virtual async Task<JToken> PostGraphQLAsync(
string url,
object body,
Expand Down Expand Up @@ -140,6 +143,9 @@ public virtual async Task<string> PutAsync(string url, object body, Dictionary<s
public virtual async Task<string> PatchAsync(string url, object body, Dictionary<string, string> customHeaders = null) =>
(await SendAsync(HttpMethod.Patch, url, body, customHeaders: customHeaders)).Content;

public virtual async Task<(string Content, KeyValuePair<string, IEnumerable<string>>[] ResponseHeaders)> PatchWithFullResponseAsync(string url, object body, Dictionary<string, string> customHeaders = null) =>
await SendAsync(HttpMethod.Patch, url, body, customHeaders: customHeaders);

public virtual async Task<string> DeleteAsync(string url, Dictionary<string, string> customHeaders = null) => (await SendAsync(HttpMethod.Delete, url, customHeaders: customHeaders)).Content;

private async Task<(string Content, KeyValuePair<string, IEnumerable<string>>[] ResponseHeaders)> GetWithRetry(
Expand All @@ -162,9 +168,19 @@ public virtual async Task<string> PatchAsync(string url, object body, Dictionary

if (body != null)
{
_log.LogVerbose($"HTTP BODY: {body.ToJson()}");
_log.LogVerbose(body is MultipartFormDataContent or StreamContent ? "HTTP BODY: BLOB" : $"HTTP BODY: {body.ToJson()}");

request.Content = body.ToJson().ToStringContent();
if (body is HttpContent httpContent)
{
_log.LogVerbose("HTTP BODY: BLOB");
request.Content = httpContent;
}
else
{
var jsonBody = body.ToJson();
_log.LogVerbose($"HTTP BODY: {jsonBody}");
request.Content = jsonBody.ToStringContent();
}
}

using var response = await _httpClient.SendAsync(request);
Expand Down
2 changes: 1 addition & 1 deletion src/OctoshiftCLI.IntegrationTests/AdoToGithub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ protected AdoToGithub(ITestOutputHelper output, string adoServerUrl = "https://d
var githubToken = Environment.GetEnvironmentVariable("GHEC_PAT");
_githubHttpClient = new HttpClient();
var githubClient = new GithubClient(logger, _githubHttpClient, new VersionChecker(_versionClient, logger), new RetryPolicy(logger), new DateTimeProvider(), githubToken);
var githubApi = new GithubApi(githubClient, "https://api.github.com", new RetryPolicy(logger));
var githubApi = new GithubApi(githubClient, "https://api.github.com", new RetryPolicy(logger), null);

Tokens = new Dictionary<string, string>
{
Expand Down
15 changes: 9 additions & 6 deletions src/OctoshiftCLI.IntegrationTests/BbsToGithub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public sealed class BbsToGithub : IDisposable
private readonly HttpClient _sourceBbsHttpClient;
private readonly BbsClient _sourceBbsClient;
private readonly BlobServiceClient _blobServiceClient;
private readonly ArchiveUploader _archiveUploader;
private readonly Dictionary<string, string> _tokens;
private readonly DateTime _startTime;
private readonly string _azureStorageConnectionString;
Expand Down Expand Up @@ -57,18 +58,20 @@ public BbsToGithub(ITestOutputHelper output)

_targetGithubHttpClient = new HttpClient();
_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 = new ArchiveUploader(_targetGithubClient, _logger);
_targetGithubApi = new GithubApi(_targetGithubClient, "https://api.github.com", new RetryPolicy(_logger), _archiveUploader);

_blobServiceClient = new BlobServiceClient(_azureStorageConnectionString);

_targetHelper = new TestHelper(_output, _targetGithubApi, _targetGithubClient, _blobServiceClient);
}

[Theory]
[InlineData("http://e2e-bbs-8-5-0-linux-2204.eastus.cloudapp.azure.com:7990", true, true)]
[InlineData("http://e2e-bbs-7-21-9-win-2019.eastus.cloudapp.azure.com:7990", false, true)]
[InlineData("http://e2e-bbs-8-5-0-linux-2204.eastus.cloudapp.azure.com:7990", true, false)]
public async Task Basic(string bbsServer, bool useSshForArchiveDownload, bool useAzureForArchiveUpload)
[InlineData("http://e2e-bbs-8-5-0-linux-2204.eastus.cloudapp.azure.com:7990", true, true, false)]
[InlineData("http://e2e-bbs-7-21-9-win-2019.eastus.cloudapp.azure.com:7990", false, true, false)]
[InlineData("http://e2e-bbs-8-5-0-linux-2204.eastus.cloudapp.azure.com:7990", true, false, false)]
[InlineData("http://e2e-bbs-8-5-0-linux-2204.eastus.cloudapp.azure.com:7990", false, false, true)]
public async Task Basic(string bbsServer, bool useSshForArchiveDownload, bool useAzureForArchiveUpload, bool useGithubStorage)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At this point I recommend adding an enum for the upload options as a class member (nested enum) right after all private readonly member declarations:

public enum ArchiveUploadOption { AzureStorage, AwsS3, GithubStorage };

Then change the method signature and the inline data like the following:

[InlineData("http://e2e-bbs-8-5-0-linux-2204.eastus.cloudapp.azure.com:7990", true,  ArchiveUploadOption.AzureStorage)]
[InlineData("http://e2e-bbs-7-21-9-win-2019.eastus.cloudapp.azure.com:7990", false, ArchiveUploadOption.AzureStorage)]
[InlineData("http://e2e-bbs-8-5-0-linux-2204.eastus.cloudapp.azure.com:7990", true, ArchiveUploadOption.AwsS3)]
[InlineData("http://e2e-bbs-8-5-0-linux-2204.eastus.cloudapp.azure.com:7990", true, ArchiveUploadOption.GithubStorage)]
public async Task Basic(string bbsServer, bool useSshForArchiveDownload, bool useAzureForArchiveUpload, bool useGithubStorage)

{
var bbsProjectKey = $"E2E-{TestHelper.GetOsName().ToUpper()}";
var githubTargetOrg = $"octoshift-e2e-bbs-{TestHelper.GetOsName()}";
Expand Down Expand Up @@ -117,7 +120,7 @@ await retryPolicy.Retry(async () =>
_tokens.Add("AWS_ACCESS_KEY_ID", Environment.GetEnvironmentVariable("AWS_ACCESS_KEY_ID"));
_tokens.Add("AWS_SECRET_ACCESS_KEY", Environment.GetEnvironmentVariable("AWS_SECRET_ACCESS_KEY"));
var awsBucketName = Environment.GetEnvironmentVariable("AWS_BUCKET_NAME");
archiveUploadOptions = $" --aws-bucket-name {awsBucketName} --aws-region {AWS_REGION}";
archiveUploadOptions = $" --aws-bucket-name {awsBucketName} --aws-region {AWS_REGION} --use-github-storage {useGithubStorage}";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a couple of things here:

  1. --use-github-storage is not yet a supported option for the generate-script commands so this ultimately won't work until we add the option.
  2. Even if the GitHub storage option was supported by generate-script this still wouldn't work because both AWS and GitHub storage options are provided at the same time which should be a validation error.

}

await _targetHelper.RunBbsCliMigration(
Expand Down
15 changes: 9 additions & 6 deletions src/OctoshiftCLI.IntegrationTests/GhesToGithub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public sealed class GhesToGithub : IDisposable
private readonly BlobServiceClient _blobServiceClient;
private readonly Dictionary<string, string> _tokens;
private readonly DateTime _startTime;
private readonly ArchiveUploader _archiveUploader;

public GhesToGithub(ITestOutputHelper output)
{
Expand All @@ -46,23 +47,26 @@ public GhesToGithub(ITestOutputHelper output)
};

_versionClient = new HttpClient();
_archiveUploader = new ArchiveUploader(_targetGithubClient, logger);

_sourceGithubHttpClient = new HttpClient();
_sourceGithubClient = new GithubClient(logger, _sourceGithubHttpClient, new VersionChecker(_versionClient, logger), new RetryPolicy(logger), new DateTimeProvider(), sourceGithubToken);
_sourceGithubApi = new GithubApi(_sourceGithubClient, GHES_API_URL, new RetryPolicy(logger));
_sourceGithubApi = new GithubApi(_sourceGithubClient, GHES_API_URL, new RetryPolicy(logger), _archiveUploader);

_targetGithubHttpClient = new HttpClient();
_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));
_targetGithubApi = new GithubApi(_targetGithubClient, "https://api.github.com", new RetryPolicy(logger), _archiveUploader);

_blobServiceClient = new BlobServiceClient(azureStorageConnectionString);

_sourceHelper = new TestHelper(_output, _sourceGithubApi, _sourceGithubClient) { GithubApiBaseUrl = GHES_API_URL };
_targetHelper = new TestHelper(_output, _targetGithubApi, _targetGithubClient, _blobServiceClient);
}

[Fact]
public async Task Basic()
[Theory]
[InlineData(false)]
[InlineData(true)]
public async Task Basic(bool useGithubStorage)
{
var githubSourceOrg = $"e2e-testing-{TestHelper.GetOsName()}";
var githubTargetOrg = $"octoshift-e2e-ghes-{TestHelper.GetOsName()}";
Expand All @@ -83,7 +87,7 @@ await retryPolicy.Retry(async () =>
});

await _targetHelper.RunGeiCliMigration(
$"generate-script --github-source-org {githubSourceOrg} --github-target-org {githubTargetOrg} --ghes-api-url {GHES_API_URL} --download-migration-logs", _tokens);
$"generate-script --github-source-org {githubSourceOrg} --github-target-org {githubTargetOrg} --ghes-api-url {GHES_API_URL} --use-github-storage {useGithubStorage} --download-migration-logs", _tokens);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case of false for useGithubStorge it shouldn't add the option at all.


_targetHelper.AssertNoErrorInLogs(_startTime);

Expand All @@ -95,7 +99,6 @@ await _targetHelper.RunGeiCliMigration(
_targetHelper.AssertMigrationLogFileExists(githubTargetOrg, repo1);
_targetHelper.AssertMigrationLogFileExists(githubTargetOrg, repo2);
}

public void Dispose()
{
_sourceGithubHttpClient?.Dispose();
Expand Down
3 changes: 1 addition & 2 deletions src/OctoshiftCLI.IntegrationTests/GithubToGithub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ public class GithubToGithub : IDisposable
private bool disposedValue;
private readonly Dictionary<string, string> _tokens;
private readonly DateTime _startTime;

public GithubToGithub(ITestOutputHelper output)
{
_startTime = DateTime.Now;
Expand All @@ -35,7 +34,7 @@ public GithubToGithub(ITestOutputHelper output)
_githubHttpClient = new HttpClient();
_versionClient = new HttpClient();
_githubClient = new GithubClient(logger, _githubHttpClient, new VersionChecker(_versionClient, logger), new RetryPolicy(logger), new DateTimeProvider(), githubToken);
_githubApi = new GithubApi(_githubClient, "https://api.github.com", new RetryPolicy(logger));
_githubApi = new GithubApi(_githubClient, "https://api.github.com", new RetryPolicy(logger), null);

_helper = new TestHelper(_output, _githubApi, _githubClient);
}
Expand Down
Loading
Loading