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

(#37) Add CustomRawUrlProvider to enable arbitrary content URLs #67

Merged
merged 1 commit into from
Nov 12, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

raltiveFilePath => relativeFilePath


## 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