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

Commit 424439d

Browse files
committed
Show commit in TE when OID clicked.
1 parent 102e337 commit 424439d

File tree

20 files changed

+162
-39
lines changed

20 files changed

+162
-39
lines changed

src/GitHub.App/Models/RemoteRepositoryModel.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ public RemoteRepositoryModel(long id, string name, UriString cloneUrl, bool isPr
2525
: base(name, cloneUrl)
2626
{
2727
Guard.ArgumentNotEmptyString(name, nameof(name));
28-
Guard.ArgumentNotNull(ownerAccount, nameof(ownerAccount));
2928

3029
Id = id;
3130
OwnerAccount = ownerAccount;

src/GitHub.App/SampleData/Documents/PullRequestPageViewModelDesigner.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,17 @@ Depends on #1993
9191
public IActorViewModel Author { get; set; } = new ActorViewModelDesigner("grokys");
9292
public string Body { get; set; }
9393
public int Number { get; set; } = 1994;
94-
public IRepositoryModel Repository { get; set; }
94+
public ILocalRepositoryModel LocalRepository { get; }
95+
public IRemoteRepositoryModel Repository { get; set; }
9596
public string Title { get; set; } = "Save drafts of comments";
9697
public Uri WebUrl { get; set; }
9798
public ReactiveCommand<Unit, Unit> OpenOnGitHub { get; }
99+
public ReactiveCommand<string, Unit> ShowCommit { get; }
98100

99-
public Task InitializeAsync(ActorModel currentUser, PullRequestDetailModel model) => Task.CompletedTask;
101+
102+
public Task InitializeAsync(IRemoteRepositoryModel repository, ILocalRepositoryModel localRepository, ActorModel currentUser, PullRequestDetailModel model)
103+
{
104+
throw new NotImplementedException();
105+
}
100106
}
101107
}

src/GitHub.App/Services/GitClient.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,11 @@ public Task Checkout(IRepository repository, string branchName)
181181
});
182182
}
183183

184+
public async Task<bool> CommitExists(IRepository repository, string sha)
185+
{
186+
return await Task.Run(() => repository.Lookup<Commit>(sha) != null).ConfigureAwait(false);
187+
}
188+
184189
public Task CreateBranch(IRepository repository, string branchName)
185190
{
186191
Guard.ArgumentNotNull(repository, nameof(repository));

src/GitHub.App/Services/PullRequestService.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,21 @@ public IObservable<Unit> Checkout(ILocalRepositoryModel repository, PullRequestD
567567
});
568568
}
569569

