8000 Add VS command to show current PR details by jcansdale · Pull Request #1128 · github/VisualStudio · GitHub
[go: up one dir, main page]

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

Add VS command to show current PR details #1128

Merged
merged 7 commits into from
Nov 9, 2017
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
5 changes: 3 additions & 2 deletions src/GitHub.App/Models/PullRequestDetailArgument.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using GitHub.ViewModels;
using GitHub.Primitives;

namespace GitHub.Models
{
Expand All @@ -9,9 +10,9 @@ namespace GitHub.Models
public class PullRequestDetailArgument
{
/// <summary>
10000 /// Gets or sets the repository containing the pull request.
/// Gets or sets the owner of the repository containing the pull request.
/// </summary>
public IRemoteRepositoryModel Repository { get; set; }
public string RepositoryOwner { get; set; }

/// <summary>
/// Gets or sets the number of the pull request.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public PullRequestDetailViewModelDesigner()
{
var repoPath = @"C:\Repo";

Model = new PullRequestModel(419,
Model = new PullRequestModel(419,
"Error handling/bubbling from viewmodels to views to viewhosts",
new AccountDesigner { Login = "shana", IsUser = true },
DateTime.Now.Subtract(TimeSpan.FromDays(3)))
Expand Down Expand Up @@ -75,7 +75,7 @@ public PullRequestDetailViewModelDesigner()
public IPullRequestModel Model { get; }
public IPullRequestSession Session { get; }
public ILocalRepositoryModel LocalRepository { get; }
public IRemoteRepositoryModel RemoteRepository { get; }
public string RemoteRepositoryOwner { get; }
public string SourceBranchDisplayName { get; set; }
public string TargetBranchDisplayName { get; set; }
public int CommentCount { get; set; }
Expand Down
20 changes: 10 additions & 10 deletions src/GitHub.App/ViewModels/PullRequestDetailViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,13 @@ private set
public ILocalRepositoryModel LocalRepository { get; }

/// <summary>
/// Gets the remote repository that contains the pull request.
/// Gets the owner of the remote repository that contains the pull request.
/// </summary>
/// <remarks>
/// The remote repository may be different from the local repository if the local
/// repository is a fork and the user is viewing pull requests from the parent repository.
/// </remarks>
public IRemoteRepositoryModel RemoteRepository { get; private set; }
public string RemoteRepositoryOwner { get; private set; }

/// <summary>
/// Gets the session for the pull request.
Expand Down Expand Up @@ -326,13 +326,13 @@ public IReadOnlyList<IPullRequestChangeNode> ChangedFilesTree
public override void Initialize(ViewWithData data)
{
int number;
var repo = RemoteRepository;
var repoOwner = RemoteRepositoryOwner;

if (data != null)
{
var arg = (PullRequestDetailArgument)data.Data;
number = arg.Number;
repo = arg.Repository;
repoOwner = arg.RepositoryOwner;
}
else
{
Expand All @@ -349,7 +349,7 @@ public override void Initialize(ViewWithData data)
}

ErrorMessage = OperationError = null;
modelService.GetPullRequest(repo, number)
modelService.GetPullRequest(repoOwner, LocalRepository.Name, number)
.TakeLast(1)
.ObserveOn(RxApp.MainThreadScheduler)
.Catch<IPullRequestModel, Exception>(ex =>
Expand All @@ -359,23 +359,23 @@ public override void Initialize(ViewWithData data)
IsLoading = IsBusy = false;
return Observable.Empty<IPullRequestModel>();
})
.Subscribe(x => Load(repo, x).Forget());
.Subscribe(x => Load(repoOwner, x).Forget());
}

/// <summary>
/// Loads the view model from octokit models.
/// </summary>
/// <param name="remoteRepository">The remote repository.</param>
/// <param name="remoteRepositoryOwner">The owner of the remote repository.</param>
/// <param name="pullRequest">The pull request model.</param>
public async Task Load(IRemoteRepositoryModel remoteRepository, IPullRequestModel pullRequest)
public async Task Load(string remoteRepositoryOwner, IPullRequestModel pullRequest)
{
Guard.ArgumentNotNull(remoteRepository, nameof(remoteRepository));
Guard.ArgumentNotNull(remoteRepositoryOwner, nameof(remoteRepositoryOwner));

try
{
var firstLoad = (Model == null);
Model = pullRequest;
RemoteRepository = remoteRepository;
RemoteRepositoryOwner = remoteRepositoryOwner;
Session = await sessionManager.GetSession(pullRequest);
Title = Resources.PullRequestNavigationItemText + " #" + pullRequest.Number;

Expand Down
2 changes: 1 addition & 1 deletion src/GitHub.App/ViewModels/PullRequestListViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ void DoOpenPullRequest(object pullRequest)
{
Data = new PullRequestDetailArgument
{
Repository = SelectedRepository,
RepositoryOwner = SelectedRepository.Owner,
Number = (int)pullRequest,
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,13 @@ public interface IPullRequestDetailViewModel : IViewModel, IHasLoading, IHasBusy
ILocalRepositoryModel LocalRepository { get; }

/// <summary>
/// Gets the remote repository that contains the pull request.
/// Gets the owner of the remote repository that contains the pull request.
/// </summary>
/// <remarks>
/// The remote repository may be different from the local repository if the local
/// repository is a fork and the user is viewing pull requests from the parent repository.
/// </remarks>
IRemoteRepositoryModel RemoteRepository { get; }
string RemoteRepositoryOwner { get; }

/// <summary>
/// Gets a string describing how to display the pull request's source branch.
Expand Down
1 change: 1 addition & 0 deletions src/GitHub.Exports/Settings/PkgCmdID.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public static class PkgCmdIDList
public const int idGitHubToolbar = 0x1120;
public const int showGitHubPaneCommand = 0x200;
public const int openPullRequestsCommand = 0x201;
public const int showCurrentPullRequestCommand = 0x202;
public const int backCommand = 0x300;
public const int forwardCommand = 0x301;
public const int refreshCommand = 0x302;
Expand Down
1 change: 1 addition & 0 deletions src/GitHub.VisualStudio/GitHub.VisualStudio.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@
<Compile Include="Helpers\ActiveDocumentSnapshot.cs" />
<Compile Include="Menus\OpenLink.cs" />
<Compile Include="Menus\LinkMenuBase.cs" />
<Compile Include="Menus\ShowCurrentPullRequest.cs" />
<Compile Include="Menus\OpenPullRequests.cs" />
<Compile Include="Menus\ShowGitHubPane.cs" />
<Compile Include="Menus\AddConnection.cs" />
Expand Down
21 changes: 16 additions & 5 deletions src/GitHub.VisualStudio/GitHub.VisualStudio.vsct
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,16 @@
</Strings>
</Button>

<Button guid="guidGitHubCmdSet" id="showCurrentPullRequestCommand" type="Button">
<Icon guid="guidImages" id="logo" />
<CommandFlag>IconIsMoniker</CommandFlag>
<Strings>
<ButtonText>Show Current Pull Request</ButtonText>
<CanonicalName>GitHub.ShowCurrentPullRequest</CanonicalName>
<LocCanonicalName>GitHub.ShowCurrentPullRequest</LocCanonicalName>
</Strings>
</Button>

<!--- Toolbar buttons -->
<Button guid="guidGitHubToolbarCmdSet" id="backCommand" type="Button">
<Icon guid="guidImages" id="arrow_left" />
Expand Down Expand Up @@ -181,13 +191,13 @@
<ButtonText>Blame</ButtonText>
</Strings>
</Button>

</Buttons>

</Commands>

<CommandPlacements>

<!-- context menu -->
<CommandPlacement guid="guidContextMenuSet" id="idGitHubContextMenuGroup" priority="0x1000">
<Parent guid="GUID_XAML_EDITOR" id="ID_XAML_CTXT"/>
Expand Down Expand Up @@ -260,7 +270,7 @@
</CommandPlacement>

</CommandPlacements>

<Symbols>
<!-- This is the package guid. -->
<GuidSymbol name="guidGitHubPkg" value="{c3d3dc68-c977-411f-b3e8-03b0dccf7dfc}" />
Expand All @@ -271,13 +281,14 @@
<IDSymbol name="idGitHubMenuGroup" value="0x1020"/>
<IDSymbol name="addConnectionCommand" value="0x110"/>
<IDSymbol name="showGitHubPaneCommand" value="0x200"/>
<IDSymbol name="showCurrentPullRequestCommand" value="0x202"/>
</GuidSymbol>

<!-- This is the Manage Connections menu -->
<GuidSymbol name="guidManageConnections" value="{0A014553-A0AA-46DD-8D6B-B8E3178CA435}">
<IDSymbol name="idManageConnections" value="0x1009"/>
</GuidSymbol>

<GuidSymbol name="guidImages" value="{27841f47-070a-46d6-90be-a5cbbfc724ac}" >
<IDSymbol name="logo" value="1" />
<IDSymbol name="arrow_left" value="2" />
E 10000 xpand Down Expand Up @@ -313,7 +324,7 @@
<IDSymbol name="idBlameCommand" value="0x0500" />

</GuidSymbol>

<GuidSymbol name="GUID_XAML_EDITOR" value="{4C87B692-1202-46AA-B64C-EF01FAEC53DA}">
<IDSymbol name="ID_XAML_CTXT" value="259"/>
</GuidSymbol>
Expand Down
3 changes: 2 additions & 1 deletion src/GitHub.VisualStudio/Menus/MenuProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ public MenuProvider(IGitHubServiceProvider serviceProvider)
{
new AddConnection(serviceProvider),
new OpenPullRequests(serviceProvider),
new ShowGitHubPane(serviceProvider)
new ShowGitHubPane(serviceProvider),
new ShowCurrentPullRequest(serviceProvider)
};

DynamicMenus = new List<IDynamicMenuHandler>
Expand Down
40 changes: 40 additions & 0 deletions src/GitHub.VisualStudio/Menus/ShowCurrentPullRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;
using GitHub.Exports;
using GitHub.UI;
using GitHub.Services;
using GitHub.Extensions;
using GitHub.Models;

namespace GitHub.VisualStudio.Menus
{
[ExportMenu(MenuType = MenuType.OpenPullRequests)]
public class ShowCurrentPullRequest : MenuBase, IMenuHandler
{
public ShowCurrentPullRequest(IGitHubServiceProvider serviceProvider)
: base(serviceProvider)
{
Guard.ArgumentNotNull(serviceProvider, nameof(serviceProvider));
}

public Guid Guid => Guids.guidGitHubCmdSet;
public int CmdId => PkgCmdIDList.showCurrentPullRequestCommand;

public void Activate(object data = null)
{
var pullRequestSessionManager = ServiceProvider.ExportProvider.GetExportedValueOrDefault<IPullRequestSessionManager>();
var session = pullRequestSessionManager?.CurrentSession;
if (session == null)
{
return; // No active PR session.
}

var pullRequest = session.PullRequest;
var arg = new PullRequestDetailArgument { RepositoryOwner = session.RepositoryOwner, Number = pullRequest.Number };
var viewWithData = new ViewWithData(UIControllerFlow.PullRequestDetail) { Data = arg };

var manager = ServiceProvider.TryGetService<IGitHubToolWindowManager>();
var host = manager.ShowHomePane();
host?.ShowView(viewWithData);
}
}
}
11 changes: 9 additions & 2 deletions src/GitHub.VisualStudio/UI/Views/PullRequestDetailView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
using Task = System.Threading.Tasks.Task;
using Microsoft.VisualStudio.TextManager.Interop;
using System.Text;
using System.Globalization;
using Microsoft.VisualStudio.Text.Projection;

namespace GitHub.VisualStudio.UI.Views
Expand Down Expand Up @@ -75,12 +76,18 @@ protected override void OnVisualParentChanged(DependencyObject oldParent)

void DoOpenOnGitHub()
{
var repo = ViewModel.RemoteRepository;
var browser = VisualStudioBrowser;
var url = repo.CloneUrl.ToRepositoryUrl().Append("pull/" + ViewModel.Model.Number);
var cloneUrl = ViewModel.LocalRepository.CloneUrl;
var url = ToPullRequestUrl(cloneUrl.Host, ViewModel.RemoteRepositoryOwner, ViewModel.LocalRepository.Name, ViewModel.Model.Number);
browser.OpenUrl(url);
}

static Uri ToPullRequestUrl(string host, string owner, string repositoryName, int number)
{
var url = string.Format(CultureInfo.InvariantCulture, "https://{0}/{1}/{2}/pull/{3}", host, owner, repositoryName, number);
return new Uri(url);
}

async Task DoOpenFile(IPullRequestFileNode file, bool workingDirectory)
{
try
Expand Down
Loading
0