Skip to content

Commit 837824e

Browse files
committed
diagnose: add GitHub API diagnostic tests
1 parent accd673 commit 837824e

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using System.Threading.Tasks;
5+
using Microsoft.Git.CredentialManager.Diagnostics;
6+
7+
namespace GitHub.Diagnostics
8+
{
9+
public class GitHubApiDiagnostic : Diagnostic
10+
{
11+
private readonly IGitHubRestApi _api;
12+
13+
public GitHubApiDiagnostic(IGitHubRestApi api)
14+
: base("GitHub API")
15+
{
16+
_api = api;
17+
}
18+
19+
protected override async Task<bool> RunInternalAsync(StringBuilder log, IList<string> additionalFiles)
20+
{
21+
var targetUri = new Uri("https://github.com");
22+
log.AppendLine($"Using '{targetUri}' as API target.");
23+
24+
log.Append("Querying '/meta' endpoint...");
25+
GitHubMetaInfo metaInfo = await _api.GetMetaInfoAsync(targetUri);
26+
log.AppendLine(" OK");
27+
28+
return true;
29+
}
30+
}
31+
}

src/shared/GitHub/GitHubHostProvider.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
using System.Collections.Generic;
33
using System.Net.Http;
44
using System.Threading.Tasks;
5+
using GitHub.Diagnostics;
56
using Microsoft.Git.CredentialManager;
67
using Microsoft.Git.CredentialManager.Authentication.OAuth;
8+
using Microsoft.Git.CredentialManager.Diagnostics;
79

810
namespace GitHub
911
{
10-
public class GitHubHostProvider : HostProvider
12+
public class GitHubHostProvider : HostProvider, IDiagnosticProvider
1113
{
1214
private static readonly string[] GitHubOAuthScopes =
1315
{
@@ -295,6 +297,11 @@ protected override void ReleaseManagedResources()
295297
base.ReleaseManagedResources();
296298
}
297299

300+
public IEnumerable<IDiagnostic> GetDiagnostics()
301+
{
302+
yield return new GitHubApiDiagnostic(_gitHubApi);
303+
}
304+
298305
#region Private Methods
299306

300307
public static bool IsGitHubDotCom(string targetUrl)

0 commit comments

Comments
 (0)