-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
158 changed files
with
1,350 additions
and
1,265 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,14 @@ | ||
devhome | ||
enums | ||
Octokit | ||
advapi | ||
Urls | ||
Dependabot | ||
github.com | ||
inlines | ||
abcd | ||
Doggos | ||
Stringify | ||
riid | ||
Impl | ||
microsoft |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,99 +1,99 @@ | ||
// Copyright (c) Microsoft Corporation and Contributors | ||
// Licensed under the MIT license. | ||
|
||
using DevHome.Logging.Helpers; | ||
using GitHubExtension.DeveloperId; | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
using DevHome.Logging.Helpers; | ||
using GitHubExtension.DeveloperId; | ||
using Microsoft.Windows.DevHome.SDK; | ||
using Octokit; | ||
|
||
namespace GitHubExtension.Client; | ||
|
||
public class GitHubClientProvider | ||
{ | ||
private readonly GitHubClient publicRepoClient; | ||
|
||
private static readonly object InstanceLock = new (); | ||
|
||
private static GitHubClientProvider? _instance; | ||
|
||
public static GitHubClientProvider Instance | ||
{ | ||
get | ||
{ | ||
if (_instance == null) | ||
{ | ||
lock (InstanceLock) | ||
{ | ||
_instance = new GitHubClientProvider(); | ||
} | ||
} | ||
|
||
return _instance; | ||
} | ||
} | ||
|
||
public GitHubClientProvider() | ||
{ | ||
publicRepoClient = new GitHubClient(new ProductHeaderValue(Constants.DEV_HOME_APPLICATION_NAME)); | ||
} | ||
|
||
public GitHubClient? GetClient(IDeveloperId devId) | ||
{ | ||
var devIdInternal = DeveloperIdProvider.GetInstance().GetDeveloperIdInternal(devId) ?? throw new ArgumentException(devId.LoginId); | ||
return devIdInternal.GitHubClient; | ||
} | ||
|
||
public GitHubClient GetClient(string url) | ||
{ | ||
var devIdInternal = DeveloperIdProvider.GetInstance().GetLoggedInDeveloperIdsInternal().Where(i => i.Url.Equals(url, StringComparison.OrdinalIgnoreCase)).FirstOrDefault(); | ||
if (devIdInternal == null) | ||
{ | ||
return publicRepoClient; | ||
} | ||
|
||
return devIdInternal.GitHubClient; | ||
} | ||
|
||
public GitHubClient GetClient() | ||
{ | ||
return publicRepoClient; | ||
} | ||
|
||
public async Task<GitHubClient> GetClientForLoggedInDeveloper(bool logRateLimit = false) | ||
{ | ||
var authProvider = DeveloperIdProvider.GetInstance(); | ||
var devIds = authProvider.GetLoggedInDeveloperIdsInternal(); | ||
GitHubClient client; | ||
if (devIds == null || !devIds.Any()) | ||
{ | ||
Log.Logger()?.ReportInfo($"No logged in developer, using public GitHub client."); | ||
client = Instance.GetClient(); | ||
} | ||
else | ||
{ | ||
Log.Logger()?.ReportInfo($"Using authenticated user: {devIds.First().LoginId}"); | ||
client = devIds.First().GitHubClient; | ||
} | ||
|
||
if (client == null) | ||
{ | ||
Log.Logger()?.ReportError($"Failed creating GitHubClient."); | ||
return client!; | ||
} | ||
|
||
if (logRateLimit) | ||
using Octokit; | ||
|
||
namespace GitHubExtension.Client; | ||
|
||
public class GitHubClientProvider | ||
{ | ||
private readonly GitHubClient publicRepoClient; | ||
|
||
private static readonly object InstanceLock = new (); | ||
|
||
private static GitHubClientProvider? _instance; | ||
|
||
public static GitHubClientProvider Instance | ||
{ | ||
get | ||
{ | ||
if (_instance == null) | ||
{ | ||
lock (InstanceLock) | ||
{ | ||
_instance = new GitHubClientProvider(); | ||
} | ||
} | ||
|
||
return _instance; | ||
} | ||
} | ||
|
||
public GitHubClientProvider() | ||
{ | ||
publicRepoClient = new GitHubClient(new ProductHeaderValue(Constants.DEV_HOME_APPLICATION_NAME)); | ||
} | ||
|
||
public GitHubClient? GetClient(IDeveloperId devId) | ||
{ | ||
var devIdInternal = DeveloperIdProvider.GetInstance().GetDeveloperIdInternal(devId) ?? throw new ArgumentException(devId.LoginId); | ||
return devIdInternal.GitHubClient; | ||
} | ||
|
||
public GitHubClient GetClient(string url) | ||
{ | ||
var devIdInternal = DeveloperIdProvider.GetInstance().GetLoggedInDeveloperIdsInternal().Where(i => i.Url.Equals(url, StringComparison.OrdinalIgnoreCase)).FirstOrDefault(); | ||
if (devIdInternal == null) | ||
{ | ||
return publicRepoClient; | ||
} | ||
|
||
return devIdInternal.GitHubClient; | ||
} | ||
|
||
public GitHubClient GetClient() | ||
{ | ||
return publicRepoClient; | ||
} | ||
|
||
public async Task<GitHubClient> GetClientForLoggedInDeveloper(bool logRateLimit = false) | ||
{ | ||
var authProvider = DeveloperIdProvider.GetInstance(); | ||
var devIds = authProvider.GetLoggedInDeveloperIdsInternal(); | ||
GitHubClient client; | ||
if (devIds == null || !devIds.Any()) | ||
{ | ||
Log.Logger()?.ReportInfo($"No logged in developer, using public GitHub client."); | ||
client = Instance.GetClient(); | ||
} | ||
else | ||
{ | ||
Log.Logger()?.ReportInfo($"Using authenticated user: {devIds.First().LoginId}"); | ||
client = devIds.First().GitHubClient; | ||
} | ||
|
||
if (client == null) | ||
{ | ||
Log.Logger()?.ReportError($"Failed creating GitHubClient."); | ||
return client!; | ||
} | ||
|
||
if (logRateLimit) | ||
{ | ||
try | ||
{ | ||
var miscRateLimit = await client.RateLimit.GetRateLimits(); | ||
Log.Logger()?.ReportInfo($"Rate Limit: Remaining: {miscRateLimit.Resources.Core.Remaining} Total: {miscRateLimit.Resources.Core.Limit} Resets: {miscRateLimit.Resources.Core.Reset.ToStringInvariant()}"); | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
Log.Logger()?.ReportError($"Rate limiting not enabled for server.", ex); | ||
} | ||
} | ||
|
||
return client; | ||
} | ||
} | ||
} | ||
} | ||
|
||
return client; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 3 additions & 2 deletions
5
src/GitHubExtension/Configuration/DeveloperOAuthConfiguration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
src/GitHubExtension/DataManager/DataManagerUpdateEventArgs.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
src/GitHubExtension/DataManager/DataStoreOperationParameters.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.