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

Commit 516817f

Browse files
committed
Make FindContextFromUrl recognize repository URLs
1 parent 285c664 commit 516817f

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

src/GitHub.App/Services/GitHubContextService.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,15 @@ public GitHubContext FindContextFromUrl(string url)
124124
Url = uri
125125
};
126126

127-
var repositoryPrefix = uri.ToRepositoryUrl().ToString() + "/";
127+
var repositoryUrl = uri.ToRepositoryUrl().ToString();
128+
if (string.Equals(url, repositoryUrl, StringComparison.OrdinalIgnoreCase) ||
129+
string.Equals(url, repositoryUrl + ".git", StringComparison.OrdinalIgnoreCase))
130+
{
131+
context.LinkType = LinkType.Repository;
132+
return context;
133+
}
134+
135+
var repositoryPrefix = repositoryUrl + "/";
128136
if (!url.StartsWith(repositoryPrefix, StringComparison.OrdinalIgnoreCase))
129137
{
130138
return context;

src/GitHub.Exports/Exports/ExportMetadata.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ public enum LinkType
2121
{
2222
Unknown,
2323
Blob,
24-
Blame
24+
Blame,
25+
Repository
2526
}
2627

2728
/// <summary>

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ public void Url_EqualTo(string url, string expectUrl)
133133
Assert.That(context.Url?.ToString(), Is.EqualTo(expectUrl));
134134
}
135135

136+
[TestCase("https://github.com/github/VisualStudio", LinkType.Repository)]
137+
[TestCase("https://github.com/github/VisualStudio.git", LinkType.Repository)]
138+
[TestCase("https://github.com/github/VisualStudio/unknown/master/README.md", LinkType.Unknown)]
136139
[TestCase("https://github.com/github/VisualStudio/blob/master/README.md", LinkType.Blob)]
137140
[TestCase("https://github.com/github/VisualStudio/unknown/master/README.md", LinkType.Unknown)]
138141
public void LinkType_EqualTo(string url, LinkType expectLinkType)

0 commit comments

Comments
 (0)