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

Commit 6a3d8e4

Browse files
committed
Remove legacy ResolvePath method
Everything now uses ResolveBlob.
1 parent 7784364 commit 6a3d8e4

File tree

3 files changed

+3
-77
lines changed

3 files changed

+3
-77
lines changed

src/GitHub.App/Services/GitHubContextService.cs

Lines changed: 3 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -237,70 +237,18 @@ public GitHubContext FindContextFromWindowTitle(string windowTitle)
237237

238238
public bool TryOpenFile(string repositoryDir, GitHubContext context)
239239
{
240-
var fileName = context.BlobName;
241-
if (fileName == null)
240+
var (commitish, path) = ResolveBlob(repositoryDir, context);
241+
if (path == null)
242242
{
243243
return false;
244244
}
245245

246-
string fullPath;
247-
var resolvedPath = ResolvePath(context);
248-
if (resolvedPath != null)
249-
{
250-
fullPath = Path.Combine(repositoryDir, resolvedPath);
251-
if (!File.Exists(fullPath))
252-
{
253-
return false;
254-
}
255-
}
256-
else
257-
{
258-
// Search by filename only
259-
fullPath = Directory.EnumerateFiles(repositoryDir, fileName, SearchOption.AllDirectories).FirstOrDefault();
260-
if (fullPath == null)
261-
{
262-
return false;
263-
}
264-
}
265-
246+
var fullPath = Path.Combine(repositoryDir, path.Replace('/', '\\'));
266247
var textView = OpenDocument(fullPath);
267-
268248
SetSelection(textView, context);
269-
270249
return true;
271250
}
272251

273-
public string ResolvePath(GitHubContext context)
274-
{
275-
var treeish = context.TreeishPath;
276-
if (treeish == null)
277-
{
278-
return null;
279-
}
280-
281-
var blobName = context.BlobName;
282-
if (blobName == null)
283-
{
284-
return null;
285-
}
286-
287-
var match = treeishCommitRegex.Match(treeish);
288-
if (match.Success)
289-
{
290-
var tree = match.Groups["tree"].Value.Replace('/', '\\');
291-
return Path.Combine(tree, blobName);
292-
}
293-
294-
match = treeishBranchRegex.Match(treeish);
295-
if (match.Success)
296-
{
297-
var tree = match.Groups["tree"].Value.Replace('/', '\\');
298-
return Path.Combine(tree, blobName);
299-
}
300-
301-
return null;
302-
}
303-
304252
public (string commitish, string path) ResolveBlob(string repositoryDir, GitHubContext context)
305253
{
306254
Guard.ArgumentNotNull(repositoryDir, nameof(repositoryDir));

src/GitHub.Exports/Services/IGitHubContextService.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ public interface IGitHubContextService
1111
GitHubContext FindContextFromUrl(string url);
1212
GitHubContext FindContextFromWindowTitle(string windowTitle);
1313
IEnumerable<string> FindWindowTitlesForClass(string className);
14-
string ResolvePath(GitHubContext context);
1514
Uri ToRepositoryUrl(GitHubContext context);
1615
bool TryOpenFile(string repositoryDir, GitHubContext context);
1716
Task<bool> TryAnnotateFile(string repositoryDir, string currentBranch, GitHubContext context);

test/GitHub.App.UnitTests/Services/GitHubContextServiceTests.cs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -350,27 +350,6 @@ public void ResolveBlob(string url, string commitish, string objectish, string e
350350
}
351351
}
352352

353-
public class TheResolvePathMethod
354-
{
355-
[TestCase("https://github.com/github/VisualStudio/blob/ee863ce265fc6217f589e66766125fed1b5b8256/foo.cs", "foo.cs")]
356-
[TestCase("https://github.com/github/VisualStudio/blob/ee863ce265fc6217f589e66766125fed1b5b8256/dir/foo.cs", @"dir\foo.cs")]
357-
[TestCase("https://github.com/github/VisualStudio/blob/ee863ce265fc6217f589e66766125fed1b5b8256/dir/subdir/foo.cs", @"dir\subdir\foo.cs")]
358-
[TestCase("https://github.com/github/VisualStudio/blob/master/foo.cs", "foo.cs")]
359-
[TestCase("https://github.com/github/VisualStudio/blob/master/dir/foo.cs", @"dir\foo.cs")]
360-
[TestCase("https://github.com/github/VisualStudio/blob/master/dir/subdir/foo.cs", @"dir\subdir\foo.cs")]
361-
[TestCase("https://github.com/github/VisualStudio/blob/unknown-branch/dir/subdir/foo.cs", null)]
362-
[TestCase("https://github.com/github/VisualStudio/blob/unknown/branch/dir/subdir/foo.cs", null)]
363-
public void ResolvePath(string url, string expectPath)
364-
{
365-
var target = CreateGitHubContextService();
366-
var context = target.FindContextFromUrl(url);
367-
368-
var path = target.ResolvePath(context);
369-
370-
Assert.That(path, Is.EqualTo(expectPath));
371-
}
372-
}
373-
374353
static GitHubContextService CreateGitHubContextService(string repositoryDir = null, IRepository repository = null)
375354
{
376355
var sp = Substitute.For<IGitHubServiceProvider>();

0 commit comments

Comments
 (0)