-
Notifications
You must be signed in to change notification settings - Fork 136
Expand file tree
/
Copy pathGhesToGithub.cs
More file actions
126 lines (103 loc) · 5.43 KB
/
GhesToGithub.cs
File metadata and controls
126 lines (103 loc) · 5.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks;
using Azure.Storage.Blobs;
using OctoshiftCLI.Services;
using Xunit;
using Xunit.Abstractions;
namespace OctoshiftCLI.IntegrationTests;
[Collection("Integration Tests")]
public sealed class GhesToGithub : IDisposable
{
private const string GHES_API_URL = "https://octoshift-ghe.westus2.cloudapp.azure.com/api/v3";
private const string UPLOADS_URL = "https://uploads.github.com";
private readonly ITestOutputHelper _output;
private readonly TestHelper _targetHelper;
private readonly TestHelper _sourceHelper;
private readonly HttpClient _versionClient;
private readonly HttpClient _targetGithubHttpClient;
private readonly GithubClient _targetGithubClient;
private readonly GithubApi _targetGithubApi;
private readonly HttpClient _sourceGithubHttpClient;
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 _azureStorageConnectionString;
public GhesToGithub(ITestOutputHelper output)
{
_startTime = DateTime.Now;
_output = output;
var logger = new OctoLogger(_ => { }, x => _output.WriteLine(x), _ => { }, _ => { });
var sourceGithubToken = Environment.GetEnvironmentVariable("GHES_PAT");
var targetGithubToken = Environment.GetEnvironmentVariable("GHEC_PAT");
_azureStorageConnectionString = Environment.GetEnvironmentVariable($"AZURE_STORAGE_CONNECTION_STRING_GHES_{TestHelper.GetOsName().ToUpper()}");
_tokens = new Dictionary<string, string>
{
["GH_SOURCE_PAT"] = sourceGithubToken,
["GH_PAT"] = targetGithubToken,
};
_versionClient = new HttpClient();
var retryPolicy = new RetryPolicy(logger, "GHES (GHES_PAT)");
var environmentVariableProvider = new EnvironmentVariableProvider(logger);
_sourceGithubHttpClient = new HttpClient();
_sourceGithubClient = new GithubClient(logger, _sourceGithubHttpClient, new VersionChecker(_versionClient, logger), new RetryPolicy(logger, "GHES (GHES_PAT)"), new DateTimeProvider(), sourceGithubToken);
_archiveUploader = new ArchiveUploader(_targetGithubClient, UPLOADS_URL, logger, retryPolicy, environmentVariableProvider);
_sourceGithubApi = new GithubApi(_sourceGithubClient, GHES_API_URL, new RetryPolicy(logger, "GHES (GHES_PAT)"), _archiveUploader);
_targetGithubHttpClient = new HttpClient();
_targetGithubClient = new GithubClient(logger, _targetGithubHttpClient, new VersionChecker(_versionClient, logger), new RetryPolicy(logger, "GitHub (GHEC_PAT)"), new DateTimeProvider(), targetGithubToken);
_targetGithubApi = new GithubApi(_targetGithubClient, "https://api.github.com", new RetryPolicy(logger, "GitHub (GHEC_PAT)"), _archiveUploader);
_blobServiceClient = new BlobServiceClient(_azureStorageConnectionString);
_sourceHelper = new TestHelper(_output, _sourceGithubApi, _sourceGithubClient) { GithubApiBaseUrl = GHES_API_URL };
_targetHelper = new TestHelper(_output, _targetGithubApi, _targetGithubClient, _blobServiceClient);
}
[Theory]
[InlineData(false)]
[InlineData(true)]
public async Task Basic(bool useGithubStorage)
{
var githubSourceOrg = $"e2e-testing-{TestHelper.GetOsName()}";
var githubTargetOrg = $"octoshift-e2e-ghes-{TestHelper.GetOsName()}";
const string repo1 = "repo-1";
const string repo2 = "repo-2";
var retryPolicy = new RetryPolicy(null);
if (!useGithubStorage)
{
_tokens["AZURE_STORAGE_CONNECTION_STRING"] = _azureStorageConnectionString;
}
await retryPolicy.Retry(async () =>
{
if (!useGithubStorage)
{
await _targetHelper.ResetBlobContainers();
}
await _sourceHelper.ResetGithubTestEnvironment(githubSourceOrg);
await _targetHelper.ResetGithubTestEnvironment(githubTargetOrg);
await _sourceHelper.CreateGithubRepo(githubSourceOrg, repo1);
await _sourceHelper.CreateGithubRepo(githubSourceOrg, repo2);
});
// Build the command with conditional option
var command = $"generate-script --github-source-org {githubSourceOrg} --github-target-org {githubTargetOrg} --ghes-api-url {GHES_API_URL} --download-migration-logs";
if (useGithubStorage)
{
command += " --use-github-storage";
}
await _targetHelper.RunGeiCliMigration(command, _tokens);
_targetHelper.AssertNoErrorInLogs(_startTime);
await _targetHelper.AssertGithubRepoExists(githubTargetOrg, repo1);
await _targetHelper.AssertGithubRepoExists(githubTargetOrg, repo2);
await _targetHelper.AssertGithubRepoInitialized(githubTargetOrg, repo1);
await _targetHelper.AssertGithubRepoInitialized(githubTargetOrg, repo2);
_targetHelper.AssertMigrationLogFileExists(githubTargetOrg, repo1);
_targetHelper.AssertMigrationLogFileExists(githubTargetOrg, repo2);
}
public void Dispose()
{
_sourceGithubHttpClient?.Dispose();
_targetGithubHttpClient?.Dispose();
_versionClient?.Dispose();
}
}