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

Commit 1fd917d

Browse files
Merge branch 'master' into fixes/pull-request-is-from-repository
2 parents 5235620 + cbec5e3 commit 1fd917d

File tree

40 files changed

+576
-157
lines changed

40 files changed

+576
-157
lines changed

CONTRIBUTING.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@ This project adheres to the [Open Code of Conduct][code-of-conduct]. By particip
1313

1414
## Submitting a pull request
1515

16-
0. [Fork][] and clone the repository (see Build Instructions in the [README][readme])
17-
0. Create a new branch: `git checkout -b my-branch-name`
18-
0. Make your change, add tests, and make sure the tests still pass
19-
0. Push to your fork and [submit a pull request][pr]
20-
0. Pat your self on the back and wait for your pull request to be reviewed and merged.
16+
1. [Fork][] and clone the repository (see Build Instructions in the [README][readme])
17+
2. Create a new branch: `git checkout -b my-branch-name`
18+
3. Make your change, add tests, and make sure the tests still pass
19+
4. Push to your fork and [submit a pull request][pr]
20+
5. Pat your self on the back and wait for your pull request to be reviewed and merged.
2121

2222
Here are a few things you can do that will increase the likelihood of your pull request being accepted:
2323

24-
- Follow the existing code's style.
25-
- Write tests.
24+
- Follow the style/format of the existing code.
25+
- Write tests for your changes.
2626
- Keep your change as focused as possible. If there are multiple changes you would like to make that are not dependent upon each other, consider submitting them as separate pull requests.
2727
- Write a [good commit message](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html).
2828

@@ -38,7 +38,7 @@ There are certain areas of the extension that are restricted in what they can do
3838
### Bug Reporting
3939

4040
Here are a few helpful tips when reporting a bug:
41-
- Verify the bug resides in the GitHub for Visual Studio extension
41+
- Verify that the bug resides in the GitHub for Visual Studio extension
4242
- A lot of functionality provided by this extension resides in the Team Explorer pane, alongside other non-GitHub tools to manage and collaborate on source code, including Visual Studio's Git support, which is owned by Microsoft.
4343
- If this bug not is related to the GitHub extension, visit the [Visual Studio support page](https://www.visualstudio.com/support/support-overview-vs) for help
4444
- Screenshots are very helpful in diagnosing bugs and understanding the state of the extension when it's experiencing problems. Please include them whenever possible.

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
os: Visual Studio 2017
2-
version: '2.5.4.{build}'
2+
version: '2.5.5.{build}'
33
skip_tags: true
44
install:
55
- ps: |

src/GitHub.App/Services/GitHubContextService.cs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ public class GitHubContextService : IGitHubContextService
5858
static readonly Regex treeishCommitRegex = new Regex($"(?<commit>[a-z0-9]{{40}})(/(?<tree>.+))?", RegexOptions.Compiled);
5959
static readonly Regex treeishBranchRegex = new Regex($"(?<branch>master)(/(?<tree>.+))?", RegexOptions.Compiled);
6060

61+
static readonly Regex tempFileObjectishRegex = new Regex(@"\\TFSTemp\\[^\\]*[.](?<objectish>[a-z0-9]{8})[.][^.\\]*$", RegexOptions.Compiled);
62+
6163
[ImportingConstructor]
6264
public GitHubContextService(IGitHubServiceProvider serviceProvider, IGitService gitService)
6365
{
@@ -305,6 +307,55 @@ public bool TryOpenFile(string repositoryDir, GitHubContext context)
305307
}
306308
}
307309

