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

Commit 102e337

Browse files
committed
Load PR timeline from GraphQL.
And display its commits and comments in the conversation view.
1 parent 02bc4ee commit 102e337

19 files changed

+132
-54
lines changed
-194 KB
Binary file not shown.
213 KB
Binary file not shown.

src/GitHub.Api/GitHub.Api.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@
3030
<ItemGroup>
3131
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.6.1" />
3232
<PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
33-
<PackageReference Include="Octokit.GraphQL" Version="0.1.1-beta" />
33+
<PackageReference Include="Octokit.GraphQL" Version="0.2.0-beta" />
3434
</ItemGroup>
3535
</Project>

src/GitHub.App/GitHub.App.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
<PackageReference Include="Microsoft.VisualStudio.SDK.EmbedInteropTypes" Version="15.0.17" />
5050
<PackageReference Include="Microsoft.VisualStudio.Shell.14.0" Version="14.3.25407" />
5151
<PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
52-
<PackageReference Include="Octokit.GraphQL" Version="0.1.1-beta" />
52+
<PackageReference Include="Octokit.GraphQL" Version="0.2.0-beta" />
5353
<PackageReference Include="Rothko" Version="0.0.3-ghfvs" />
5454
<PackageReference Include="Serilog" Version="2.5.0" />
5555
<PackageReference Include="SerilogAnalyzer" Version="0.12.0.0" />

