-
Notifications
You must be signed in to change notification settings - Fork 136
Expand file tree
/
Copy pathAdoToGithub.cs
More file actions
71 lines (60 loc) · 2.68 KB
/
AdoToGithub.cs
File metadata and controls
71 lines (60 loc) · 2.68 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
using System;
using System.Collections.Generic;
using System.Net.Http;
using OctoshiftCLI.Services;
using Xunit.Abstractions;
namespace OctoshiftCLI.IntegrationTests
{
public abstract class AdoToGithub : IDisposable
{
private readonly ITestOutputHelper _output;
private readonly HttpClient _adoHttpClient;
private readonly HttpClient _githubHttpClient;
private readonly HttpClient _versionClient;
private bool disposedValue;
protected TestHelper Helper { get; }
protected Dictionary<string, string> Tokens { get; }
protected DateTime StartTime { get; }
protected AdoToGithub(ITestOutputHelper output, string adoServerUrl = "https://dev.azure.com", string adoPatEnvVar = "ADO_PAT")
{
StartTime = DateTime.Now;
_output = output;
var logger = new OctoLogger(x => { }, x => _output.WriteLine(x), x => { }, x => { });
_versionClient = new HttpClient();
var adoToken = Environment.GetEnvironmentVariable(adoPatEnvVar);
_adoHttpClient = new HttpClient();
var retryPolicy = new RetryPolicy(logger, $"Azure DevOps ({adoPatEnvVar})");
var adoClient = new AdoClient(logger, _adoHttpClient, new VersionChecker(_versionClient, logger), retryPolicy, adoToken);
var adoApi = new AdoApi(adoClient, adoServerUrl, logger);
var githubToken = Environment.GetEnvironmentVariable("GHEC_PAT");
_githubHttpClient = new HttpClient();
var githubClient = new GithubClient(logger, _githubHttpClient, new VersionChecker(_versionClient, logger), new RetryPolicy(logger, "GitHub (GHEC_PAT)"), new DateTimeProvider(), githubToken);
var githubApi = new GithubApi(githubClient, "https://api.github.com", new RetryPolicy(logger, "GitHub (GHEC_PAT)"), null);
Tokens = new Dictionary<string, string>
{
["GH_PAT"] = githubToken,
["ADO_PAT"] = adoToken
};
Helper = new TestHelper(_output, adoApi, githubApi, adoClient, githubClient);
}
protected virtual void Dispose(bool disposing)
{
if (!disposedValue)
{
if (disposing)
{
_adoHttpClient.Dispose();
_githubHttpClient.Dispose();
_versionClient.Dispose();
}
disposedValue = true;
}
}
public void Dispose()
{
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
Dispose(disposing: true);
GC.SuppressFinalize(this);
}
}
}