310+
/// <inheritdoc/>
311+
public string FindObjectishForTFSTempFile(string tempFile)
312+
{
313+
var match = tempFileObjectishRegex.Match(tempFile);
314+
if (match.Success)
315+
{
316+
return match.Groups["objectish"].Value;
317+
}
318+
319+
return null;
320+
}
321+
322+
/// <inheritdoc/>
323+
public (string commitSha, string blobPath) ResolveBlobFromHistory(string repositoryDir, string objectish)
324+
{
325+
using (var repo = gitService.GetRepository(repositoryDir))
326+
{
327+
var blob = repo.Lookup<Blob>(objectish);
328+
if (blob == null)
329+
{
330+
return (null, null);
331+
}
332+
333+
foreach (var commit in repo.Commits)
334+
{
335+
var trees = new Stack<Tree>();
336+
trees.Push(commit.Tree);
337+
338+
while (trees.Count > 0)
339+
{
340+
foreach (var treeEntry in trees.Pop())
341+
{
342+
if (treeEntry.Target == blob)
343+
{
344+
return (commit.Sha, treeEntry.Path);
345+
}
346+
347+
if (treeEntry.TargetType == TreeEntryTargetType.Tree)
348+
{
349+
trees.Push((Tree)treeEntry.Target);
350+
}
351+
}
352+
}
353+
}
354+
355+
return (null, null);
356+
}
357+
}
358+
308359
/// <inheritdoc/>
309360
public bool HasChangesInWorkingDirectory(string repositoryDir, string commitish, string path)
310361
{

src/GitHub.App/ViewModels/Dialog/LoginToGitHubForEnterpriseViewModel.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public LoginToGitHubForEnterpriseViewModel(
6565
this.WhenAnyValue(x => x.EnterpriseUrl, x => x.EnterpriseUrlValidator.ValidationResult)
6666
.Throttle(TimeSpan.FromMilliseconds(500), scheduler)
6767
.ObserveOn(RxApp.MainThreadScheduler)
68-
.Subscribe(x => EnterpriseUrlChanged(x.Item1, x.Item2?.IsValid ?? false));
68+
.Subscribe(x => UpdatingProbeStatus = EnterpriseUrlChanged(x.Item1, x.Item2?.IsValid ?? false));
6969

7070
NavigateLearnMore = ReactiveCommand.CreateAsyncObservable(_ =>
7171
{
@@ -122,13 +122,19 @@ public IReactiveCommand<Unit> NavigateLearnMore
122122
get;
123123
}
124124

125+
public Task UpdatingProbeStatus
126+
{
127+
get;
128+
private set;
129+
}
130+
125131
protected override async Task ResetValidation()
126132
{
127133
EnterpriseUrl = null;
128134
await EnterpriseUrlValidator.ResetAsync();
129135
}
130136

131-
async void EnterpriseUrlChanged(string url, bool valid)
137+
async Task EnterpriseUrlChanged(string url, bool valid)
132138
{
133139
if (!valid)
134140
{

src/GitHub.App/ViewModels/GitHubPane/IssueListViewModelBase.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,10 +246,7 @@ void FilterChanged()
246246
{
247247
numberFilter = 0;
248248

249-
if (SearchQuery.StartsWith('#'))
250-
{
251-
int.TryParse(SearchQuery.Substring(1), out numberFilter);
252-
}
249+
int.TryParse(SearchQuery.Substring(SearchQuery.StartsWith('#') ? 1 : 0), out numberFilter);
253250

254251
if (numberFilter == 0)
255252
{

src/GitHub.App/ViewModels/GitHubPane/PullRequestReviewSummaryViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public static IEnumerable<PullRequestReviewSummaryViewModel> BuildByUser(
4141
{
4242
var existing = new Dictionary<string, PullRequestReviewSummaryViewModel>();
4343

44-
foreach (var review in pullRequest.Reviews.OrderBy(x => x.Id))
44+
foreach (var review in pullRequest.Reviews.OrderBy(x => x.SubmittedAt))
4545
{
4646
if (review.State == PullRequestReviewState.Pending && review.Author.Login != currentUser.Login)
4747
continue;

src/GitHub.Exports/Services/IGitHubContextService.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,30 @@ public interface IGitHubContextService
7171
/// <returns>The resolved commit-ish, blob path and commit SHA for the blob. Path will be null if the commit-ish can be resolved but not the blob.</returns>
7272
(string commitish, string path, string commitSha) ResolveBlob(string repositoryDir, GitHubContext context, string remoteName = "origin");
7373

74+
/// <summary>
75+
/// Find the object-ish (first 8 chars of a blob SHA) from the path to historical blob created by Team Explorer.
76+
/// </summary>
77+
/// <remarks>
78+
/// Team Explorer creates temporary blob files in the following format:
79+
/// C:\Users\me\AppData\Local\Temp\TFSTemp\vctmp21996_181282.IOpenFromClipboardCommand.783ac965.cs
80+
/// The object-ish appears immediately before the file extension and the path contains the folder "TFSTemp".
81+
/// <remarks>
82+
/// <param name="tempFile">The path to a possible Team Explorer temporary blob file.</param>
83+
/// <returns>The target file's object-ish (blob SHA fragment) or null if the path isn't recognized as a Team Explorer blob file.</returns>
84+
string FindObjectishForTFSTempFile(string tempFile);
85+
86+
/// <summary>
87+
/// Find a tree entry in the commit log where a blob appears and return its commit SHA and path.
88+
/// </summary>
89+
/// <remarks>
90+
/// Search back through the commit log for the first tree entry where a blob appears. This operation only takes
91+
/// a fraction of a seond on the `github/VisualStudio` repository even if a tree entry casn't be found.
92+
/// </remarks>
93+
/// <param name="repositoryDir">The target repository directory.</param>
94+
/// <param name="objectish">The fragment of a blob SHA to find.</param>
95+
/// <returns>The commit SHA and blob path or null if the blob can't be found.</returns>
96+
(string commitSha, string blobPath) ResolveBlobFromHistory(string repositoryDir, string objectish);
97+
7498
/// <summary>
7599
/// Check if a file in the working directory has changed since a specified commit-ish.
76100
/// </summary>

src/GitHub.InlineReviews/GitHub.InlineReviews.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@
8484
<Compile Include="Margins\InlineCommentMargin.cs" />
8585
<Compile Include="Margins\InlineCommentMarginVisible.cs" />
8686
<Compile Include="Margins\InlineCommentMarginEnabled.cs" />
87+
<Compile Include="Services\CommentService.cs" />
88+
<Compile Include="Services\ICommentService.cs" />
8789
<Compile Include="PullRequestStatusBarPackage.cs" />
8890
<Compile Include="InlineReviewsPackage.cs" />
8991
<Compile Include="Models\InlineCommentThreadModel.cs" />
Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
using System;
22
using System.ComponentModel.Composition;
3+
using Microsoft.VisualStudio.Shell;
34
using Microsoft.VisualStudio.Utilities;
45
using Microsoft.VisualStudio.Text.Editor;
56
using Microsoft.VisualStudio.Text.Tagging;
67
using Microsoft.VisualStudio.Text.Classification;
7-
using GitHub.InlineReviews.Services;
88
using GitHub.Services;
9+
using GitHub.VisualStudio;
10+
using GitHub.InlineReviews.Services;
911

1012
namespace GitHub.InlineReviews.Margins
1113
{
@@ -17,28 +19,41 @@ namespace GitHub.InlineReviews.Margins
1719
[TextViewRole(PredefinedTextViewRoles.Interactive)]
1820
internal sealed class InlineCommentMarginProvider : IWpfTextViewMarginProvider
1921
{
20-
readonly IEditorFormatMapService editorFormatMapService;
21-
readonly IViewTagAggregatorFactoryService tagAggregatorFactory;
22-
readonly IInlineCommentPeekService peekService;
22+
readonly Lazy<IEditorFormatMapService> editorFormatMapService;
23+
readonly Lazy<IViewTagAggregatorFactoryService> tagAggregatorFactory;
24+
readonly Lazy<IInlineCommentPeekService> peekService;
2325
readonly Lazy<IPullRequestSessionManager> sessionManager;
26+
readonly UIContext uiContext;
2427

2528
[ImportingConstructor]
2629
public InlineCommentMarginProvider(
27-
IGitHubServiceProvider serviceProvider,
28-
IEditorFormatMapService editorFormatMapService,
29-
IViewTagAggregatorFactoryService tagAggregatorFactory,
30-
IInlineCommentPeekService peekService)
30+
Lazy<IPullRequestSessionManager> sessionManager,
31+
Lazy<IEditorFormatMapService> editorFormatMapService,
32+
Lazy<IViewTagAggregatorFactoryService> tagAggregatorFactory,
33+
Lazy<IInlineCommentPeekService> peekService)
3134
{
35+
this.sessionManager = sessionManager;
3236
this.editorFormatMapService = editorFormatMapService;
3337
this.tagAggregatorFactory = tagAggregatorFactory;
3438
this.peekService = peekService;
35-
sessionManager = new Lazy<IPullRequestSessionManager>(() => serviceProvider.GetService<IPullRequestSessionManager>());
39+
40+
uiContext = UIContext.FromUIContextGuid(new Guid(Guids.UIContext_Git));
3641
}
3742

3843
public IWpfTextViewMargin CreateMargin(IWpfTextViewHost wpfTextViewHost, IWpfTextViewMargin parent)
3944
{
45+
if (!uiContext.IsActive)
46+
{
47+
// Only create margin when in the context of a Git repository
48+
return null;
49+
}
50+
4051
return new InlineCommentMargin(
41-
wpfTextViewHost, peekService, editorFormatMapService, tagAggregatorFactory, sessionManager);
52+
wpfTextViewHost,
53+
peekService.Value,
54+
editorFormatMapService.Value,
55+
tagAggregatorFactory.Value,
56+
sessionManager);
4257
}
4358
}
4459
}

src/GitHub.InlineReviews/Margins/PullRequestFileMarginProvider.cs

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
using GitHub.Commands;
44
using GitHub.Services;
55
using GitHub.Settings;
6+
using GitHub.VisualStudio;
7+
using Microsoft.VisualStudio.Shell;
68
using Microsoft.VisualStudio.Utilities;
79
using Microsoft.VisualStudio.Text.Editor;
810

@@ -19,25 +21,28 @@ namespace GitHub.InlineReviews.Margins
1921
[TextViewRole(PredefinedTextViewRoles.Editable)]
2022
internal sealed class PullRequestFileMarginProvider : IWpfTextViewMarginProvider
2123
{
22-
readonly IPullRequestSessionManager sessionManager;
23-
readonly IToggleInlineCommentMarginCommand enableInlineCommentsCommand;
24-
readonly IGoToSolutionOrPullRequestFileCommand goToSolutionOrPullRequestFileCommand;
25-
readonly IPackageSettings packageSettings;
24+
readonly Lazy<IPullRequestSessionManager> sessionManager;
25+
readonly Lazy<IToggleInlineCommentMarginCommand> enableInlineCommentsCommand;
26+
readonly Lazy<IGoToSolutionOrPullRequestFileCommand> goToSolutionOrPullRequestFileCommand;
27+
readonly Lazy<IPackageSettings> packageSettings;
2628
readonly Lazy<IUsageTracker> usageTracker;
29+
readonly UIContext uiContext;
2730

2831
[ImportingConstructor]
2932
public PullRequestFileMarginProvider(
30-
IToggleInlineCommentMarginCommand enableInlineCommentsCommand,
31-
IGoToSolutionOrPullRequestFileCommand goToSolutionOrPullRequestFileCommand,
32-
IPullRequestSessionManager sessionManager,
33-
IPackageSettings packageSettings,
33+
Lazy<IToggleInlineCommentMarginCommand> enableInlineCommentsCommand,
34+
Lazy<IGoToSolutionOrPullRequestFileCommand> goToSolutionOrPullRequestFileCommand,
35+
Lazy<IPullRequestSessionManager> sessionManager,
36+
Lazy<IPackageSettings> packageSettings,
3437
Lazy<IUsageTracker> usageTracker)
3538
{
3639
this.enableInlineCommentsCommand = enableInlineCommentsCommand;
3740
this.goToSolutionOrPullRequestFileCommand = goToSolutionOrPullRequestFileCommand;
3841
this.sessionManager = sessionManager;
3942
this.packageSettings = packageSettings;
4043
this.usageTracker = usageTracker;
44+
45+
uiContext = UIContext.FromUIContextGuid(new Guid(Guids.UIContext_Git));
4146
}
4247

4348
/// <summary>
@@ -50,8 +55,14 @@ public PullRequestFileMarginProvider(
5055
/// </returns>
5156
public IWpfTextViewMargin CreateMargin(IWpfTextViewHost wpfTextViewHost, IWpfTextViewMargin marginContainer)
5257
{
58+
if (!uiContext.IsActive)
59+
{
60+
// Only create margin when in the context of a Git repository
61+
return null;
62+
}
63+
5364
// Comments in the editor feature flag
54-
if (!packageSettings.EditorComments)
65+
if (!packageSettings.Value.EditorComments)
5566
{
5667
return null;
5768
}
@@ -63,7 +74,11 @@ public IWpfTextViewMargin CreateMargin(IWpfTextViewHost wpfTextViewHost, IWpfTex
6374
}
6475

6576
return new PullRequestFileMargin(
66-
wpfTextViewHost.TextView, enableInlineCommentsCommand, goToSolutionOrPullRequestFileCommand, sessionManager, usageTracker);
77+
wpfTextViewHost.TextView,
78+
enableInlineCommentsCommand.Value,
79+
goToSolutionOrPullRequestFileCommand.Value,
80+
sessionManager.Value,
81+
usageTracker);
6782
}
6883

6984
bool IsDiffView(ITextView textView) => textView.Roles.Contains("DIFF");

0 commit comments

Comments
 (0)