Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/GitHubConnector.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="9.0.0" />
<PackageReference Include="Microsoft.Graph" Version="5.55.0" />
<PackageReference Include="Microsoft.Graph" Version="6.8.0" />
<PackageReference Include="Octokit" Version="14.0.0" />
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.556">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
34 changes: 27 additions & 7 deletions src/Services/SearchConnectorService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Microsoft.Graph;
using Microsoft.Graph.External.Connections.Item.Items.Item.MicrosoftGraphExternalConnectorsAddActivities;
using Microsoft.Graph.Models.ExternalConnectors;
using Microsoft.Kiota.Abstractions.Serialization;
using Microsoft.Kiota.Authentication.Azure;

namespace GitHubConnector.Services;
Expand Down Expand Up @@ -149,10 +150,7 @@ public SearchConnectorService(AppSettings settings)
{
Id = itemType == "issues" ? "issueDisplay" : "repoDisplay",
Priority = 1,
Layout = new()
{
AdditionalData = await GetResultTemplateAsync(resultCardJsonFile),
},
Layout = await GetResultTemplateAsync(resultCardJsonFile),
},
],
},
Expand Down Expand Up @@ -280,10 +278,32 @@ public Task<Identity> GetIdentityForGitHubUserAsync(string? gitHubLogin)
});
}

private static async Task<Dictionary<string, object>> GetResultTemplateAsync(string resultCardJsonFile)
private static async Task<UntypedNode> GetResultTemplateAsync(string resultCardJsonFile)
{
var cardContents = await File.ReadAllTextAsync(resultCardJsonFile);
return JsonSerializer.Deserialize<Dictionary<string, object>>(cardContents) ??
throw new Exception($"Could not deserialize contents of {resultCardJsonFile}");
using var cardJson = JsonDocument.Parse(cardContents);
return ToUntypedNode(cardJson.RootElement);
}

private static UntypedNode ToUntypedNode(JsonElement element)
{
return element.ValueKind switch
{
JsonValueKind.Object => new UntypedObject(element.EnumerateObject()
.ToDictionary(property => property.Name, property => ToUntypedNode(property.Value))),
JsonValueKind.Array => new UntypedArray(element.EnumerateArray().Select(ToUntypedNode)),
JsonValueKind.String => new UntypedString(element.GetString()!),
JsonValueKind.Number => element.TryGetInt32(out var intValue) ?
new UntypedInteger(intValue) :
element.TryGetInt64(out var longValue) ?
new UntypedLong(longValue) :
element.TryGetDecimal(out var decimalValue) ?
new UntypedDecimal(decimalValue) :
new UntypedDouble(element.GetDouble()),
JsonValueKind.True => new UntypedBoolean(true),
JsonValueKind.False => new UntypedBoolean(false),
JsonValueKind.Null => new UntypedNull(),
_ => throw new JsonException($"Unsupported JSON value: {element.ValueKind}"),
};
}
}
Loading