forked from GitTools/GitLink
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
I tried to implement the functionality mentioned in the issue GitTool…
…s#66 I did pretty much the same thing as Marcind with his CustomRawUrlProvider, here is the readme part. Running for an uncommon URL When working with a repository using uncommon URL you can use placeholders to specifiy where the filename and revision hash should be, use -u parameter with the custom URL GitLink.exe c:\source\catel -u "https://host/projects/catel/repos/catel/browse/{filename}?at={revision}&raw" The custom url will be used to fill the placeholders with the relative file path and the revision hash. I also added an option to download the sources with powershell because SRCSRV http support doesn't accept characters like "?" thus another option was needed
- Loading branch information
Simon Musy
committed
Nov 30, 2015
1 parent
fa353f6
commit fc4ec89
Showing
11 changed files
with
222 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
using GitLink.Providers; | ||
using NUnit.Framework; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace GitLink.Tests.Providers | ||
{ | ||
public class CustomUrlProviderFacts | ||
{ | ||
private const string correctUrl = "https://bitbucket.intra.company.com/projects/aaa/repos/a/browse/{filename}?at={revision}&raw"; | ||
[TestFixture] | ||
public class TheInitialization | ||
{ | ||
[TestCase(correctUrl, true)] | ||
[TestCase("https://example.com/repo", false)] | ||
[TestCase("https://bitbucket.intra.company.com/projects/aaa/repos/a/browse/{filename}?raw", true)] | ||
[TestCase("gopher://example.com/repo", false)] | ||
public void CorrectlyValidatesForUrls(string url, bool expectedValue) | ||
{ | ||
var provider = new CustomUrlProvider(); | ||
var valid = provider.Initialize(url); | ||
|
||
Assert.AreEqual(expectedValue, valid); | ||
} | ||
} | ||
|
||
[TestFixture] | ||
public class TheGitHubProviderProperties | ||
{ | ||
[TestCase] | ||
public void ReturnsNullCompany() | ||
{ | ||
var provider = new CustomUrlProvider(); | ||
provider.Initialize(correctUrl); | ||
|
||
Assert.IsNull(provider.CompanyName); | ||
} | ||
|
||
[TestCase] | ||
public void ReturnsNullCompanyUrl() | ||
{ | ||
var provider = new CustomUrlProvider(); | ||
provider.Initialize(correctUrl); | ||
|
||
Assert.IsNull(provider.CompanyUrl); | ||
} | ||
|
||
[TestCase] | ||
public void ReturnsNullProject() | ||
{ | ||
var provider = new CustomUrlProvider(); | ||
provider.Initialize(correctUrl); | ||
|
||
Assert.IsNull(provider.ProjectName); | ||
} | ||
|
||
[TestCase] | ||
public void ReturnsNullProjectUrl() | ||
{ | ||
var provider = new CustomUrlProvider(); | ||
provider.Initialize(correctUrl); | ||
|
||
Assert.IsNull(provider.ProjectUrl); | ||
} | ||
|
||
[TestCase] | ||
public void ReturnsValidRawGitUrl() | ||
{ | ||
var provider = new CustomUrlProvider(); | ||
provider.Initialize(correctUrl); | ||
|
||
string correctReturnedUrl = correctUrl.Replace("{filename}", "%var2%"); | ||
correctReturnedUrl = correctReturnedUrl.Replace("{revision}", "{0}"); | ||
|
||
Assert.AreEqual(correctReturnedUrl, provider.RawGitUrl); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
namespace GitLink.Providers | ||
{ | ||
using GitTools.Git; | ||
using System.Text.RegularExpressions; | ||
|
||
public sealed class CustomUrlProvider : ProviderBase | ||
{ | ||
private static readonly string fileNamePlaceHolder = "{filename}"; | ||
private static readonly string revisionPlaceHolder = "{revision}"; | ||
private readonly Regex _regexUrl = new Regex(@"https?://.+"); | ||
|
||
private string _rawUrl; | ||
|
||
public CustomUrlProvider() | ||
: base(new GitPreparer()) | ||
{ | ||
} | ||
|
||
public override string RawGitUrl | ||
{ | ||
get | ||
{ | ||
return _rawUrl; | ||
} | ||
} | ||
|
||
public override bool Initialize(string url) | ||
{ | ||
if (string.IsNullOrEmpty(url) || !_regexUrl.IsMatch(url) ||( | ||
!url.Contains(fileNamePlaceHolder) && !url.Contains(revisionPlaceHolder))) | ||
{ | ||
return false; | ||
} | ||
|
||
if(url.Contains(fileNamePlaceHolder)) | ||
_rawUrl = url.Replace(fileNamePlaceHolder, "%var2%"); | ||
|
||
if(url.Contains(revisionPlaceHolder)) | ||
_rawUrl = _rawUrl.Replace(revisionPlaceHolder, "{0}"); | ||
|
||
return true; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// -------------------------------------------------------------------------------------------------------------------- | ||
// <copyright file="ProviderManager.cs" company="CatenaLogic"> | ||
// Copyright (c) 2014 - 2014 CatenaLogic. All rights reserved. | ||
// </copyright> | ||
// -------------------------------------------------------------------------------------------------------------------- | ||
|
||
|
||
namespace GitLink.Providers | ||
{ | ||
using Catel.IoC; | ||
using Catel.Reflection; | ||
|
||
public class ProviderManager : IProviderManager | ||
{ | ||
public ProviderBase GetProvider(string url) | ||
{ | ||
var providerTypes = TypeCache.GetTypes(x => typeof(ProviderBase).IsAssignableFromEx(x) && !x.IsAbstract && x != typeof(CustomRawUrlProvider) && x != typeof(CustomUrlProvider)); | ||
|
||
var typeFactory = TypeFactory.Default; | ||
|
||
var customUrlProvider = typeFactory.CreateInstance<CustomUrlProvider>(); | ||
if (customUrlProvider.Initialize(url)) | ||
{ | ||
return customUrlProvider; | ||
} | ||
|
||
foreach (var providerType in providerTypes) | ||
{ | ||
var provider = (ProviderBase) typeFactory.CreateInstance(providerType); | ||
if (provider.Initialize(url)) | ||
{ | ||
return provider; | ||
} | ||
} | ||
|
||
var customProvider = typeFactory.CreateInstance<CustomRawUrlProvider>(); | ||
if (customProvider.Initialize(url)) | ||
{ | ||
return customProvider; | ||
} | ||
|
||
return null; | ||
} | ||
} | ||
} |