Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.
Closed
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
13 changes: 4 additions & 9 deletions src/GitHub.App/Services/RepositoryCloneService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,11 @@ public async Task<ViewerRepositoriesModel> ReadViewerRepositories(HostAddress ad
Direction = OrderDirection.Asc
};

// Pass this for affiliations and ownerAffiliations. See:
// https://platform.github.9909958.xyzmunity/t/unable-to-fetch-users-repositories-by-organization-membership/7557/6
var affiliation = new RepositoryAffiliation?[]
{
RepositoryAffiliation.Owner, RepositoryAffiliation.Collaborator
RepositoryAffiliation.Owner, RepositoryAffiliation.Collaborator, RepositoryAffiliation.OrganizationMember
};

var repositorySelection = new Fragment<Repository, RepositoryListItemModel>(
Expand All @@ -94,16 +96,9 @@ public async Task<ViewerRepositoriesModel> ReadViewerRepositories(HostAddress ad
.Select(viewer => new ViewerRepositoriesModel
{
Owner = viewer.Login,
Repositories = viewer.Repositories(null, null, null, null, null, null, null, order, affiliation, null)
Repositories = viewer.Repositories(null, null, null, null, affiliation, null, null, order, affiliation, RepositoryPrivacy.Private)
.AllPages()
.Select(repositorySelection).ToList(),
Organizations = viewer.Organizations(null, null, null, null).AllPages().Select(org => new
{
org.Login,
Repositories = org.Repositories(null, null, null, null, null, null, null, order, null, null)
.AllPages()
.Select(repositorySelection).ToList()
}).ToDictionary(x => x.Login, x => (IReadOnlyList<RepositoryListItemModel>)x.Repositories),
}).Compile();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,19 +108,20 @@ public async Task Activate()

try
{
var results = await service.ReadViewerRepositories(connection.HostAddress).ConfigureAwait(true);
var results = await log.TimeAsync(nameof(service.ReadViewerRepositories),
() => service.ReadViewerRepositories(connection.HostAddress));

var yourRepositories = results.Repositories
.Where(r => r.Owner == results.Owner)
.Select(x => new RepositoryItemViewModel(x, "Your repositories"));
var collaboratorRepositories = results.Repositories

var orgRepositories = results.Repositories
.Where(r => r.Owner != results.Owner)
.OrderBy(r => r.Owner)
.Select(x => new RepositoryItemViewModel(x, "Collaborator repositories"));
var orgRepositories = results.Organizations
.OrderBy(x => x.Key)
.SelectMany(x => x.Value.Select(y => new RepositoryItemViewModel(y, x.Key)));
Items = yourRepositories.Concat(collaboratorRepositories).Concat(orgRepositories).ToList();
.Select(r => new RepositoryItemViewModel(r, r.Owner));

Items = yourRepositories.Concat(orgRepositories).ToList();
log.Information("Read {Total} viewer repositories", Items.Count);
ItemsView = CollectionViewSource.GetDefaultView(Items);
ItemsView.GroupDescriptions.Add(new PropertyGroupDescription(nameof(RepositoryItemViewModel.Group)));
ItemsView.Filter = FilterItem;
Expand Down
1 change: 0 additions & 1 deletion src/GitHub.Exports/Models/ViewerRepositoriesModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@ public class ViewerRepositoriesModel
{
public string Owner { get; set; }
public IReadOnlyList<RepositoryListItemModel> Repositories { get; set; }
public IDictionary<string, IReadOnlyList<RepositoryListItemModel>> Organizations { get; set; }
}
}
22 changes: 13 additions & 9 deletions src/GitHub.InlineReviews/Services/PullRequestSessionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public IReadOnlyList<InlineAnnotationModel> BuildAnnotations(
relativePath = relativePath.Replace("\\", "/");

return pullRequest.CheckSuites
?.SelectMany(checkSuite => checkSuite.CheckRuns.Select(checkRun => new { checkSuite, checkRun}))
?.SelectMany(checkSuite => checkSuite.CheckRuns.Select(checkRun => new { checkSuite, checkRun }))
.SelectMany(arg =>
arg.checkRun.Annotations
.Where(annotation => annotation.Path == relativePath)
Expand Down Expand Up @@ -361,17 +361,21 @@ public virtual async Task<PullRequestDetailModel> ReadPullRequestDetail(HostAddr
var result = await connection.Run(readPullRequest, vars);

var apiClient = await apiClientFactory.Create(address);
var files = await apiClient.GetPullRequestFiles(owner, name, number).ToList();
var lastCommitModel = await GetPullRequestLastCommitAdapter(address, owner, name, number);

result.Statuses = (IReadOnlyList<StatusModel>) lastCommitModel.Statuses ?? Array.Empty<StatusModel>();
var files = await log.TimeAsync(nameof(apiClient.GetPullRequestFiles),
async () => await apiClient.GetPullRequestFiles(owner, name, number).ToList());

var lastCommitModel = await log.TimeAsync(nameof(GetPullRequestLastCommitAdapter),
() => GetPullRequestLastCommitAdapter(address, owner, name, number));

result.Statuses = (IReadOnlyList<StatusModel>)lastCommitModel.Statuses ?? Array.Empty<StatusModel>();

if (lastCommitModel.CheckSuites == null)
{
result.CheckSuites = Array.Empty<CheckSuiteModel>();
}
else
{
{
result.CheckSuites = lastCommitModel.CheckSuites;
foreach (var checkSuite in result.CheckSuites)
{
Expand Down Expand Up @@ -838,8 +842,8 @@ async Task<LastCommitAdapter> GetPullRequestLastCommitAdapter(HostAddress addres
commit => new LastCommitAdapter
{
Statuses = commit.Commit.Status == null ? null : commit.Commit.Status
.Select(context => context == null
? null
.Select(context => context == null
? null
: context.Contexts
.Select(statusContext => new StatusModel
{
Expand Down Expand Up @@ -871,7 +875,7 @@ async Task<LastCommitAdapter> GetPullRequestLastCommitAdapter(HostAddress addres
static void BuildPullRequestThreads(PullRequestDetailModel model)
{
var commentsByReplyId = new Dictionary<string, List<CommentAdapter>>();

// Get all comments that are not replies.
foreach (CommentAdapter comment in model.Reviews.SelectMany(x => x.Comments))
{
Expand Down Expand Up @@ -961,5 +965,5 @@ class LastCommitAdapter

public string HeadSha { get; set; }
}
}
}
}
37 changes: 36 additions & 1 deletion src/GitHub.Logging/Logging/ILoggerExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
using System;
using System.Globalization;
using System.Threading.Tasks;
using Serilog;

namespace GitHub.Logging
Expand Down Expand Up @@ -25,5 +28,37 @@ public static void Assert(this ILogger logger, bool condition, string messageTem
#pragma warning restore Serilog004
}
}

public static void Time(this ILogger logger, string name, Action method)
{
var startTime = DateTime.Now;
method();
logger.Information("{Name} took {Seconds} seconds", name, FormatSeconds(DateTime.Now - startTime));
}

public static T Time<T>(this ILogger logger, string name, Func<T> method)
{
var startTime = DateTime.Now;
var value = method();
logger.Information("{Name} took {Seconds} seconds", name, FormatSeconds(DateTime.Now - startTime));
return value;
}

public static async Task TimeAsync(this ILogger logger, string name, Func<Task> methodAsync)
{
var startTime = DateTime.Now;
await methodAsync().ConfigureAwait(false);
logger.Information("{Name} took {Seconds} seconds", name, FormatSeconds(DateTime.Now - startTime));
}

public static async Task<T> TimeAsync<T>(this ILogger logger, string name, Func<Task<T>> methodAsync)
{
var startTime = DateTime.Now;
var value = await methodAsync().ConfigureAwait(false);
logger.Information("{Name} took {Seconds} seconds", name, FormatSeconds(DateTime.Now - startTime));
return value;
}

static string FormatSeconds(TimeSpan timeSpan) => timeSpan.TotalSeconds.ToString("0.##", CultureInfo.InvariantCulture);
}
}
}