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

Commit c2dd90e

Browse files
Merge branch 'master' into remove-fork-experimental-setting
2 parents ca3456c + 865845e commit c2dd90e

27 files changed

+398
-78
lines changed

src/GitHub.App/Services/DialogService.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,31 @@ public class DialogService : IDialogService
1616
{
1717
readonly IViewViewModelFactory factory;
1818
readonly IShowDialogService showDialog;
19+
readonly IGitHubContextService gitHubContextService;
1920

2021
[ImportingConstructor]
2122
public DialogService(
2223
IViewViewModelFactory factory,
23-
IShowDialogService showDialog)
24+
IShowDialogService showDialog,
25+
IGitHubContextService gitHubContextService)
2426
{
2527
Guard.ArgumentNotNull(factory, nameof(factory));
2628
Guard.ArgumentNotNull(showDialog, nameof(showDialog));
29+
Guard.ArgumentNotNull(showDialog, nameof(gitHubContextService));
2730

2831
this.factory = factory;
2932
this.showDialog = showDialog;
33+
this.gitHubContextService = gitHubContextService;
3034
}
3135

3236
public async Task<CloneDialogResult> ShowCloneDialog(IConnection connection, string url = null)
3337
{
38+
if (string.IsNullOrEmpty(url))
39+
{
40+
var clipboardContext = gitHubContextService.FindContextFromClipboard();
41+
url = clipboardContext?.Url;
42+
}
43+
3444
var viewModel = factory.CreateViewModel<IRepositoryCloneViewModel>();
3545
if (url != null)
3646
{

src/GitHub.App/Services/GitHubContextService.cs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Text;
44
using System.Linq;
55
using System.Windows;
6+
using System.Globalization;
67
using System.Threading.Tasks;
78
using System.Collections.Generic;
89
using System.ComponentModel.Composition;
@@ -25,6 +26,7 @@ public class GitHubContextService : IGitHubContextService
2526
{
2627
readonly IGitHubServiceProvider serviceProvider;
2728
readonly IGitService gitService;
29+
readonly IVSServices vsServices;
2830
readonly Lazy<IVsTextManager2> textManager;
2931

3032
// USERID_REGEX = /[a-z0-9][a-z0-9\-\_]*/i
@@ -61,13 +63,38 @@ public class GitHubContextService : IGitHubContextService
6163
static readonly Regex tempFileObjectishRegex = new Regex(@"\\TFSTemp\\[^\\]*[.](?<objectish>[a-z0-9]{8})[.][^.\\]*$", RegexOptions.Compiled);
6264

6365
[ImportingConstructor]
64-
public GitHubContextService(IGitHubServiceProvider serviceProvider, IGitService gitService)
66+
public GitHubContextService(IGitHubServiceProvider serviceProvider, IGitService gitService, IVSServices vsServices)
6567
{
6668
this.serviceProvider = serviceProvider;
6769
this.gitService = gitService;
70+
this.vsServices = vsServices;
6871
textManager = new Lazy<IVsTextManager2>(() => serviceProvider.GetService<SVsTextManager, IVsTextManager2>());
6972
}
7073

74+
/// <inheritdoc/>
75+
public void TryNavigateToContext(string repositoryDir, GitHubContext context)
76+
{
77+
if (context?.LinkType == LinkType.Blob)
78+
{
79+
var (commitish, path, commitSha) = ResolveBlob(repositoryDir, context);
80+
if (commitish == null && path == null)
81+
{
82+
var message = string.Format(CultureInfo.CurrentCulture, Resources.CouldntFindCorrespondingFile, context.Url);
83+
vsServices.ShowMessageBoxInfo(message);
84+
return;
85+
}
86+
87+
var hasChanges = HasChangesInWorkingDirectory(repositoryDir, commitish, path);
88+
if (hasChanges)
89+
{
90+
var message = string.Format(CultureInfo.CurrentCulture, Resources.ChangesInWorkingDirectoryMessage, commitish);
91+
vsServices.ShowMessageBoxInfo(message);
92+
}
93+
94+
TryOpenFile(repositoryDir, context);
95+
}
96+
}
97+
7198
/// <inheritdoc/>
7299
public GitHubContext FindContextFromClipboard()
73100
{

src/GitHub.App/Services/RepositoryCloneService.cs

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ public class RepositoryCloneService : IRepositoryCloneService
3636
readonly IVSGitServices vsGitServices;
3737
readonly ITeamExplorerServices teamExplorerServices;
3838
readonly IGraphQLClientFactory graphqlFactory;
39+
readonly IGitHubContextService gitHubContextService;
3940
readonly IUsageTracker usageTracker;
41+
readonly Lazy<EnvDTE.DTE> dte;
4042
ICompiledQuery<ViewerRepositoriesModel> readViewerRepositories;
4143

4244
[ImportingConstructor]
@@ -45,13 +47,17 @@ public RepositoryCloneService(
4547
IVSGitServices vsGitServices,
4648
ITeamExplorerServices teamExplorerServices,
4749
IGraphQLClientFactory graphqlFactory,
48-
IUsageTracker usageTracker)
50+
IGitHubContextService gitHubContextService,
51+
IUsageTracker usageTracker,
52+
IGitHubServiceProvider sp)
4953
{
5054
this.operatingSystem = operatingSystem;
5155
this.vsGitServices = vsGitServices;
5256
this.teamExplorerServices = teamExplorerServices;
5357
this.graphqlFactory = graphqlFactory;
58+
this.gitHubContextService = gitHubContextService;
5459
this.usageTracker = usageTracker;
60+
dte = new Lazy<EnvDTE.DTE>(() => sp.GetService<EnvDTE.DTE>());
5561

5662
defaultClonePath = GetLocalClonePathFromGitProvider(operatingSystem.Environment.GetUserRepositoriesPath());
5763
}
@@ -125,7 +131,10 @@ public async Task CloneOrOpenRepository(
125131
var isDotCom = HostAddress.IsGitHubDotComUri(repositoryUrl);
126132
if (DestinationDirectoryExists(repositoryPath))
127133
{
128-
teamExplorerServices.OpenRepository(repositoryPath);
134+
if (!IsSolutionInRepository(repositoryPath))
135+
{
136+
teamExplorerServices.OpenRepository(repositoryPath);
137+
}
129138

130139
if (isDotCom)
131140
{
@@ -153,6 +162,36 @@ public async Task CloneOrOpenRepository(
153162

154163
// Give user a chance to choose a solution
155164
teamExplorerServices.ShowHomePage();
165+
166+
// Navigate to context for supported URL types (e.g. /blob/ URLs)
167+
var context = gitHubContextService.FindContextFromUrl(url);
168+
if (context != null)
169+
{
170+
gitHubContextService.TryNavigateToContext(repositoryPath, context);
171+
}
172+
}
173+
174+
bool IsSolutionInRepository(string repositoryPath)
175+
{
176+
var solutionPath = dte.Value.Solution.FileName;
177+
if (string.IsNullOrEmpty(solutionPath))
178+
{
179+
return false;
180+
}
181+
182+
var isFolder = operatingSystem.Directory.DirectoryExists(solutionPath);
183+
var solutionDir = isFolder ? solutionPath : Path.GetDirectoryName(solutionPath);
184+
if (string.Equals(repositoryPath, solutionDir, StringComparison.OrdinalIgnoreCase))
185+
{
186+
return true;
187+
}
188+
189+
if (solutionDir.StartsWith(repositoryPath + '\\', StringComparison.OrdinalIgnoreCase))
190+
{
191+
return true;
192+
}
193+
194+
return false;
156195
}
157196

158197
/// <inheritdoc/>

src/GitHub.App/ViewModels/Dialog/Clone/RepositoryCloneViewModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ public async Task InitializeAsync(IConnection connection)
137137

138138
this.WhenAnyValue(x => x.SelectedTabIndex).Subscribe(x => tabs[x].Activate().Forget());
139139

140-
// Users in group A will see the URL tab by default
141-
if (await IsGroupA().ConfigureAwait(false))
140+
// When a clipboard URL has been set or a user is in group A, show the URL tab by default
141+
if (!string.IsNullOrEmpty(UrlTab.Url) || await IsGroupA().ConfigureAwait(false))
142142
{
143143
SelectedTabIndex = 2;
144144
}

src/GitHub.Exports/Services/IGitHubContextService.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ namespace GitHub.Services
88
/// </summary>
99
public interface IGitHubContextService
1010
{
11+
/// <summary>
12+
/// Attempt to navigate to the equivalent context inside Visual Studio.
13+
/// </summary>
14+
/// <param name="repositoryDir">The target repository</param>
15+
/// <param name="context">The context to open.</param>
16+
void TryNavigateToContext(string repositoryDir, GitHubContext context);
17+
1118
/// <summary>
1219
/// Find the context from a URL in the clipboard if any.
1320
/// </summary>

src/GitHub.InlineReviews/GitHub.InlineReviews.csproj

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,12 @@
9090
<Compile Include="Services\PullRequestSessionManager.cs" />
9191
<Compile Include="Margins\InlineCommentMarginProvider.cs" />
9292
<Compile Include="Services\PullRequestSessionService.cs" />
93+
<Compile Include="Tags\ShowInlineAnnotationGlyph.xaml.cs">
94+
<DependentUpon>ShowInlineAnnotationGlyph.xaml</DependentUpon>
95+
</Compile>
96+
<Compile Include="Tags\ShowInlineCommentAnnotationGlyph.xaml.cs">
97+
<DependentUpon>ShowInlineCommentAnnotationGlyph.xaml</DependentUpon>
98+
</Compile>
9399
<Compile Include="ViewModels\PullRequestFileMarginViewModel.cs" />
94100
<Compile Include="ViewModels\InlineCommentPeekViewModel.cs" />
95101
<Compile Include="ViewModels\PullRequestStatusViewModel.cs" />
@@ -228,6 +234,14 @@
228234
<SubType>Designer</SubType>
229235
<ContainsDesignTimeResources>true</ContainsDesignTimeResources>
230236
</Page>
237+
<Page Include="Tags\ShowInlineAnnotationGlyph.xaml">
238+
<Generator>MSBuild:Compile</Generator>
239+
<SubType>Designer</SubType>
240+
</Page>
241+
<Page Include="Tags\ShowInlineCommentAnnotationGlyph.xaml">
242+
<Generator>MSBuild:Compile</Generator>
243+
<SubType>Designer</SubType>
244+
</Page>
231245
<Page Include="Views\PullRequestFileMarginView.xaml">
232246
<SubType>Designer</SubType>
233247
<Generator>MSBuild:Compile</Generator>

src/GitHub.InlineReviews/Tags/InlineCommentGlyphFactory.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,22 @@ static UserControl CreateGlyph(InlineCommentTag tag)
5959

6060
if (showTag != null)
6161
{
62-
return new ShowInlineCommentGlyph();
62+
if (showTag.Thread != null && showTag.Annotations != null)
63+
{
64+
return new ShowInlineCommentAnnotationGlyph();
65+
}
66+
67+
if (showTag.Thread != null)
68+
{
69+
return new ShowInlineCommentGlyph();
70+
}
71+
72+
if (showTag.Annotations != null)
73+
{
74+
return new ShowInlineAnnotationGlyph();
75+
}
76+
77+
throw new ArgumentException($"{nameof(showTag)} does not have a thread or annotations");
6378
}
6479

6580
throw new ArgumentException($"Unknown 'InlineCommentTag' type '{tag}'");

src/GitHub.InlineReviews/Tags/InlineCommentTagger.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,26 @@ public IEnumerable<ITagSpan<InlineCommentTag>> GetTags(NormalizedSnapshotSpanCol
127127
{
128128
linesWithTags[line - startLine] = true;
129129

130+
CheckAnnotationLevel? summaryAnnotationLevel = null;
131+
if (annotations != null)
132+
{
133+
var hasFailure = annotations.Any(model => model.AnnotationLevel == CheckAnnotationLevel.Failure);
134+
if (hasFailure)
135+
{
136+
summaryAnnotationLevel = CheckAnnotationLevel.Failure;
137+
}
138+
else
139+
{
140+
var hasWarning = annotations.Any(model => model.AnnotationLevel == CheckAnnotationLevel.Warning);
141+
summaryAnnotationLevel = hasWarning ? CheckAnnotationLevel.Warning : CheckAnnotationLevel.Notice;
142+
}
143+
}
144+
130145
var showInlineTag = new ShowInlineCommentTag(currentSession, line, thread?.DiffLineType ?? DiffChangeType.Add)
131146
{
132147
Thread = thread,
133-
Annotations = annotations
148+
Annotations = annotations,
149+
SummaryAnnotationLevel = summaryAnnotationLevel,
134150
};
135151

136152
result.Add(new TagSpan<ShowInlineCommentTag>(
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<UserControl x:Class="GitHub.InlineReviews.Tags.ShowInlineAnnotationGlyph"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:cache="clr-namespace:GitHub.UI.Helpers;assembly=GitHub.UI"
7+
xmlns:models="clr-namespace:GitHub.Models;assembly=GitHub.Exports"
8+
mc:Ignorable="d">
9+
10+
<Grid>
11+
<Border Background="{DynamicResource GitHubGlyphMarginCommentableBackground}" BorderThickness="0,0,1,0" />
12+
<Viewbox HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,1,0,0">
13+
<Canvas Width="16" Height="16">
14+
<Canvas.Resources>
15+
<Style TargetType="Rectangle">
16+
<Setter Property="Fill" Value="{DynamicResource GitHubDiffGlyphFill.None}" />
17+
<Setter Property="Stroke" Value="{DynamicResource GitHubDiffGlyphFill.None}" />
18+
</Style>
19+
</Canvas.Resources>
20+
21+
<Rectangle Width="7"
22+
Height="7"
23+
Canvas.Top="3"
24+
Canvas.Left="2.5"
25+
Stroke="White"
26+
StrokeThickness="1">
27+
<Rectangle.LayoutTransform>
28+
<TransformGroup>
29+
<RotateTransform Angle="-45" />
30+
</TransformGroup>
31+
</Rectangle.LayoutTransform>
32+
<Rectangle.Style>
33+
<Style TargetType="Rectangle">
34+
<Setter Property="Fill" Value="{DynamicResource GitHubAnnotationMarkerInfoFill}"/>
35+
<Style.Triggers>
36+
<DataTrigger Binding="{Binding SummaryAnnotationLevel}"
37+
Value="Failure">
38+
<Setter Property="Fill" Value="{DynamicResource GitHubAnnotationMarkerFailureFill}"/>
39+
</DataTrigger>
40+
<DataTrigger Binding="{Binding SummaryAnnotationLevel}"
41+
Value="Warning">
42+
<Setter Property="Fill" Value="{DynamicResource GitHubAnnotationMarkerWarningFill}"/>
43+
</DataTrigger>
44+
</Style.Triggers>
45+
</Style>
46+
</Rectangle.Style>
47+
</Rectangle>
48+
</Canvas>
49+
</Viewbox>
50+
</Grid>
51+
</UserControl>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
using System.Windows.Controls;
3+
4+
namespace GitHub.InlineReviews.Tags
5+
{
6+
public partial class ShowInlineAnnotationGlyph : UserControl
7+
{
8+
public ShowInlineAnnotationGlyph()
9+
{
10+
InitializeComponent();
11+
}
12+
}
13+
}

0 commit comments

Comments
 (0)