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

Commit 39f3a54

Browse files
committed
Rename Treeish to TreeishPath
GitHub URLs combine branches/SHAs and tree paths. For example: https://github.com/github/visualstudio/tree/master/src Git would represent "master/src" as the tree-ish "master:src". Because looking at the URL we don't know where the branch stops and the tree starts, "master/src" is being stored as the TreeishPath property.
1 parent 2243891 commit 39f3a54

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

src/GitHub.App/Services/GitHubContext.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ public class GitHubContext
88
public string RepositoryName { get; set; }
99
public string Host { get; set; }
1010
public string BranchName { get; set; }
11-
public string Treeish { get; set; }
11+
/// <summary>
12+
/// Like a tree-ish but with ':' changed to '/' (e.g. "master/src" not "master:src").
13+
/// </summary>
14+
public string TreeishPath { get; set; }
1215
public string BlobName { get; set; }
1316
public int? PullRequest { get; set; }
1417
public int? Issue { get; set; }

src/GitHub.App/Services/GitHubContextService.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public GitHubContext FindContextFromUrl(string url)
9191
var match = urlBlobRegex.Match(subpath);
9292
if (match.Success)
9393
{
94-
context.Treeish = match.Groups["treeish"].Value;
94+
context.TreeishPath = match.Groups["treeish"].Value;
9595
context.BlobName = match.Groups["blobName"].Value;
9696
return context;
9797
}
@@ -155,7 +155,7 @@ public GitHubContext FindContextFromWindowTitle(string windowTitle)
155155
Owner = match.Groups["owner"].Value,
156156
RepositoryName = match.Groups["repo"].Value,
157157
BranchName = match.Groups["branch"].Value,
158-
Treeish = $"{match.Groups["branch"].Value}/{match.Groups["tree"].Value}"
158+
TreeishPath = $"{match.Groups["branch"].Value}/{match.Groups["tree"].Value}"
159159
};
160160
}
161161

@@ -266,7 +266,7 @@ public bool TryOpenFile(GitHubContext context, string repositoryDir)
266266

267267
public string ResolvePath(GitHubContext context)
268268
{
269-
var treeish = context.Treeish;
269+
var treeish = context.TreeishPath;
270270
if (treeish == null)
271271
{
272272
return null;

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,13 @@ public void PullRequest(string url, int? expectPullRequest)
6969
[TestCase("https://github.com/github/VisualStudio/blob/ee863ce265fc6217f589e66766125fed1b5b8256/foo.cs", "ee863ce265fc6217f589e66766125fed1b5b8256", "foo.cs")]
7070
[TestCase("https://github.com/github/VisualStudio/blob/ee863ce265fc6217f589e66766125fed1b5b8256/path/foo.cs", "ee863ce265fc6217f589e66766125fed1b5b8256/path", "foo.cs")]
7171
[TestCase("https://github.com/github/VisualStudio/blob/master/bar.cs#stuff", "master", "bar.cs")]
72-
public void Blob(string url, string expectTreeish, string expectBlobName)
72+
public void Blob(string url, string expectTreeishPath, string expectBlobName)
7373
{
7474
var target = CreateGitHubContextService();
7575

7676
var context = target.FindContextFromUrl(url);
7777

78-
Assert.That(context.Treeish, Is.EqualTo(expectTreeish));
78+
Assert.That(context.TreeishPath, Is.EqualTo(expectTreeishPath));
7979
Assert.That(context.BlobName, Is.EqualTo(expectBlobName));
8080
}
8181

@@ -302,7 +302,7 @@ public void Tree(string windowTitle, string expectTreeish, string expectBranch)
302302

303303
var context = target.FindContextFromWindowTitle(windowTitle);
304304

305-
Assert.That(context?.Treeish, Is.EqualTo(expectTreeish));
305+
Assert.That(context?.TreeishPath, Is.EqualTo(expectTreeish));
306306
Assert.That(context?.BranchName, Is.EqualTo(expectBranch));
307307
}
308308

0 commit comments

Comments
 (0)