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

Commit 31ba2de

Browse files
committed
Merge pull request #89 from github/shana/extensions-cleanup
Consolidate extension classes into one place
2 parents 84c79d5 + d736110 commit 31ba2de

File tree

11 files changed

+68
-72
lines changed

11 files changed

+68
-72
lines changed

src/GitHub.App/Extensions/RepositoryModelExtensions.cs

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/GitHub.App/GitHub.App.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@
126126
<Compile Include="Caches\ImageCache.cs" />
127127
<Compile Include="Extensions\AkavacheExtensions.cs" />
128128
<Compile Include="Extensions\EnvironmentExtensions.cs" />
129-
<Compile Include="Extensions\RepositoryModelExtensions.cs" />
130129
<Compile Include="Extensions\ValidationExtensions.cs" />
131130
<Compile Include="GlobalSuppressions.cs" />
132131
<Compile Include="Infrastructure\LoggingConfiguration.cs" />
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using GitHub.Primitives;
2+
using LibGit2Sharp;
3+
using Microsoft.VisualStudio.TeamFoundation.Git.Extensibility;
4+
using System;
5+
using System.Linq;
6+
7+
namespace GitHub.Extensions
8+
{
9+
public static class GitHelpers
10+
{
11+
public static Repository GetRepoFromIGit(this IGitRepositoryInfo repoInfo)
12+
{
13+
var repoPath = Repository.Discover(repoInfo.RepositoryPath);
14+
if (repoPath == null)
15+
return null;
16+
return new Repository(repoPath);
17+
}
18+
19+
public static UriString GetUriFromRepository(this IGitRepositoryInfo repoInfo)
20+
{
21+
return repoInfo.GetRepoFromIGit()?.GetUri();
22+
}
23+
24+
public static UriString GetUri(this Repository repo)
25+
{
26+
return UriString.ToUriString(GetUriFromRepository(repo)?.ToRepositoryUrl());
27+
}
28+
29+
static UriString GetUriFromRepository(Repository repo)
30+
{
31+
return repo
32+
?.Network
33+
.Remotes
34+
.FirstOrDefault(x => x.Name.Equals("origin", StringComparison.Ordinal))
35+
?.Url;
36+
}
37+
38+
public static Repository GetRepoFromPath(string path)
39+
{
40+
var repoPath = Repository.Discover(path);
41+
if (repoPath == null)
42+
return null;
43+
return new Repository(repoPath);
44+
}
45+
}
46+
}

src/GitHub.Exports/Helpers/PropertyNotifierExtensions.cs renamed to src/GitHub.Exports/Extensions/PropertyNotifierExtensions.cs

File renamed without changes.

src/GitHub.Exports/Helpers/SimpleRepositoryModelExtensions.cs renamed to src/GitHub.Exports/Extensions/SimpleRepositoryModelExtensions.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,30 @@
22
using System;
33
using System.Linq;
44
using System.IO;
5+
using Microsoft.VisualStudio.TeamFoundation.Git.Extensibility;
56

