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

Commit

Permalink
Merge pull request #67 from marcind/customUrl
Browse files Browse the repository at this point in the history
(#37) Add CustomRawUrlProvider to enable arbitrary content URLs
  • Loading branch information
GeertvanHorrik committed Nov 12, 2015
2 parents bc35b66 + da9c86f commit c6e3728
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 1 deletion.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,14 @@ When specific projects should be ignored, use the *-ignore* option. This option

GitLink.exe c:\source\catel -u https://github.com/catel/catel -f Catel.sln -ignore Catel.Core.WP80,Catel.MVVM.WP80

## Running for a custom raw content URL

When working with a content proxy or an alternative git VCS system that supports direct HTTP access to specific file revisions use the `-u` parameter with the custom raw content root URL

GitLink.exe c:\source\catel -u https://raw.githubusercontent.com/catel/catel

The custom url will be used to fill in the following pattern `{customUrl}/{revision}/{raltiveFilePath}` when generating the source mapping.

## Getting help

When you need help about GitLink, use the following command line:
Expand Down
1 change: 1 addition & 0 deletions src/GitLink.Tests/GitLink.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="GlobalInitialization.cs" />
<Compile Include="Providers\BitBucketProviderFacts.cs" />
<Compile Include="Providers\CustomRawUrlProviderFacts.cs" />
<Compile Include="Providers\GitHubProviderFacts.cs" />
<Compile Include="Providers\ProviderManagerFacts.cs" />
</ItemGroup>
Expand Down
82 changes: 82 additions & 0 deletions src/GitLink.Tests/Providers/CustomRawUrlProviderFacts.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
namespace GitLink.Tests.Providers
{
using GitLink.Providers;
using NUnit.Framework;

public class CustomRawUrlProviderFacts
{
[TestFixture]
public class TheInitialization
{
[TestCase("http://example.com/repo", true)]
[TestCase("https://example.com/repo", true)]
[TestCase("https://example.com/repo/", true)]
[TestCase("gopher://example.com/repo", false)]
public void CorrectlyValidatesForUrls(string url, bool expectedValue)
{
var provider = new CustomRawUrlProvider();
var valid = provider.Initialize(url);

Assert.AreEqual(expectedValue, valid);
}
}

[TestFixture]
public class TheGitHubProviderProperties
{
[TestCase]
public void ReturnsNullCompany()
{
var provider = new CustomRawUrlProvider();
provider.Initialize("http://example.com/repo");

Assert.IsNull(provider.CompanyName);
}

[TestCase]
public void ReturnsNullCompanyUrl()
{
var provider = new CustomRawUrlProvider();
provider.Initialize("http://example.com/repo");

Assert.IsNull(provider.CompanyUrl);
}

[TestCase]
public void ReturnsNullProject()
{
var provider = new CustomRawUrlProvider();
provider.Initialize("http://example.com/repo");

Assert.IsNull(provider.ProjectName);
}

[TestCase]
public void ReturnsNullProjectUrl()
{
var provider = new CustomRawUrlProvider();
provider.Initialize("http://example.com/repo");

Assert.IsNull(provider.ProjectUrl);
}

[TestCase]
public void ReturnsValidRawGitUrl()
{
var provider = new CustomRawUrlProvider();
provider.Initialize("http://example.com/repo");

Assert.AreEqual("http://example.com/repo", provider.RawGitUrl);
}

[TestCase]
public void ReturnsValidRawGitUrlWithNoTrailingSlash()
{
var provider = new CustomRawUrlProvider();
provider.Initialize("http://example.com/repo/");

Assert.AreEqual("http://example.com/repo", provider.RawGitUrl);
}
}
}
}
1 change: 1 addition & 0 deletions src/GitLink.Tests/Providers/ProviderManagerFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class TheProviderGetProviderMethod
{
[TestCase("https://bitbucket.org/CatenaLogic/GitLink", typeof(BitBucketProvider))]
[TestCase("https://github.com/CatenaLogic/GitLink", typeof(GitHubProvider))]
[TestCase("https://example.com/repo", typeof(CustomRawUrlProvider))]
[TestCase("", null)]
public void ReturnsRightProvider(string url, Type expectedType)
{
Expand Down
1 change: 1 addition & 0 deletions src/GitLink/GitLink.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Context.cs" />
<Compile Include="Providers\BitBucketProvider.cs" />
<Compile Include="Providers\CustomRawUrlProvider.cs" />
<Compile Include="Providers\GitHubProvider.cs" />
<Compile Include="Providers\Interfaces\IProviderManager.cs" />
<Compile Include="Providers\Interfaces\IProvider.cs" />
Expand Down
42 changes: 42 additions & 0 deletions src/GitLink/Providers/CustomRawUrlProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
namespace GitLink.Providers
{
using System;
using System.Text.RegularExpressions;
using GitTools.Git;

public sealed class CustomRawUrlProvider : ProviderBase
{
private readonly Regex _regex = new Regex(@"https?://.+");

private string _rawUrl;

public CustomRawUrlProvider()
: base(new GitPreparer())
{
}

public override string RawGitUrl
{
get
{
return _rawUrl;
}
}

public override bool Initialize(string url)
{
if (string.IsNullOrEmpty(url) || !_regex.IsMatch(url))
{
return false;
}

_rawUrl = url;
if (_rawUrl.EndsWith("/", StringComparison.Ordinal))
{
_rawUrl = _rawUrl.TrimEnd('/');
}

return true;
}
}
}
8 changes: 7 additions & 1 deletion src/GitLink/Providers/ProviderManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class ProviderManager : IProviderManager
{
public ProviderBase GetProvider(string url)
{
var providerTypes = TypeCache.GetTypes(x => typeof(ProviderBase).IsAssignableFromEx(x) && !x.IsAbstract);
var providerTypes = TypeCache.GetTypes(x => typeof(ProviderBase).IsAssignableFromEx(x) && !x.IsAbstract && x != typeof(CustomRawUrlProvider));

var typeFactory = TypeFactory.Default;

Expand All @@ -27,6 +27,12 @@ public ProviderBase GetProvider(string url)
}
}

var customProvider = typeFactory.CreateInstance<CustomRawUrlProvider>();
if (customProvider.Initialize(url))
{
return customProvider;
}

return null;
}
}
Expand Down

0 comments on commit c6e3728

Please sign in to comment.