Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit 1541ce0

Browse files
Removing GitHubClient from various places
1 parent 97e9176 commit 1541ce0

File tree

3 files changed

+35
-45
lines changed

3 files changed

+35
-45
lines changed

src/GitHub.Api/Application/ApiClient.cs

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ public static IApiClient Create(UriString repositoryUrl, IKeychain keychain, IPr
2727
public UriString OriginalUrl { get; }
2828

2929
private readonly IKeychain keychain;
30-
private readonly IGitHubClient githubClient;
3130
private readonly IProcessManager processManager;
3231
private readonly ITaskManager taskManager;
3332
private readonly NPath nodeJsExecutablePath;
@@ -43,7 +42,6 @@ public ApiClient(UriString hostUrl, IKeychain keychain, IGitHubClient githubClie
4342
HostAddress = HostAddress.Create(hostUrl);
4443
OriginalUrl = hostUrl;
4544
this.keychain = keychain;
46-
this.githubClient = githubClient;
4745
this.processManager = processManager;
4846
this.taskManager = taskManager;
4947
this.nodeJsExecutablePath = nodeJsExecutablePath;
@@ -114,7 +112,7 @@ public async Task Login(string username, string password, Action<LoginResult> ne
114112
LoginResultData res = null;
115113
try
116114
{
117-
res = await loginManager.Login(OriginalUrl, githubClient, username, password);
115+
res = await loginManager.Login(OriginalUrl, username, password);
118116
}
119117
catch (Exception ex)
120118
{
@@ -160,7 +158,7 @@ public async Task<bool> LoginAsync(string username, string password, Func<LoginR
160158
LoginResultData res = null;
161159
try
162160
{
163-
res = await loginManager.Login(OriginalUrl, githubClient, username, password);
161+
res = await loginManager.Login(OriginalUrl, username, password);
164162
}
165163
catch (Exception)
166164
{
@@ -216,17 +214,19 @@ private async Task<GitHubRepository> CreateRepositoryInternal(NewRepository newR
216214
{
217215
logger.Trace("Creating repository for organization");
218216

219-
repository = (await githubClient.Repository.Create(organization, newRepository)).ToGitHubRepository();
217+
//repository = (await githubClient.Repository.Create(organization, newRepository)).ToGitHubRepository();
220218
}
221219
else
222220
{
223221
logger.Trace("Creating repository for user");
224222

225-
repository = (await githubClient.Repository.Create(newRepository)).ToGitHubRepository();
223+
//repository = (await githubClient.Repository.Create(newRepository)).ToGitHubRepository();
226224
}
227225

228-
logger.Trace("Created Repository");
229-
return repository;
226+
throw new NotImplementedException();
227+
228+
//logger.Trace("Created Repository");
229+
//return repository;
230230
}
231231
catch (Exception ex)
232232
{
@@ -244,20 +244,22 @@ private async Task GetOrganizationInternal(Action<Organization[]> onSuccess, Act
244244
await ValidateKeychain();
245245
await ValidateCurrentUserInternal();
246246

247-
var organizations = await githubClient.Organization.GetAllForCurrent();
248-
249-
logger.Trace("Obtained {0} Organizations", organizations?.Count.ToString() ?? "NULL");
250-
251-
if (organizations != null)
252-
{
253-
var array = organizations.Select(organization => new Organization() {
254-
Name = organization.Name,
255-
Login = organization.Login
256-
}).ToArray();
257-
onSuccess(array);
258-
}
247+
throw new NotImplementedException();
248+
249+
// var organizations = await githubClient.Organization.GetAllForCurrent();
250+
//
251+
// logger.Trace("Obtained {0} Organizations", organizations?.Count.ToString() ?? "NULL");
252+
//
253+
// if (organizations != null)
254+
// {
255+
// var array = organizations.Select(organization => new Organization() {
256+
// Name = organization.Name,
257+
// Login = organization.Login
258+
// }).ToArray();
259+
// onSuccess(array);
260+
// }
259261
}
260-
catch(Exception ex)
262+
catch (Exception ex)
261263
{
262264
logger.Error(ex, "Error Getting Organizations");
263265
onError?.Invoke(ex);
@@ -271,7 +273,9 @@ private async Task<GitHubUser> GetCurrentUserInternal()
271273
logger.Trace("Getting Current User");
272274
await ValidateKeychain();
273275

274-
return (await githubClient.User.Current()).ToGitHubUser();
276+
throw new NotImplementedException();
277+
278+
//return (await githubClient.User.Current()).ToGitHubUser();
275279
}
276280
catch (KeychainEmptyException)
277281
{
@@ -316,9 +320,7 @@ private async Task<bool> LoadKeychainInternal()
316320
var uriString = keychain.Connections.First().Host;
317321
var keychainAdapter = await keychain.Load(uriString);
318322

319-
logger.Trace("LoadKeychainInternal: Loaded");
320-
321-
return keychainAdapter.OctokitCredentials != Credentials.Anonymous;
323+
throw new NotImplementedException();
322324
}
323325

324326
logger.Trace("LoadKeychainInternal: No keys to load");

src/GitHub.Api/Authentication/ILoginManager.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@ interface ILoginManager
1212
/// Attempts to log into a GitHub server.
1313
/// </summary>
1414
/// <param name="host"></param>
15-
/// <param name="client">An octokit client configured to access the server.</param>
1615
/// <param name="username">The username.</param>
1716
/// <param name="password">The password.</param>
1817
/// <returns>The logged in user.</returns>
1918
/// <exception cref="AuthorizationException">
2019
/// The login authorization failed.
2120
/// </exception>
22-
Task<LoginResultData> Login(UriString host, IGitHubClient client, string username, string password);
21+
Task<LoginResultData> Login(UriString host, string username, string password);
2322
Task<LoginResultData> ContinueLogin(LoginResultData loginResultData, string twofacode);
2423

2524
/// <summary>

src/GitHub.Api/Authentication/LoginManager.cs

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,10 @@ public LoginManager(
7171
/// <inheritdoc/>
7272
public async Task<LoginResultData> Login(
7373
UriString host,
74-
IGitHubClient client,
7574
string username,
7675
string password)
7776
{
7877
Guard.ArgumentNotNull(host, nameof(host));
79-
Guard.ArgumentNotNull(client, nameof(client));
8078
Guard.ArgumentNotNullOrWhiteSpace(username, nameof(username));
8179
Guard.ArgumentNotNullOrWhiteSpace(password, nameof(password));
8280

@@ -96,8 +94,7 @@ public async Task<LoginResultData> Login(
9694

9795
try
9896
{
99-
//auth = await CreateAndDeleteExistingApplicationAuthorization(client, newAuth, null);
100-
auth = await TryLogin(client, host, username, password);
97+
auth = await TryLogin(host, username, password);
10198
EnsureNonNullAuthorization(auth);
10299
}
103100
catch (TwoFactorAuthorizationException e)
@@ -114,7 +111,7 @@ public async Task<LoginResultData> Login(
114111
logger.Error(e, "2FA TwoFactorAuthorizationException: {0} {1}", LoginResultCodes.CodeRequired, e.Message);
115112
}
116113

117-
return new LoginResultData(result, e.Message, client, host, newAuth);
114+
return new LoginResultData(result, e.Message, host, newAuth);
118115
}
119116
catch(LoginAttemptsExceededException e)
120117
{
@@ -157,7 +154,6 @@ public async Task<LoginResultData> Login(
157154

158155
public async Task<LoginResultData> ContinueLogin(LoginResultData loginResultData, string twofacode)
159156
{
160-
var client = loginResultData.Client;
161157
var newAuth = loginResultData.NewAuth;
162158
var host = loginResultData.Host;
163159
var k = keychain.Connect(host);
@@ -166,11 +162,8 @@ public async Task<LoginResultData> ContinueLogin(LoginResultData loginResultData
166162
try
167163
{
168164
logger.Trace("2FA Continue");
169-
var auth = await TryContinueLogin(client, host, username, password, twofacode);
170-
//var auth = await CreateAndDeleteExistingApplicationAuthorization(
171-
// client,
172-
// newAuth,
173-
// twofacode);
165+
var auth = await TryContinueLogin(host, username, password, twofacode);
166+
174167
EnsureNonNullAuthorization(auth);
175168

176169
keychain.SetToken(host, auth.Token);
@@ -182,7 +175,7 @@ public async Task<LoginResultData> ContinueLogin(LoginResultData loginResultData
182175
{
183176
logger.Trace(e, "2FA TwoFactorAuthorizationException: {0} {1}", LoginResultCodes.CodeFailed, e.Message);
184177

185-
return new LoginResultData(LoginResultCodes.CodeFailed, Localization.Wrong2faCode, client, host, newAuth);
178+
return new LoginResultData(LoginResultCodes.CodeFailed, Localization.Wrong2faCode, host, newAuth);
186179
}
187180
catch (ApiValidationException e)
188181
{
@@ -253,7 +246,6 @@ private async Task<ApplicationAuthorization> CreateAndDeleteExistingApplicationA
253246
}
254247

255248
private async Task<ApplicationAuthorization> TryLogin(
256-
IGitHubClient client,
257249
UriString host,
258250
string username,
259251
string password
@@ -304,7 +296,6 @@ string password
304296
}
305297

306298
private async Task<ApplicationAuthorization> TryContinueLogin(
307-
IGitHubClient client,
308299
UriString host,
309300
string username,
310301
string password,
@@ -382,20 +373,18 @@ class LoginResultData
382373
public string Message;
383374
internal NewAuthorization NewAuth { get; set; }
384375
internal UriString Host { get; set; }
385-
internal IGitHubClient Client { get; set; }
386376

387377
internal LoginResultData(LoginResultCodes code, string message,
388-
IGitHubClient client, UriString host, NewAuthorization newAuth)
378+
UriString host, NewAuthorization newAuth)
389379
{
390380
this.Code = code;
391381
this.Message = message;
392382
this.NewAuth = newAuth;
393383
this.Host = host;
394-
this.Client = client;
395384
}
396385

397386
internal LoginResultData(LoginResultCodes code, string message, UriString host)
398-
: this(code, message, null, host, null)
387+
: this(code, message, host, null)
399388
{
400389
}
401390
}

0 commit comments

Comments
 (0)