src/GitHub.App/Services/PullRequestService.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public async Task<Page<PullRequestListItemModel>> ReadPullRequests(
9090
if (readPullRequests == null)
9191
{
9292
readPullRequests = new Query()
93-
.Repository(Var(nameof(owner)), Var(nameof(name)))
93+
.Repository(owner: Var(nameof(owner)), name: Var(nameof(name)))
9494
.PullRequests(
9595
first: 100,
9696
after: Var(nameof(after)),
@@ -151,7 +151,7 @@ public async Task<Page<PullRequestListItemModel>> ReadPullRequests(
151151
if (readPullRequestsEnterprise == null)
152152
{
153153
readPullRequestsEnterprise = new Query()
154-
.Repository(Var(nameof(owner)), Var(nameof(name)))
154+
.Repository(owner: Var(nameof(owner)), name: Var(nameof(name)))
155155
.PullRequests(
156156
first: 100,
157157
after: Var(nameof(after)),
@@ -290,7 +290,7 @@ public async Task<Page<ActorModel>> ReadAssignableUsers(
290290
if (readAssignableUsers == null)
291291
{
292292
readAssignableUsers = new Query()
293-
.Repository(Var(nameof(owner)), Var(nameof(name)))
293+
.Repository(owner: Var(nameof(owner)), name: Var(nameof(name)))
294294
.AssignableUsers(first: 100, after: Var(nameof(after)))
295295
.Select(connection => new Page<ActorModel>
296296
{

src/GitHub.App/Services/RepositoryCloneService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,13 @@ public async Task<ViewerRepositoriesModel> ReadViewerRepositories(HostAddress ad
8888
.Select(viewer => new ViewerRepositoriesModel
8989
{
9090
Owner = viewer.Login,
91-
Repositories = viewer.Repositories(null, null, null, null, null, order, affiliation, null, null)
91+
Repositories = viewer.Repositories(null, null, null, null, affiliation, null, null, order, null, null)
9292
.AllPages()
9393
.Select(repositorySelection).ToList(),
9494
OrganizationRepositories = viewer.Organizations(null, null, null, null).AllPages().Select(org => new
9595
{
9696
org.Login,
97-
Repositories = org.Repositories(null, null, null, null, null, order, null, null, null)
97+
Repositories = org.Repositories(null, null, null, null, null, null, null, order, null, null)
9898
.AllPages()
9999
.Select(repositorySelection).ToList()
100100
}).ToDictionary(x => x.Login, x => (IReadOnlyList<RepositoryListItemModel>)x.Repositories),

src/GitHub.App/Services/RepositoryService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public RepositoryService(IGraphQLClientFactory graphqlFactory)
3434
if (readParentOwnerLogin == null)
3535
{
3636
readParentOwnerLogin = new Query()
37-
.Repository(Var(nameof(owner)), Var(nameof(name)))
37+
.Repository(owner: Var(nameof(owner)), name: Var(nameof(name)))
3838
.Select(r => r.Parent != null ? Tuple.Create(r.Parent.Owner.Login, r.Parent.Name) : null)
3939
.Compile();
4040
}

src/GitHub.App/ViewModels/Documents/CommitSummariesViewModel.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Collections.Generic;
2+
using System.Linq;
23

34
namespace GitHub.ViewModels.Documents
45
{
@@ -9,6 +10,11 @@ public CommitSummariesViewModel(params CommitSummaryViewModel[] commits)
910
Commits = commits;
1011
}
1112

13+
public CommitSummariesViewModel(IEnumerable<CommitSummaryViewModel> commits)
14+
{
15+
Commits = commits.ToList();
16+
}
17+
1218
public IReadOnlyList<CommitSummaryViewModel> Commits { get; }
1319
}
1420
}

src/GitHub.App/ViewModels/Documents/CommitSummaryViewModel.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ public class CommitSummaryViewModel : ViewModelBase
99
public CommitSummaryViewModel(CommitModel model)
1010
{
1111
AbbreviatedOid = model.AbbreviatedOid;
12+
Author = new ActorViewModel(model.Author);
1213
Header = model.MessageHeadline;
1314
}
1415

1516
public string AbbreviatedOid { get; }
17+
public IActorViewModel Author { get; }
1618
public string Header { get; }
1719
}
1820
}

src/GitHub.App/ViewModels/Documents/PullRequestPageViewModel.cs

Lines changed: 50 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace GitHub.ViewModels.Documents
1616
/// </summary>
1717
[Export(typeof(IPullRequestPageViewModel))]
1818
[PartCreationPolicy(CreationPolicy.NonShared)]
19-
public class PullRequestPageViewModel : PullRequestViewModelBase, IPullRequestPageViewModel
19+
public class PullRequestPageViewModel : PullRequestViewModelBase, IPullRequestPageViewModel, ICommentThreadViewModel
2020
{
2121
readonly IViewViewModelFactory factory;
2222
readonly IPullRequestSessionManager sessionManager;
@@ -37,44 +37,69 @@ public PullRequestPageViewModel(
3737
this.sessionManager = sessionManager;
3838
}
3939

40+
/// <inheritdoc/>
41+
public IActorViewModel CurrentUser { get; private set; }
42+
4043
/// <inheritdoc/>
4144
public IReadOnlyList<IViewModel> Timeline { get; private set; }
4245

46+
/// <inheritdoc/>
47+
IReadOnlyReactiveList<ICommentViewModel> ICommentThreadViewModel.Comments => throw new NotImplementedException();
48+
4349
/// <inheritdoc/>
4450
public async Task InitializeAsync(
4551
ActorModel currentUser,
4652
PullRequestDetailModel model)
4753
{
4854
await base.InitializeAsync(model).ConfigureAwait(true);
4955

50-
Timeline = new IViewModel[]
56+
CurrentUser = new ActorViewModel(currentUser);
57+
58+
var timeline = new ReactiveList<IViewModel>();
59+
var commits = new List<CommitSummaryViewModel>();
60+
61+
foreach (var i in model.Timeline)
5162
{
52-
new CommitSummariesViewModel(
53-
new CommitSummaryViewModel(new CommitModel
54-
{
55-
Author = new ActorModel { Login = "grokys" },
56-
AbbreviatedOid = "c7c7d25",
57-
MessageHeadline = "Refactor comment view models."
58-
}),
59-
new CommitSummaryViewModel(new CommitModel
60-
{
61-
Author = new ActorModel { Login = "grokys" },
62-
AbbreviatedOid = "04e6a90",
63-
MessageHeadline = "Refactor comment view models.",
64-
})),
65-
new CommentViewModelDesigner
63+
if (!(i is CommitModel) && commits.Count > 0)
6664
{
67-
Author = new ActorViewModelDesigner("meaghanlewis"),
68-
Body = @"This is looking great! Really enjoying using this feature so far.
65+
timeline.Add(new CommitSummariesViewModel(commits));
66+
commits.Clear();
67+
}
6968

70-
When leaving an inline comment, the comment posts successfully and then a new comment is drafted with the same text.",
71-
},
72-
new CommentViewModelDesigner
69+
switch (i)
7370
{
74-
Author = new ActorViewModelDesigner("grokys"),
75-
Body = @"Oops, sorry about that @meaghanlewis - I was sure I tested those things, but must have got messed up again at some point. Should be fixed now.",
76-
},
77-
};
71+
case CommitModel commit:
72+
commits.Add(new CommitSummaryViewModel(commit));
73+
break;
74+
case CommentModel comment:
75+
var vm = factory.CreateViewModel<ICommentViewModel>();
76+
await vm.InitializeAsync(this, currentUser, comment, CommentEditState.None).ConfigureAwait(true);
77+
timeline.Add(vm);
78+
break;
79+
}
80+
}
81+
82+
if (commits.Count > 0)
83+
{
84+
timeline.Add(new CommitSummariesViewModel(commits));
85+
}
86+
87+
Timeline = timeline;
88+
}
89+
90+
Task ICommentThreadViewModel.DeleteComment(int pullRequestId, int commentId)
91+
{
92+
throw new NotImplementedException();
93+
}
94+
95+
Task ICommentThreadViewModel.EditComment(string id, string body)
96+
{
97+
throw new NotImplementedException();
98+
}
99+
100+
Task ICommentThreadViewModel.PostComment(string body)
101+
{
102+
throw new NotImplementedException();
78103
}
79104
}
80105
}

0 commit comments

Comments
 (0)