Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Friendly error when missing GitHub data provider #1256

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
7 changes: 7 additions & 0 deletions src/Octoshift/Services/AdoApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,13 @@ public virtual async Task<string> GetGithubHandle(string org, string teamProject
var response = await _client.PostAsync(url, payload);
var data = JObject.Parse(response);

#pragma warning disable IDE0046 // Convert to conditional expression
if (data["dataProviders"]["ms.vss-work-web.github-user-data-provider"] == null)
{
throw new OctoshiftCliException("Missing data from 'ms.vss-work-web.github-user-data-provider'. Please ensure the Azure DevOps project has a configured GitHub connection.");
}
#pragma warning restore IDE0046 // Convert to conditional expression

return (string)data["dataProviders"]["ms.vss-work-web.github-user-data-provider"]["login"];
}

Expand Down
36 changes: 36 additions & 0 deletions src/OctoshiftCLI.Tests/Octoshift/Services/AdoApiTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,42 @@ public async Task GetGithubHandle_Should_Return_Handle()
result.Should().Be(handle);
}

[Fact]
public async Task GetGithubHandle_Throws_On_Missing_Data_Provider()
{
var githubToken = Guid.NewGuid().ToString();

var endpoint = $"https://dev.azure.com/{ADO_ORG.EscapeDataString()}/_apis/Contribution/HierarchyQuery?api-version=5.0-preview.1";
var payload = new
{
contributionIds = new[]
{
"ms.vss-work-web.github-user-data-provider"
},
dataProviderContext = new
{
properties = new
{
accessToken = githubToken,
sourcePage = new
{
routeValues = new
{
project = ADO_TEAM_PROJECT
}
}
}
}
};

var json = $"{{ \"dataProviders\": {{ }} }}";

_mockAdoClient.Setup(x => x.PostAsync(endpoint, It.Is<object>(y => y.ToJson() == payload.ToJson())).Result).Returns(json);

var exception = await Assert.ThrowsAsync<OctoshiftCliException>(() => sut.GetGithubHandle(ADO_ORG, ADO_TEAM_PROJECT, githubToken));
exception.Message.Should().Be("Missing data from 'ms.vss-work-web.github-user-data-provider'. Please ensure the Azure DevOps project has a configured GitHub connection.");
}

[Fact]
public async Task GetBoardsGithubConnection_Should_Return_Connection_With_All_Repos()
{
Expand Down
Loading