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

Commit 381806b

Browse files
committed
Add support for resolving tags
1 parent 19be672 commit 381806b

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

src/GitHub.App/Services/GitHubContextService.cs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -281,21 +281,22 @@ public bool TryOpenFile(string repositoryDir, GitHubContext context)
281281

282282
foreach (var (commitish, path) in objectish)
283283
{
284-
var remoteRef = $"refs/remotes/{remoteName}/{commitish}";
285-
var commit = repository.Lookup(remoteRef);
286-
if (commit == null)
284+
var resolveRefs = new[] { $"refs/remotes/{remoteName}/{commitish}", $"refs/tags/{commitish}" };
285+
foreach (var resolveRef in resolveRefs)
287286
{
288-
continue;
287+
var commit = repository.Lookup(resolveRef);
288+
if (commit != null)
289+
{
290+
var blob = repository.Lookup($"{resolveRef}:{path}");
291+
if (blob != null)
292+
{
293+
return (resolveRef, path, commit.Sha);
294+
}
295+
296+
// Resolved commitish but not path
297+
return (resolveRef, null, commit.Sha);
298+
}
289299
}
290-
291-
var blob = repository.Lookup($"{remoteRef}:{path}");
292-
if (blob == null)
293-
{
294-
// Resolved commitish but not path
295-
return (remoteRef, null, commit.Sha);
296-
}
297-
298-
return (remoteRef, path, commit.Sha);
299300
}
300301

301302
return (null, null, null);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ public class TheResolveBlobMethod
335335
[TestCase("https://github.com/github/VisualStudio/blob/master/foo.cs", "refs/remotes/origin/master", null, "refs/remotes/origin/master", null, CommitSha, Description = "Resolve commit only")]
336336
[TestCase("https://github.com/github/VisualStudio/blob/36d6b0bb6e319337180d523281c42d9611744e66/src/code.cs", CommitSha, CommitSha + ":src/code.cs", CommitSha, "src/code.cs", CommitSha, Description = "Resolve commit only")]
337337
[TestCase("https://github.com/github/VisualStudio/commit/8cf9a268c497adb4fc0a14572253165e179dd11e", "8cf9a268c497adb4fc0a14572253165e179dd11e", null, null, null, null)]
338+
[TestCase("https://github.com/github/VisualStudio/blob/v2.5.3.2888/build.cmd", "refs/tags/v2.5.3.2888", "refs/tags/v2.5.3.2888:build.cmd", "refs/tags/v2.5.3.2888", "build.cmd", CommitSha)]
338339
public void ResolveBlob(string url, string commitish, string objectish, string expectCommitish, string expectPath, string expectCommitSha)
339340
{
340341
var repositoryDir = "repositoryDir";

0 commit comments

Comments
 (0)