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

Commit

Permalink
Check repository links have an owner and repo name
Browse files Browse the repository at this point in the history
  • Loading branch information
jcansdale committed Jan 14, 2019
1 parent 516817f commit 2c22a36
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/GitHub.App/Services/GitHubContextService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,18 @@ public GitHubContext FindContextFromUrl(string url)
Url = uri
};

if (uri.Owner == null)
{
context.LinkType = LinkType.Unknown;
return context;
}

if (uri.RepositoryName == null)
{
context.LinkType = LinkType.Unknown;
return context;
}

var repositoryUrl = uri.ToRepositoryUrl().ToString();
if (string.Equals(url, repositoryUrl, StringComparison.OrdinalIgnoreCase) ||
string.Equals(url, repositoryUrl + ".git", StringComparison.OrdinalIgnoreCase))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ public void Url_EqualTo(string url, string expectUrl)
[TestCase("https://github.com/github/VisualStudio.git", LinkType.Repository)]
[TestCase("https://github.com/github/VisualStudio/unknown/master/README.md", LinkType.Unknown)]
[TestCase("https://github.com/github/VisualStudio/blob/master/README.md", LinkType.Blob)]
[TestCase("https://github.com", LinkType.Unknown)]
[TestCase("https://github.com/github", LinkType.Unknown)]
[TestCase("https://github.com/github/VisualStudio/unknown/master/README.md", LinkType.Unknown)]
public void LinkType_EqualTo(string url, LinkType expectLinkType)
{
Expand Down

0 comments on commit 2c22a36

Please sign in to comment.