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

Commit 2c22a36

Browse files
committed
Check repository links have an owner and repo name
1 parent 516817f commit 2c22a36

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/GitHub.App/Services/GitHubContextService.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,18 @@ public GitHubContext FindContextFromUrl(string url)
124124
Url = uri
125125
};
126126

127+
if (uri.Owner == null)
128+
{
129+
context.LinkType = LinkType.Unknown;
130+
return context;
131+
}
132+
133+
if (uri.RepositoryName == null)
134+
{
135+
context.LinkType = LinkType.Unknown;
136+
return context;
137+
}
138+
127139
var repositoryUrl = uri.ToRepositoryUrl().ToString();
128140
if (string.Equals(url, repositoryUrl, StringComparison.OrdinalIgnoreCase) ||
129141
string.Equals(url, repositoryUrl + ".git", StringComparison.OrdinalIgnoreCase))

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ public void Url_EqualTo(string url, string expectUrl)
137137
[TestCase("https://github.com/github/VisualStudio.git", LinkType.Repository)]
138138
[TestCase("https://github.com/github/VisualStudio/unknown/master/README.md", LinkType.Unknown)]
139139
[TestCase("https://github.com/github/VisualStudio/blob/master/README.md", LinkType.Blob)]
140+
[TestCase("https://github.com", LinkType.Unknown)]
141+
[TestCase("https://github.com/github", LinkType.Unknown)]
140142
[TestCase("https://github.com/github/VisualStudio/unknown/master/README.md", LinkType.Unknown)]
141143
public void LinkType_EqualTo(string url, LinkType expectLinkType)
142144
{

0 commit comments

Comments
 (0)