8000 Master PR for refactoring connections by grokys · Pull Request #1277 · 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.

Master PR for refactoring connections #1277

Merged
merged 43 commits into from
Nov 21, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
b790d96
ILoginCache -> IKeychain
grokys Aug 25, 2017
1c81104
Use IKeychain for credentials.
grokys Aug 25, 2017
21f888e
Updated parameter name.
grokys Aug 25, 2017
7e061d1
Removed unneeded usings.
grokys Aug 25, 2017
c8b8dd7
Updated variable names.
grokys Aug 25, 2017
95f2c0b
Remove `IObservableKeychainAdapter`.
grokys Aug 25, 2017
7b4080f
Merge branch 'master' into fixes/1176-duplicate-login-classes
grokys Aug 30, 2017
3b13736
Store "master" credential.
grokys Aug 30, 2017
a142423
Merge branch 'master' into fixes/1176-duplicate-login-classes
grokys Sep 7, 2017
bcfbd79
Fix broken merge.
grokys Sep 7, 2017
c52a261
Merge branch 'fixes/1176-duplicate-login-classes' into fixes/harden-c…
grokys Sep 7, 2017
e6c5d89
Merge branch 'master' into fixes/1176-duplicate-login-classes
grokys Oct 20, 2017
17c845e
Merge branch 'fixes/1176-duplicate-login-classes' into fixes/harden-c…
grokys Oct 20, 2017
a627271
Merge branch 'master' into refactor/connections-master
grokys Oct 20, 2017
470ea13
Removed `IConnection.Repositories`.
grokys Oct 20, 2017
d98ec51
Refactored ConnectionManager/Connection.
grokys Oct 23, 2017
aa78f03
Refactored RepositoryHost(s).
grokys Oct 23, 2017
7cf89c9
Added DebuggerDisplay back in.
grokys Oct 23, 2017
213a7fc
Moved LocalRepositories to GitHub.VisualStudio.
grokys Oct 24, 2017
90c35c5
Track login metrics.
grokys Oct 26, 2017
9db05a7
Fix failing tests.
grokys Oct 26, 2017
f854b79
WIP: Removing RepositoryHost(s)
grokys Oct 26, 2017
3240372
WIP: Still removing RepositoryHost(s)
grokys Oct 26, 2017
038f232
WIP: Removing RepositoryHost(s) from tests.
grokys Oct 26, 2017
a57a759
Finished migrating tests (I think).
grokys Oct 27, 2017
95cd0b1
Added IModelServiceFactory implemenation.
grokys Oct 27, 2017
6034643
Added IGlobalConnection.
grokys Oct 27, 2017
17aebf8
Removed ConnectionManager.ConnectionCreated.
grokys Oct 27, 2017
00232f0
Merge branch 'master' into refactor/connections-master
grokys Nov 3, 2017
01aad33
Merge branch 'refactor/connections-master' into refactor/connections/…
grokys Nov 3, 2017
217e415
Merge branch 'refactor/connections/local-repositories' into refactor/…
grokys Nov 3, 2017
7e57621
Insert AccountCacheItem for connection.
grokys Nov 7, 2017
e45d0c6
Merge branch 'master' into refactor/connections-master
grokys Nov 7, 2017
8f6d218
Merge branch 'refactor/connections-master' into refactor/connections/…
grokys Nov 7, 2017
32f073a
Merge branch 'refactor/connections/local-repositories' into refactor/…
grokys Nov 7, 2017
9f15db6
Merge branch 'refactor/connection-manager' into refactor/connections/…
grokys Nov 7, 2017
cd546bb
Fix CA errors.
grokys Nov 7, 2017
def6070
Merge pull request #1283 from github/refactor/connections/remove-repo…
grokys Nov 8, 2017
fc57163
Merge branch 'master' into refactor/connections-master
grokys Nov 8, 2017
d9c2a2f
Removed empty file.
grokys Nov 8, 2017
cefd4b9
Merge branch 'master' into refactor/connections-master
grokys Nov 14, 2017
7d7b188
Merge branch 'master' into refactor/connections-master
grokys Nov 20, 2017
4701dd0
Merge branch 'master' into refactor/connections-master
grokys Nov 20, 2017
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
Prev Previous commit
Next Next commit
Merge branch 'master' into refactor/connections-master
 Conflicts:
	src/GitHub.App/ViewModels/PullRequestCreationViewModel.cs
	test/UnitTests/GitHub.App/Caches/CredentialCacheTests.cs
	test/UnitTests/GitHub.App/Models/RepositoryHostTests.cs
	test/UnitTests/GitHub.App/ViewModels/PullRequestCreationViewModelTests.cs
	test/UnitTests/Helpers/TestLoginCache.cs
  • Loading branch information