570+
public async Task<bool> FetchCommit(ILocalRepositoryModel localRepository, IRepositoryModel remoteRepository, string sha)
571+
{
572+
using (var repo = gitService.GetRepository(localRepository.LocalPath))
573+
{
574+
if (!await gitClient.CommitExists(repo, sha).ConfigureAwait(false))
575+
{
576+
var remote = await CreateRemote(repo, remoteRepository.CloneUrl).ConfigureAwait(false);
577+
await gitClient.Fetch(repo, remote).ConfigureAwait(false);
578+
return await gitClient.CommitExists(repo, sha).ConfigureAwait(false);
579+
}
580+
581+
return true;
582+
}
583+
}
584+
570585
public IObservable<string> GetDefaultLocalBranchName(ILocalRepositoryModel repository, int pullRequestNumber, string pullRequestTitle)
571586
{
572587
return Observable.Defer(() =>
Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,31 @@
1-
using System;
2-
using GitHub.Models;
3-
using GitHub.ViewModels;
1+
using GitHub.Models;
42

53
namespace GitHub.ViewModels.Documents
64
{
75
public class CommitSummaryViewModel : ViewModelBase
86
{
9-
public CommitSummaryViewModel(CommitModel model)
7+
/// <summary>
8+
/// Initializes a new instance of the <see cref="CommitSummaryViewModel"/> class.
9+
/// </summary>
10+
/// <param name="commit">The commit model.</param>
11+
public CommitSummaryViewModel(CommitModel commit)
1012
{
11-
AbbreviatedOid = model.AbbreviatedOid;
12-
Author = new ActorViewModel(model.Author);
13-
Header = model.MessageHeadline;
13+
AbbreviatedOid = commit.AbbreviatedOid;
14+
Author = new ActorViewModel(commit.Author);
15+
Header = commit.MessageHeadline;
16+
Oid = commit.Oid;
1417
}
1518

16-
public string AbbreviatedOid { get; }
17-
public IActorViewModel Author { get; }
18-
public string Header { get; }
19+
/// <inheritdoc/>
20+
public string AbbreviatedOid { get; private set; }
21+
22+
/// <inheritdoc/>
23+
public IActorViewModel Author { get; private set; }
24+
25+
/// <inheritdoc/>
26+
public string Header { get; private set; }
27+
28+
/// <inheritdoc/>
29+
public string Oid { get; private set; }
1930
}
2031
}

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,21 @@ public async Task Load(IConnection connection, string owner, string name, int nu
4949
{
5050
var session = await sessionManager.GetSession(owner, name, number).ConfigureAwait(true);
5151
var vm = factory.CreateViewModel<IPullRequestPageViewModel>();
52-
await vm.InitializeAsync(session.User, session.PullRequest).ConfigureAwait(true);
52+
53+
var repository = new RemoteRepositoryModel(
54+
0,
55+
name,
56+
session.LocalRepository.CloneUrl.WithOwner(session.PullRequest.HeadRepositoryOwner),
57+
false,
58+
false,
59+
null,
60+
null);
61+
62+
await vm.InitializeAsync(
63+
repository,
64+
session.LocalRepository,
65+
session.User,
66+
session.PullRequest).ConfigureAwait(true);
5367
Content = vm;
5468
}
5569
catch (Exception ex)

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

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.ComponentModel.Composition;
4+
using System.Reactive;
45
using System.Threading.Tasks;
56
using GitHub.Extensions;
67
using GitHub.Factories;
@@ -19,7 +20,9 @@ namespace GitHub.ViewModels.Documents
1920
public class PullRequestPageViewModel : PullRequestViewModelBase, IPullRequestPageViewModel, ICommentThreadViewModel
2021
{
2122
readonly IViewViewModelFactory factory;
23+
readonly IPullRequestService service;
2224
readonly IPullRequestSessionManager sessionManager;
25+
readonly ITeamExplorerServices teServices;
2326

2427
/// <summary>
2528
/// Initializes a new instance of the <see cref="PullRequestPageViewModel"/> class.
@@ -28,13 +31,21 @@ public class PullRequestPageViewModel : PullRequestViewModelBase, IPullRequestPa
2831
[ImportingConstructor]
2932
public PullRequestPageViewModel(
3033
IViewViewModelFactory factory,
31-
IPullRequestSessionManager sessionManager)
34+
IPullRequestService service,
35+
IPullRequestSessionManager sessionManager,
36+
ITeamExplorerServices teServices)
3237
{
3338
Guard.ArgumentNotNull(factory, nameof(factory));
39+
Guard.ArgumentNotNull(service, nameof(service));
3440
Guard.ArgumentNotNull(sessionManager, nameof(sessionManager));
41+
Guard.ArgumentNotNull(teServices, nameof(teServices));
3542

3643
this.factory = factory;
44+
this.service = service;
3745
this.sessionManager = sessionManager;
46+
this.teServices = teServices;
47+
48+
ShowCommit = ReactiveCommand.CreateFromTask<string>(DoShowCommit);
3849
}
3950

4051
/// <inheritdoc/>
@@ -43,15 +54,20 @@ public PullRequestPageViewModel(
4354
/// <inheritdoc/>
4455
public IReadOnlyList<IViewModel> Timeline { get; private set; }
4556

57+
/// <inheritdoc/>
58+
public ReactiveCommand<string, Unit> ShowCommit { get; }
59+
4660
/// <inheritdoc/>
4761
IReadOnlyReactiveList<ICommentViewModel> ICommentThreadViewModel.Comments => throw new NotImplementedException();
4862

4963
/// <inheritdoc/>
5064
public async Task InitializeAsync(
65+
IRemoteRepositoryModel repository,
66+
ILocalRepositoryModel localRepository,
5167
ActorModel currentUser,
5268
PullRequestDetailModel model)
5369
{
54-
await base.InitializeAsync(model).ConfigureAwait(true);
70+
await base.InitializeAsync(repository, localRepository, model).ConfigureAwait(true);
5571

5672
CurrentUser = new ActorViewModel(currentUser);
5773

@@ -72,9 +88,11 @@ public async Task InitializeAsync(
7288
commits.Add(new CommitSummaryViewModel(commit));
7389
break;
7490
case CommentModel comment:
75-
var vm = factory.CreateViewModel<ICommentViewModel>();
76-
await vm.InitializeAsync(this, currentUser, comment, CommentEditState.None).ConfigureAwait(true);
77-
timeline.Add(vm);
91+
{
92+
var vm = factory.CreateViewModel<ICommentViewModel>();
93+
await vm.InitializeAsync(this, currentUser, comment, CommentEditState.None).ConfigureAwait(true);
94+
timeline.Add(vm);
95+
}
7896
break;
7997
}
8098
}
@@ -101,5 +119,11 @@ Task ICommentThreadViewModel.PostComment(string body)
101119
{
102120
throw new NotImplementedException();
103121
}
122+
123+
async Task DoShowCommit(string oid)
124+
{
125+
await service.FetchCommit(LocalRepository, Repository, oid).ConfigureAwait(true);
126+
teServices.ShowCommitDetails(oid);
127+
}
104128
}
105129
}

src/GitHub.App/ViewModels/IssueishViewModel.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public IssueishViewModel()
3030
}
3131

3232
/// <inheritdoc/>
33-
public IRepositoryModel Repository { get; private set; }
33+
public IRemoteRepositoryModel Repository { get; private set; }
3434

3535
/// <inheritdoc/>
3636
public int Number { get; private set; }
@@ -66,8 +66,11 @@ public Uri WebUrl
6666
/// <inheritdoc/>
6767
public ReactiveCommand<Unit, Unit> OpenOnGitHub { get; }
6868

69-
protected Task InitializeAsync(IssueishDetailModel model)
69+
protected Task InitializeAsync(
70+
IRemoteRepositoryModel repository,
71+
IssueishDetailModel model)
7072
{
73+
Repository = repository;
7174
Author = new ActorViewModel(model.Author);
7275
Body = model.Body;
7376
Number = model.Number;

src/GitHub.App/ViewModels/PullRequestViewModelBase.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ public PullRequestViewModelBase()
2626
{
2727
}
2828

29+
/// <inheritdoc/>
30+
public ILocalRepositoryModel LocalRepository { get; private set; }
31+
2932
public PullRequestState State
3033
{
3134
get => state;
@@ -44,11 +47,15 @@ public string TargetBranchDisplayName
4447
private set => this.RaiseAndSetIfChanged(ref targetBranchDisplayName, value);
4548
}
4649

47-
protected virtual async Task InitializeAsync(PullRequestDetailModel model)
50+
protected virtual async Task InitializeAsync(
51+
IRemoteRepositoryModel repository,
52+
ILocalRepositoryModel localRepository,
53+
PullRequestDetailModel model)
4854
{
49-
await base.InitializeAsync(model).ConfigureAwait(true);
55+
await base.InitializeAsync(repository, model).ConfigureAwait(true);
5056

5157
var fork = model.BaseRepositoryOwner != model.HeadRepositoryOwner;
58+
LocalRepository = localRepository;
5259
SourceBranchDisplayName = GetBranchDisplayName(fork, model.HeadRepositoryOwner, model.HeadRefName);
5360
TargetBranchDisplayName = GetBranchDisplayName(fork, model.BaseRepositoryOwner, model.BaseRefName);
5461
}

src/GitHub.Exports.Reactive/Services/IGitClient.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,14 @@ public interface IGitClient
6464
/// <returns></returns>
6565
Task Checkout(IRepository repository, string branchName);
6666

67+
/// <summary>
68+
/// Checks if a commit exists a the repository.
69+
/// </summary>
70+
/// <param name="repository">The repository.</param>
71+
/// <param name="sha">The SHA of the commit.</param>
72+
/// <returns></returns>
73+
Task<bool> CommitExists(IRepository repository, string sha);
74+
6775
/// <summary>
6876
/// Creates a new branch.
6977
/// </summary>

0 commit comments

Comments
 (0)