Skip to content

Commit 3c2984d

Browse files
authored
Add the repository Explorer projects (#106)
* repository explorer compiler in the new repo Add all the existing projects. Make sure everything compiles using .NET 7 * fix warnings.
1 parent b7cd8c8 commit 3c2984d

File tree

95 files changed

+4716
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+4716
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
using DotnetDocsTools.GitHubCommunications;
2+
using DotnetDocsTools.GraphQLQueries;
3+
4+
namespace Dotnet.DocsTools.GraphQLQueries
5+
{
6+
/// <summary>
7+
/// Retrieve the count of open issues based on labels
8+
/// </summary>
9+
/// <remarks>
10+
/// This query returns the number of matching open issues. You can specify
11+
/// either issues with certain labels, or issues without certain labels,
12+
/// or a mix.
13+
/// </remarks>
14+
public class LabeledIssueCounts
15+
{
16+
private const string AreaIssuesCount =
17+
@"query ($search_value: String!) {
18+
search(query: $search_value, type: ISSUE) {
19+
issueCount
20+
}
21+
}
22+
";
23+
private readonly IGitHubClient client;
24+
private readonly string search_value;
25+
26+
/// <summary>
27+
/// Constructor
28+
/// </summary>
29+
/// <param name="client">The GitHub client.</param>
30+
/// <param name="owner">The owner of the repository</param>
31+
/// <param name="repository">The repository name</param>
32+
/// <param name="labelFilter">The GraphQL string for filtering</param>
33+
public LabeledIssueCounts(IGitHubClient client, string owner, string repository, string labelFilter)
34+
{
35+
this.client = client ?? throw new ArgumentNullException(paramName: nameof(client), message: "Cannot be null");
36+
if (string.IsNullOrWhiteSpace(owner))
37+
throw new ArgumentException(message: "Must not be whitespace", paramName: nameof(owner));
38+
if (string.IsNullOrWhiteSpace(repository))
39+
throw new ArgumentException(message: "Must not be whitespace", paramName: nameof(repository));
40+
search_value = $"repo:{owner}/{repository} is:issue is:open " + labelFilter;
41+
//Console.WriteLine(search_value);
42+
}
43+
44+
/// <summary>
45+
/// Perform the query for the issue count
46+
/// </summary>
47+
/// <returns>The number of open issues matching this query.</returns>
48+
public async Task<int> PerformQueryAsync()
49+
{
50+
var queryText = new GraphQLPacket
51+
{
52+
query = AreaIssuesCount
53+
};
54+
queryText.variables["search_value"] = search_value;
55+
56+
var results = await client.PostGraphQLRequestAsync(queryText);
57+
return results.Descendent("search", "issueCount").GetInt32();
58+
}
59+
}
60+
}
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Router AppAssembly="@typeof(App).Assembly">
2+
<Found Context="routeData">
3+
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
4+
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
5+
</Found>
6+
<NotFound>
7+
<PageTitle>Not found</PageTitle>
8+
<LayoutView Layout="@typeof(MainLayout)">
9+
<p role="alert">Sorry, there's nothing at this address.</p>
10+
</LayoutView>
11+
</NotFound>
12+
</Router>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<div class="row">
2+
@if (AppState is { RepoState.IsAssigned: true } && !_isEditing)
3+
{
4+
<ErrorBoundary @ref="_errorBoundary">
5+
<ChildContent>
6+
@PostConfigurationContent
7+
</ChildContent>
8+
<ErrorContent>
9+
<div class="alert alert-danger" role="alert">
10+
<h4 class="alert-heading">Error</h4>
11+
<p>Something has gone terribly wrong.</p>
12+
</div>
13+
</ErrorContent>
14+
</ErrorBoundary>
15+
}
16+
else
17+
{
18+
<form class="col-4">
19+
@if (OptionalMessageContent is not null)
20+
{
21+
<div class="mb-3">
22+
@OptionalMessageContent
23+
</div>
24+
}
25+
<div class="mb-3">
26+
<label for="org" class="form-label">Organization</label>
27+
<input id="org" @bind=@_organizationName
28+
class="form-control" placeholder="GitHub organization name" />
29+
</div>
30+
<div class="mb-3">
31+
<label for="repo" class="form-label">Repository</label>
32+
<input id="repo" @bind=@_repositoryName
33+
class="form-control" placeholder="GitHub repository name" />
34+
</div>
35+
<div class="mb-3">
36+
<pre>
37+
<code>
38+
@FullyQualifiedOrgAndRepo
39+
</code>
40+
</pre>
41+
</div>
42+
<button class="btn btn-lg btn-primary" type="button"
43+
disabled=@(_organizationName is null || _repositoryName is null)
44+
@onclick="OnAssignClick">
45+
Assign
46+
</button>
47+
</form>
48+
}
49+
</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
using GitHub.RepositoryExplorer.Client.Extensions;
2+
3+
namespace GitHub.RepositoryExplorer.Client.Components;
4+
5+
public sealed partial class ConfigureRepo
6+
{
7+
private string? _organizationName;
8+
private string? _repositoryName;
9+
private bool _isEditing = false;
10+
private ErrorBoundary? _errorBoundary;
11+
12+
[Inject]
13+
public AppInMemoryStateService AppState { get; set; } = null!;
14+
15+
[Inject]
16+
public ILocalStorageService LocalStorage { get; set; } = null!;
17+
18+
[Parameter, EditorRequired]
19+
public RenderFragment PostConfigurationContent { get; set; } = null!;
20+
21+
[Parameter]
22+
public RenderFragment? OptionalMessageContent { get; set; }
23+
24+
public bool IsConfigured => AppState is { RepoState.IsAssigned: true };
25+
26+
public string FullyQualifiedOrgAndRepo =>
27+
$"https://github.com/{_organizationName ?? "org"}/{_repositoryName ?? "repo"}";
28+
29+
public void EditConfiguration() => _isEditing = true;
30+
31+
protected override void OnInitialized()
32+
{
33+
base.OnInitialized();
34+
35+
_organizationName = LocalStorage.TryGetItem<string>("github.org");
36+
_repositoryName = LocalStorage.TryGetItem<string>("github.repo");
37+
38+
if (RepoConfigurationDispatched(false))
39+
{
40+
StateHasChanged();
41+
}
42+
}
43+
44+
protected override void OnParametersSet() => _errorBoundary?.Recover();
45+
46+
private void OnAssignClick()
47+
{
48+
_ = RepoConfigurationDispatched(true);
49+
_isEditing = false;
50+
}
51+
52+
private bool RepoConfigurationDispatched(bool persistToLocalStorage)
53+
{
54+
if (_organizationName is null || _repositoryName is null)
55+
{
56+
return false;
57+
}
58+
59+
if (persistToLocalStorage)
60+
{
61+
LocalStorage.TrySetItem("github.org", _organizationName);
62+
LocalStorage.TrySetItem("github.repo", _repositoryName);
63+
}
64+
65+
AppState.RepoState = new Repository(
66+
_organizationName,
67+
_repositoryName);
68+
69+
return true;
70+
}
71+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<div class="d-flex align-items-center justify-content-center">
2+
<div class="fs-1 d-flex justify-content-center align-items-center">
3+
<strong class="p-5">@Message</strong>
4+
<div class="spinner-grow ms-auto" role="status" aria-hidden="true"></div>
5+
</div>
6+
</div>
7+
8+
@code {
9+
[Parameter]
10+
public string Message { get; set; } = "🤓 Loading, please wait...";
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
namespace GitHub.RepositoryExplorer.Client.Extensions;
2+
3+
internal static class LocalStorageServiceExtensions
4+
{
5+
internal static T? TryGetItem<T>(this ILocalStorageService localStorage, string key)
6+
{
7+
try
8+
{
9+
return localStorage.GetItem<T>(key);
10+
}
11+
catch
12+
{
13+
return default;
14+
}
15+
}
16+
17+
internal static void TrySetItem<T>(this ILocalStorageService localStorage, string key, T value)
18+
{
19+
try
20+
{
21+
localStorage.SetItem<T>(key, value);
22+
}
23+
catch { }
24+
}
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net7.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<UserSecretsId>1e8b5bf8-1a2d-446d-9cd3-48609334c53f</UserSecretsId>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<Content Remove="Pages\LineChartJS.razor" />
12+
</ItemGroup>
13+
14+
<ItemGroup>
15+
<PackageReference Include="Blazor.LocalStorage.WebAssembly" Version="7.0.0" />
16+
<PackageReference Include="ChartJs.Blazor.Fork" Version="2.0.2" />
17+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="7.0.2" />
18+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="7.0.2" PrivateAssets="all" />
19+
<PackageReference Include="Microsoft.Extensions.Http" Version="7.0.0" />
20+
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="7.0.0" />
21+
</ItemGroup>
22+
23+
<ItemGroup>
24+
<ProjectReference Include="..\GitHub.RepositoryExplorer.Models\GitHub.RepositoryExplorer.Models.csproj" />
25+
</ItemGroup>
26+
27+
<ItemGroup>
28+
<Content Update="wwwroot\appsettings.json">
29+
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
30+
</Content>
31+
</ItemGroup>
32+
33+
<ItemGroup>
34+
<UpToDateCheckInput Remove="Pages\LineChartJS.razor" />
35+
</ItemGroup>
36+
37+
<ItemGroup>
38+
<_ContentIncludedByDefault Remove="Pages\LineChartJS.razor" />
39+
</ItemGroup>
40+
41+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
global using GitHub.RepositoryExplorer.Client;
2+
global using GitHub.RepositoryExplorer.Client.Components;
3+
global using GitHub.RepositoryExplorer.Client.Options;
4+
global using GitHub.RepositoryExplorer.Client.Services;
5+
global using GitHub.RepositoryExplorer.Models;
6+
global using Microsoft.AspNetCore.Components;
7+
global using Microsoft.AspNetCore.Components.Web;
8+
global using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
9+
global using Microsoft.Extensions.DependencyInjection;
10+
global using Microsoft.Extensions.Options;
11+
global using Microsoft.JSInterop;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace GitHub.RepositoryExplorer.Client;
2+
3+
static class HttpClientNames
4+
{
5+
internal static string IssuesApi = nameof(IssuesApi);
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
public record class IssueSummary
2+
{
3+
public bool IsLoading { get; init; } = true;
4+
5+
public DateOnly Date { get; init; }
6+
7+
public IEnumerable<ProductIssueCount> Data { get; init; } =
8+
Array.Empty<ProductIssueCount>();
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
public record class RepoLabels
2+
{
3+
public bool IsLoading { get; init; } = true;
4+
5+
public IssueClassificationModel IssueClassification { get; init; } = new();
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
public record class Repository(
2+
string? Org,
3+
string? Repo)
4+
{
5+
public bool IsAssigned => Org is { Length: > 0 } && Repo is { Length: > 0 };
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace GitHub.RepositoryExplorer.Client.Options;
2+
3+
public class IssuesApiOptions
4+
{
5+
public string ServerUrl { get; set; } = null!;
6+
}

0 commit comments

Comments
 (0)