grokys committed Nov 8, 2017
commit fc57163dd853b9dbbada03afbf50460460674536
4 changes: 2 additions & 2 deletions GitHubVS.sln
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Meta", "Meta", "{72036B62-2
README.md = README.md
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTests", "src\UnitTests\UnitTests.csproj", "{596595A6-2A3C-469E-9386-9E3767D863A5}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTests", "test\UnitTests\UnitTests.csproj", "{596595A6-2A3C-469E-9386-9E3767D863A5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitHub.UI", "src\GitHub.UI\GitHub.UI.csproj", "{346384DD-2445-4A28-AF22-B45F3957BD89}"
EndProject
Expand Down Expand Up @@ -88,7 +88,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Splat-Portable", "submodule
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CredentialManagement", "src\CredentialManagement\CredentialManagement.csproj", "{41A47C5B-C606-45B4-B83C-22B9239E4DA0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TrackingCollectionTests", "src\TrackingCollectionTests\TrackingCollectionTests.csproj", "{7B835A7D-CF94-45E8-B191-96F5A4FE26A8}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TrackingCollectionTests", "test\TrackingCollectionTests\TrackingCollectionTests.csproj", "{7B835A7D-CF94-45E8-B191-96F5A4FE26A8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitHub.TeamFoundation.14", "src\GitHub.TeamFoundation.14\GitHub.TeamFoundation.14.csproj", "{161DBF01-1DBF-4B00-8551-C5C00F26720D}"
EndProject
Expand Down
4 changes: 2 additions & 2 deletions install.cmd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Configuration=%1
@set path=%cd%\tools\VsixUtil;%path%
@set Configuration=%1
@if "%Configuration%" == "" echo Please specify Debug or Release
tools\VsixUtil\vsixutil /install "build\%Configuration%\GitHub.VisualStudio.vsix"
@echo Installed %Configuration% build of GitHub for Visual Studio
4 changes: 2 additions & 2 deletions scripts/test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ $env:PATH = "$$PSScriptRoot;$env:PATH"
$exitcode = 0

Write-Output "Running Tracking Collection Tests..."
Run-NUnit src TrackingCollectionTests $TimeoutDuration $config -AppVeyor:$AppVeyor
Run-NUnit test TrackingCollectionTests $TimeoutDuration $config -AppVeyor:$AppVeyor
if (!$?) {
$exitcode = 1
}
Expand All @@ -47,7 +47,7 @@ if (!$?) {
}

Write-Output "Running UnitTests..."
Run-XUnit src UnitTests $TimeoutDuration $config -AppVeyor:$AppVeyor
Run-XUnit test UnitTests $TimeoutDuration $config -AppVeyor:$AppVeyor
if (!$?) {
$exitcode = 3
}
Expand Down
36 changes: 35 additions & 1 deletion src/GitHub.App/Services/GitClient.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using GitHub.Extensions;
using GitHub.Models;
using GitHub.Primitives;
using LibGit2Sharp;
using GitHub.Logging;
Expand Down Expand Up @@ -38,7 +40,6 @@ public GitClient(IGitHubCredentialProvider credentialProvider)
public Task Pull(IRepository repository)
{
Guard.ArgumentNotNull(repository, nameof(repository));

return Task.Factory.StartNew(() =>
{
var signature = repository.Config.BuildSignature(DateTimeOffset.UtcNow);
Expand Down Expand Up @@ -474,6 +475,39 @@ public Task<bool> IsHeadPushed(IRepository repo)
});
}

public Task<IReadOnlyList<CommitMessage>> GetMessagesForUniqueCommits(
IRepository repo,
string baseBranch,
string compareBranch,
int maxCommits)
{
return Task.Factory.StartNew(() =>
{
var baseCommit = repo.Lookup<Commit>(baseBranch);
var compareCommit = repo.Lookup<Commit>(compareBranch);
if (baseCommit == null || compareCommit == null)
{
var missingBranch = baseCommit == null ? baseBranch : compareBranch;
throw new NotFoundException(missingBranch);
}

var mergeCommit = repo.ObjectDatabase.FindMergeBase(baseCommit, compareCommit);
var commitFilter = new CommitFilter
{
IncludeReachableFrom = baseCommit,
ExcludeReachableFrom = mergeCommit,
};

var commits = repo.Commits
.QueryBy(commitFilter)
.Take(maxCommits)
.Select(c => new CommitMessage(c.Message))
.ToList();

return (IReadOnlyList<CommitMessage>)commits;
});
}

static bool IsCanonical(string s)
{
Guard.ArgumentNotEmptyString(s, nameof(s));
Expand Down
13 changes: 13 additions & 0 deletions src/GitHub.App/Services/PullRequestService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,19 @@ public IObservable<string> GetPullRequestTemplate(ILocalRepositoryModel reposito
});
}

public IObservable<IReadOnlyList<CommitMessage>> GetMessagesForUniqueCommits(
ILocalRepositoryModel repository,
string baseBranch,
string compareBranch,
int maxCommits)
{
return Observable.Defer(() =>
{
var repo = gitService.GetRepository(repository.LocalPath);
return gitClient.GetMessagesForUniqueCommits(repo, baseBranch, compareBranch, maxCommits).ToObservable();
});
}

public IObservable<bool> IsWorkingDirectoryClean(ILocalRepositoryModel repository)
{
var repo = gitService.GetRepository(repository.LocalPath);
Expand Down
58 changes: 56 additions & 2 deletions src/GitHub.App/ViewModels/PullRequestCreationViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@ public PullRequestCreationViewModel(
});

SourceBranch = activeRepo.CurrentBranch;
service.GetPullRequestTemplate(activeRepo)
.Subscribe(x => Description = x ?? String.Empty, () => Description = Description ?? String.Empty);

this.WhenAnyValue(x => x.Branches)
.WhereNotNull()
Expand All @@ -93,6 +91,31 @@ public PullRequestCreationViewModel(

SetupValidators();

var uniqueCommits = this.WhenAnyValue(
x => x.SourceBranch,
x => x.TargetBranch)
.Where(x => x.Item1 != null && x.Item2 != null)
.Select(branches =>
{
var baseBranch = branches.Item1.Name;
var compareBranch = branches.Item2.Name;

// We only need to get max two commits for what we're trying to achieve here.
// If there's no commits we want to block creation of the PR, if there's one commits
// we wan't to use its commit message as the PR title/body and finally if there's more
// than one we'll use the branch name for the title.
return service.GetMessagesForUniqueCommits(activeRepo, baseBranch, compareBranch, maxCommits: 2)
.Catch<IReadOnlyList<CommitMessage>, Exception>(ex =>
{
log.Warning(ex, "Could not load unique commits");
return Observable.Empty<IReadOnlyList<CommitMessage>>();
});
})
.Switch()
.ObserveOn(RxApp.MainThreadScheduler)
.Replay(1)
.RefCount();

var whenAnyValidationResultChanges = this.WhenAny(
x => x.TitleValidator.ValidationResult,
x => x.BranchValidator.ValidationResult,
Expand Down Expand Up @@ -128,6 +151,37 @@ public PullRequestCreationViewModel(
this.WhenAnyValue(x => x.Initialized, x => x.GitHubRepository, x => x.Description, x => x.IsExecuting)
.Select(x => !(x.Item1 && x.Item2 != null && x.Item3 != null && !x.Item4))
.Subscribe(x => IsBusy = x);

Observable.CombineLatest(
this.WhenAnyValue(x => x.SourceBranch),
uniqueCommits,
service.GetPullRequestTemplate(activeRepo).DefaultIfEmpty(string.Empty),
(compare, commits, template) => new { compare, commits, template })
.Subscribe(x =>
{
var prTitle = string.Empty;
var prDescription = string.Empty;

if (x.commits.Count == 1)
{
prTitle = x.commits[0].Summary;
prDescription = x.commits[0].Details;
}
else
{
prTitle = x.compare.Name.Humanize();
}

if (!string.IsNullOrWhiteSpace(x.template))
{
if (!string.IsNullOrEmpty(prDescription))
prDescription += "\n\n";
prDescription += x.template;
}

PRTitle = prTitle;
Description = prDescription;
});
}

public override void Initialize(ViewWithData data = null)
Expand Down
18 changes: 18 additions & 0 deletions src/GitHub.Exports.Reactive/Services/IGitClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using System.Threading.Tasks;
using LibGit2Sharp;
using GitHub.Primitives;
using System.Collections.Generic;
using GitHub.Models;

namespace GitHub.Services
{
Expand Down Expand Up @@ -204,5 +206,21 @@ public interface IGitClient
/// <param name="repository">The repository.</param>
/// <returns></returns>
Task<bool> IsHeadPushed(IRepository repo);

/// <summary>
/// Gets the unique commits from <paramref name="compareBranch"/> to the merge base of
/// <paramref name="baseBranch"/> and <paramref name="compareBranch"/> and returns their
/// commit messages.
/// </summary>
/// <param name="repository">The repository.</param>
/// <param name="baseBranch">The base branch to find a merge base with.</param>
/// <param name="compareBranch">The compare branch to find a merge base with.</param>
/// <param name="maxCommits">The maximum number of commits to return.</param>
/// <returns>An enumerable of unique commits from the merge base to the compareBranch.</returns>
Task<IReadOnlyList<CommitMessage>> GetMessagesForUniqueCommits(
IRepository repo,
string baseBranch,
string compareBranch,
int maxCommits);
}
}
18 changes: 18 additions & 0 deletions src/GitHub.Exports.Reactive/Services/IPullRequestService.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using System.Reactive;
using System.Text;
using System.Threading.Tasks;
using GitHub.Models;
using LibGit2Sharp;
using Octokit;
Expand Down Expand Up @@ -157,5 +159,21 @@ IObservable<string> ExtractFile(
IObservable<Unit> RemoveUnusedRemotes(ILocalRepositoryModel repository);

IObservable<string> GetPullRequestTemplate(ILocalRepositoryModel repository);

/// <summary>
/// Gets the unique commits from <paramref name="compareBranch"/> to the merge base of
/// <paramref name="baseBranch"/> and <paramref name="compareBranch"/> and returns their
/// commit messages.
/// </summary>
/// <param name="repository">The repository.</param>
/// <param name="baseBranch">The base branch to find a merge base with.</param>
/// <param name="compareBranch">The compare branch to find a merge base with.</param>
/// <param name="maxCommits">The maximum number of commits to return.</param>
/// <returns>An enumerable of unique commits from the merge base to the compareBranch.</returns>
IObservable<IReadOnlyList<CommitMessage>> GetMessagesForUniqueCommits(
ILocalRepositoryModel repository,
string baseBranch,
string compareBranch,
int maxCommits);
}
}
1 change: 1 addition & 0 deletions src/GitHub.Exports/GitHub.Exports.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@
<ItemGroup>
<Compile Include="Exports\ExportForProcess.cs" />
<Compile Include="GitHubLogicException.cs" />
<Compile Include="Models\CommitMessage.cs" />
<Compile Include="Models\DiffChangeType.cs" />
<Compile Include="Models\DiffChunk.cs" />
<Compile Include="Models\DiffLine.cs" />
Expand Down
56 changes: 56 additions & 0 deletions src/GitHub.Exports/Models/CommitMessage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using System;
using System.Linq;

namespace GitHub.Models
{
public class CommitMessage : IEquatable<CommitMessage>
{
public string Summary { get; private set; }
public string Details { get; private set; }
public string FullMessage { get; private set; }

/// <summary>
/// This is for mocking porpoises.
/// http://cl.ly/image/0q2A2W0U3O2t
/// </summary>
public CommitMessage() { }

public CommitMessage(string fullMessage)
{
if (string.IsNullOrEmpty(fullMessage)) return;

var lines = fullMessage.Replace("\r\n", "\n").Split('\n');
Summary = lines.FirstOrDefault();

FullMessage = fullMessage;
var detailsLines = lines
.Skip(1)
.SkipWhile(string.IsNullOrEmpty)
.ToList();
Details = detailsLines.Any(x => !string.IsNullOrWhiteSpace(x))
? string.Join(Environment.NewLine, detailsLines).Trim()
: null;
}

public bool Equals(CommitMessage other)
{
if (ReferenceEquals(other, null))
{
return false;
}

return string.Equals(Summary, other.Summary)
&& string.Equals(Details, other.Details);
}

public override bool Equals(object obj)
{
return Equals(obj as CommitMessage);
}

public override int GetHashCode()
{
return Tuple.Create(Summary, Details).GetHashCode();
}
}
}
26 changes: 26 additions & 0 deletions src/GitHub.Extensions/StringExtensions.cs
FDAA
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace GitHub.Extensions
{
Expand Down Expand Up @@ -196,5 +198,29 @@ public static Uri ToUriSafe(this string url)
Uri.TryCreate(url, UriKind.Absolute, out uri);
return uri;
}

/// <summary>
/// Returns an alphanumeric sentence cased string with dashes and underscores as spaces.
/// </summary>
/// <param name="s">The string to format.</param>
[SuppressMessage("Microsoft.Globalization", "CA1308:NormalizeStringsToUppercase")]
public static string Humanize(this string s)
{
if (String.IsNullOrWhiteSpace(s))
{
return s;
}

var matches = Regex.Matches(s, @"[a-zA-Z\d]{1,}", RegexOptions.None);

if (matches.Count == 0)
{
return s;
}

var result = matches.Cast<Match>().Select(match => match.Value.ToLower(CultureInfo.InvariantCulture));
var combined = String.Join(" ", result);
return Char.ToUpper(combined[0], CultureInfo.InvariantCulture) + combined.Substring(1);
}
}
}
5 changes: 1 addition & 4 deletions src/GitHub.InlineReviews/Tags/InlineCommentTagger.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reactive.Linq;
using System.Threading.Tasks;
using GitHub.Extensions;
using GitHub.InlineReviews.Services;
using GitHub.Logging;
using GitHub.Models;
using GitHub.Services;
using GitHub.VisualStudio;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.Text.Tagging;
Expand Down Expand Up @@ -50,7 +47,7 @@ public InlineCommentTagger(
this.sessionManager = sessionManager;
}

public bool ShowMargin => file != null;
public bool ShowMargin => file?.Diff?.Count > 0;

public event EventHandler<SnapshotSpanEventArgs> TagsChanged;

Expand Down
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.
0