67
namespace GitHub.Extensions
78
{
8-
using VisualStudio;
9-
109
public static class SimpleRepositoryModelExtensions
1110
{
11+
/// <summary>
12+
/// Create a SimpleRepositoryModel from a VS git repo object
13+
/// </summary>
14+
public static ISimpleRepositoryModel ToModel(this IGitRepositoryInfo repo)
15+
{
16+
if (repo == null)
17+
return null;
18+
var uri = repo.GetUriFromRepository();
19+
var name = uri?.NameWithOwner;
20+
return name != null ? new SimpleRepositoryModel(name, uri, repo.RepositoryPath) : null;
21+
}
22+
1223
public static bool HasCommits(this ISimpleRepositoryModel repository)
1324
{
14-
var repo = Services.GetRepoFromPath(repository.LocalPath);
25+
var repo = GitHelpers.GetRepoFromPath(repository.LocalPath);
1526
return repo?.Commits.Any() ?? false;
1627
}
28+
1729
public static bool MightContainSolution(this ISimpleRepositoryModel repository)
1830
{
1931
var dir = new DirectoryInfo(repository.LocalPath);
File renamed without changes.

src/GitHub.Exports/GitHub.Exports.csproj

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,10 @@
9999
<None Include="..\..\script\Key.snk" Condition="$(Buildtype) == 'Internal'">
100100
<Link>Key.snk</Link>
101101
</None>
102+
<Compile Include="Extensions\GitHelpers.cs" />
102103
<Compile Include="Helpers\INotifyPropertySource.cs" />
103-
<Compile Include="Helpers\PropertyNotifierExtensions.cs" />
104-
<Compile Include="Helpers\SimpleRepositoryModelExtensions.cs" />
104+
<Compile Include="Extensions\PropertyNotifierExtensions.cs" />
105+
<Compile Include="Extensions\SimpleRepositoryModelExtensions.cs" />
105106
<Compile Include="Info\ApplicationInfo.cs" />
106107
<Compile Include="Models\IAccount.cs" />
107108
<Compile Include="Models\IConnectionManager.cs" />
@@ -122,7 +123,7 @@
122123
</ItemGroup>
123124
<ItemGroup>
124125
<Compile Include="Authentication\AuthenticationResultExtensions.cs" />
125-
<Compile Include="Services\VSExtensions.cs" />
126+
<Compile Include="Extensions\VSExtensions.cs" />
126127
<Compile Include="UI\IView.cs" />
127128
<Compile Include="UI\Octicon.cs" />
128129
<Compile Include="ViewModels\IGitHubConnectSection.cs" />

src/GitHub.Exports/Services/Services.cs

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.Linq;
32
using EnvDTE;
43
using EnvDTE80;
54
using GitHub.Services;
@@ -8,9 +7,9 @@
87
using Microsoft.VisualStudio.ComponentModelHost;
98
using Microsoft.VisualStudio.Shell;
109
using Microsoft.VisualStudio.Shell.Interop;
11-
using Microsoft.VisualStudio.TeamFoundation.Git.Extensibility;
1210
using GitHub.Info;
1311
using GitHub.Primitives;
12+
using GitHub.Extensions;
1413

1514
namespace GitHub.VisualStudio
1615
{
@@ -142,40 +141,5 @@ public static Repository GetRepoFromSolution(this IVsSolution solution)
142141
return null;
143142
return new Repository(repoPath);
144143
}
145-
146-
public static UriString GetUri(this Repository repo)
147-
{
148-
return UriString.ToUriString(GetUriFromRepository(repo)?.ToRepositoryUrl());
149-
}
150-
151-
static UriString GetUriFromRepository(Repository repo)
152-
{
153-
return repo
154-
?.Network
155-
.Remotes
156-
.FirstOrDefault(x => x.Name.Equals("origin", StringComparison.Ordinal))
157-
?.Url;
158-
}
159-
160-
public static Repository GetRepoFromIGit(this IGitRepositoryInfo repoInfo)
161-
{
162-
var repoPath = Repository.Discover(repoInfo.RepositoryPath);
163-
if (repoPath == null)
164-
return null;
165-
return new Repository(repoPath);
166-
}
167-
168-
public static Repository GetRepoFromPath(string path)
169-
{
170-
var repoPath = Repository.Discover(path);
171-
if (repoPath == null)
172-
return null;
173-
return new Repository(repoPath);
174-
}
175-
176-
public static UriString GetUriFromRepository(this IGitRepositoryInfo repoInfo)
177-
{
178-
return repoInfo.GetRepoFromIGit()?.GetUri();
179-
}
180144
}
181145
}

src/GitHub.Exports/Services/VSServices.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ static IEnumerable<ISimpleRepositoryModel> PokeTheRegistryForRepositoryList()
120120
var path = subkey?.GetValue("Path") as string;
121121
if (path != null)
122122
{
123-
var uri = VisualStudio.Services.GetRepoFromPath(path)?.GetUri();
123+
var uri = GitHelpers.GetRepoFromPath(path)?.GetUri();
124124
var name = uri?.NameWithOwner;
125125
if (name != null)
126126
return new SimpleRepositoryModel(name, uri, path);

src/GitHub.Extensions/GitRepoExtensions.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
using Microsoft.VisualStudio.TeamFoundation.Git.Extensibility;
22
using NullGuard;
33
using System;
4-
using System.Collections.Generic;
5-
using System.Linq;
6-
using System.Text;
7-
using System.Threading.Tasks;
84

95
namespace GitHub.Extensions
106
{

0 commit comments

Comments
 (0)