Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit 78ad9f4

Browse files
authored
Merge pull request #1476 from github/fixes/1473-enterprise-instance-not-detected
Fix SimpleApiClient.IsEnterprise().
2 parents b568332 + 3be40a0 commit 78ad9f4

File tree

6 files changed

+15
-10
lines changed

6 files changed

+15
-10
lines changed

src/GitHub.Api/SimpleApiClient.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ async Task<Repository> GetRepositoryInternal()
7272
if (repo != null)
7373
{
7474
hasWiki = await HasWikiInternal(repo);
75-
isEnterprise = await IsEnterpriseInternal();
75+
isEnterprise = isEnterprise ?? await IsEnterpriseInternal();
7676
repositoryCache = repo;
7777
}
7878
owner = ownerLogin;
@@ -99,9 +99,14 @@ public bool HasWiki()
9999
return hasWiki.HasValue && hasWiki.Value;
100100
}
101101

102-
public bool IsEnterprise()
102+
public async Task<bool> IsEnterprise()
103103
{
104-
return isEnterprise.HasValue && isEnterprise.Value;
104+
if (!isEnterprise.HasValue)
105+
{
106+
isEnterprise = await IsEnterpriseInternal();
107+
}
108+
109+
return isEnterprise ?? false;
105110
}
106111

107112
async Task<bool> HasWikiInternal(Repository repo)

src/GitHub.App/ViewModels/GitHubPane/GitHubPaneViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ async Task UpdateContent(ILocalRepositoryModel repository)
366366
var repositoryUrl = repository.CloneUrl.ToRepositoryUrl();
367367
var isDotCom = HostAddress.IsGitHubDotComUri(repositoryUrl);
368368
var client = await apiClientFactory.Create(repository.CloneUrl);
369-
var isEnterprise = isDotCom ? false : client.IsEnterprise();
369+
var isEnterprise = isDotCom ? false : await client.IsEnterprise();
370370

371371
if ((isDotCom || isEnterprise) && await IsValidRepository(client))
372372
{

src/GitHub.Exports/Api/ISimpleApiClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public interface ISimpleApiClient
1111
UriString OriginalUrl { get; }
1212
Task<Repository> GetRepository();
1313
bool HasWiki();
14-
bool IsEnterprise();
14+
Task<bool> IsEnterprise();
1515
bool IsAuthenticated();
1616
}
1717
}

src/GitHub.VisualStudio.UI/Base/TeamExplorerItemBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ protected async Task<RepositoryOrigin> GetRepositoryOrigin()
126126
{
127127
var repo = await SimpleApiClient.GetRepository();
128128

129-
if ((repo.FullName == ActiveRepoName || repo.Id == 0) && SimpleApiClient.IsEnterprise())
129+
if ((repo.FullName == ActiveRepoName || repo.Id == 0) && await SimpleApiClient.IsEnterprise())
130130
{
131131
return RepositoryOrigin.Enterprise;
132132
}

src/GitHub.VisualStudio/Menus/MenuBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ protected async Task<bool> IsGitHubRepo()
123123
{
124124
var repo = await SimpleApiClient.GetRepository();
125125
var activeRepoFullName = ActiveRepo.Owner + '/' + ActiveRepo.Name;
126-
return (repo.FullName == activeRepoFullName || repo.Id == 0) && SimpleApiClient.IsEnterprise();
126+
return (repo.FullName == activeRepoFullName || repo.Id == 0) && await SimpleApiClient.IsEnterprise();
127127
}
128128
return isdotcom;
129129
}

test/UnitTests/GitHub.Api/SimpleApiClientTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,10 @@ public async Task ReturnsTrueWhenEnterpriseProbeReturnsOk(EnterpriseProbeResult
132132
new Lazy<IWikiProbe>(() => wikiProbe));
133133
await client.GetRepository();
134134

135-
var result = client.IsEnterprise();
135+
var result = await client.IsEnterprise();
136136

137137
Assert.That(expected, Is.EqualTo(result));
138-
Assert.That(expected, Is.EqualTo(client.IsEnterprise()));
138+
Assert.That(expected, Is.EqualTo(await client.IsEnterprise()));
139139
}
140140

141141
[Test]
@@ -151,7 +151,7 @@ public void ReturnsFalseWhenWeHaveNotRequestedRepository()
151151
new Lazy<IEnterpriseProbe>(() => enterpriseProbe),
152152
new Lazy<IWikiProbe>(() => wikiProbe));
153153

154-
var result = client.IsEnterprise();
154+
var result = client.IsEnterprise().Result;
155155

156156
Assert.False(result);
157157
}

0 commit comments

Comments
 (0)