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

Added first support for issue trackers #10

Merged
merged 6 commits into from
Jun 9, 2015
Merged
Show file tree
Hide file tree
Changes from 5 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
Binary file modified deployment/FinalBuilder/GitTools.Core.CreatePackages.fbp7
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0"?>
<package>
<metadata>
<id>GitTools.IssueTrackers</id>
<version>[VERSION]</version>
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not use $version$ then run nuget pack -version 1.10.0

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I use FinalBuilder, just a basic script for all packages (also picks up the right dependencies, etc). Not really in scope to change anything related to this for now.

<title>GitTools.IssueTrackers</title>
<authors>gittools</authors>
<owners>gittools</owners>

<description>
Issue Trackers core library for GitTools.
</description>
<summary>
</summary>

<tags>git tools issue tracker</tags>

<requireLicenseAcceptance>false</requireLicenseAcceptance>
<copyright>Copyright GitTools team 2010 - 2015</copyright>

<language>en-US</language>
<projectUrl>https://github.com/GitTools/GitTools.Core</projectUrl>
<!--<licenseUrl>http://catel.codeplex.com/license</licenseUrl>-->
<!--<iconUrl>http://www.catenalogic.com/catel.png</iconUrl>-->

<dependencies>
<dependency id="GitTools.Core" version="[VERSION]" />

<!--<dependency id="GitTools.Core" version="[replaced]" />-->
</dependencies>
</metadata>
</package>
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
namespace GitTools.Tests
{
using NUnit.Framework;

[TestFixture]
public class IAuthenticationContextExtensionsFacts
{
[TestCase("user", "password", null, false)]
[TestCase(null, null, "token", false)]
[TestCase(null, null, null, true)]
public void TheIsEmptyMethod(string username, string password, string token, bool expectedValue)
{
var authenticationContext = new AuthenticationContext
{
Username = username,
Password = password,
Token = token
};

Assert.AreEqual(expectedValue, authenticationContext.IsEmpty());
}

[TestCase("user", "password", null, true)]
[TestCase(null, null, "token", false)]
[TestCase(null, null, null, false)]
public void TheIsUsernameAndPasswordAuthenticationMethod(string username, string password, string token, bool expectedValue)
{
var authenticationContext = new AuthenticationContext
{
Username = username,
Password = password,
Token = token
};

Assert.AreEqual(expectedValue, authenticationContext.IsUsernameAndPasswordAuthentication());
}

[TestCase("user", "password", null, false)]
[TestCase(null, null, "token", true)]
[TestCase(null, null, null, false)]
public void TheIsTokenAuthenticationMethod(string username, string password, string token, bool expectedValue)
{
var authenticationContext = new AuthenticationContext
{
Username = username,
Password = password,
Token = token
};

Assert.AreEqual(expectedValue, authenticationContext.IsTokenAuthentication());
}
}
}
9 changes: 9 additions & 0 deletions src/GitTools.Core.Tests/GitTools.Core.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
<NoWarn>1591;1998</NoWarn>
</PropertyGroup>
<ItemGroup>
<Reference Include="Jira.SDK">
<HintPath>..\..\lib\Jira.SDK.1.1.1.2\lib\net45\Jira.SDK.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="nunit.framework, Version=2.6.4.14350, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<HintPath>..\..\lib\NUnit.2.6.4\lib\nunit.framework.dll</HintPath>
<Private>True</Private>
Expand All @@ -59,6 +63,7 @@
<Compile Include="ArgumentParserFacts.cs" />
<Compile Include="ContextFacts.cs" />
<Compile Include="Context\Context.cs" />
<Compile Include="Context\Extensions\IAuthenticationContextExtensionsFacts.cs" />
<Compile Include="Extensions\StringExtensionsFacts.cs" />
<Compile Include="GlobalInitialization.cs" />
<Compile Include="ModuleInitializer.cs" />
Expand All @@ -69,6 +74,10 @@
<Project>{c11252f9-0eca-44dc-860b-e029c04fbd10}</Project>
<Name>GitTools.Core</Name>
</ProjectReference>
<ProjectReference Include="..\GitTools.IssueTrackers\GitTools.IssueTrackers.csproj">
<Project>{ac5f41ea-962e-491b-8557-a2a10dc757e4}</Project>
<Name>GitTools.IssueTrackers</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Content Include="FodyWeavers.xml" />
Expand Down
9 changes: 5 additions & 4 deletions src/GitTools.Core.Tests/packages.config
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Fody" version="1.29.0-beta01" targetFramework="net45" userInstalled="true" />
<package id="ModuleInit.Fody" version="1.5.6.0" targetFramework="net45" developmentDependency="true" userInstalled="true" />
<package id="NUnit" version="2.6.4" targetFramework="net45" userInstalled="true" />
<package id="Shouldly" version="2.5.0" targetFramework="net45" userInstalled="true" />
<package id="Fody" version="1.29.0-beta01" targetFramework="net45" />
<package id="Jira.SDK" version="1.1.1.2" targetFramework="net45" />
<package id="ModuleInit.Fody" version="1.5.6.0" targetFramework="net45" developmentDependency="true" />
<package id="NUnit" version="2.6.4" targetFramework="net45" />
<package id="Shouldly" version="2.5.0" targetFramework="net45" />
</packages>
14 changes: 12 additions & 2 deletions src/GitTools.Core.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.31101.0
# Visual Studio 14
VisualStudioVersion = 14.0.22823.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitTools.Core", "GitTools.Core\GitTools.Core.csproj", "{C11252F9-0ECA-44DC-860B-E029C04FBD10}"
EndProject
Expand All @@ -26,6 +26,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "lib", "lib", "{532E0393-2C1
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitTools.Core.Tests", "GitTools.Core.Tests\GitTools.Core.Tests.csproj", "{0834BE9B-5CDE-4CAB-A683-C70A7D91450B}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Core.IssueTrackers", "Core.IssueTrackers", "{5E7A6723-E488-4CFF-B838-B5ABA6B38479}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitTools.IssueTrackers", "GitTools.IssueTrackers\GitTools.IssueTrackers.csproj", "{AC5F41EA-962E-491B-8557-A2A10DC757E4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -40,6 +44,10 @@ Global
{0834BE9B-5CDE-4CAB-A683-C70A7D91450B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0834BE9B-5CDE-4CAB-A683-C70A7D91450B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0834BE9B-5CDE-4CAB-A683-C70A7D91450B}.Release|Any CPU.Build.0 = Release|Any CPU
{AC5F41EA-962E-491B-8557-A2A10DC757E4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AC5F41EA-962E-491B-8557-A2A10DC757E4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AC5F41EA-962E-491B-8557-A2A10DC757E4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AC5F41EA-962E-491B-8557-A2A10DC757E4}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -49,5 +57,7 @@ Global
{1E56230A-4CDE-4142-A7F0-BE0625746DA0} = {17E77AE6-5E23-4898-BCAB-7AF62BB0DFBA}
{377F4B45-0F5E-4F78-8A7B-27725DC79197} = {17E77AE6-5E23-4898-BCAB-7AF62BB0DFBA}
{0834BE9B-5CDE-4CAB-A683-C70A7D91450B} = {377F4B45-0F5E-4F78-8A7B-27725DC79197}
{5E7A6723-E488-4CFF-B838-B5ABA6B38479} = {17E77AE6-5E23-4898-BCAB-7AF62BB0DFBA}
{AC5F41EA-962E-491B-8557-A2A10DC757E4} = {5E7A6723-E488-4CFF-B838-B5ABA6B38479}
EndGlobalSection
EndGlobal
2 changes: 2 additions & 0 deletions src/GitTools.Core/App_Packages/LibLog.4.2/LibLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@

#pragma warning disable 1591

#define LIBLOG_PUBLIC

// If you copied this file manually, you need to change all "YourRootNameSpace" so not to clash with other libraries
// that use LibLog
#if LIBLOG_PROVIDERS_ONLY
Expand Down
24 changes: 24 additions & 0 deletions src/GitTools.Core/Context/AuthenticationContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
namespace GitTools
{
public class AuthenticationContext : IAuthenticationContext
{
public AuthenticationContext()
{
}

public AuthenticationContext(string username, string password)
{
Username = username;
Password = password;
}

public AuthenticationContext(string token)
{
Token = token;
}

public string Username { get; set; }
public string Password { get; set; }
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have considered that, but we pass everything around as strings (into the command line). Do you think it will be better? It's an easy change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have implemented all context as Disposable now so we can use secure strings now if we want to.

Copy link
Member

Choose a reason for hiding this comment

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

In all honesty, I don't know 😸 It just occurred to me that perhaps we should. If we can't accept the input from the command line as a SecureString, then there isn't much point (I think) in converting as the string would already to subject to "attack". Not sure there is much to be gained here, unless we prompt the user to input credentials into standard credential window, rather than directly at the command line, but that would break the automation route?!?

public string Token { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
namespace GitTools
{
using Logging;

public static class IAuthenticationContextExtensions
{
private static readonly ILog Log = LogProvider.GetCurrentClassLogger();

public static bool IsEmpty(this IAuthenticationContext authenticationContext)
{
if (authenticationContext == null)
{
return true;
}

if (IsUsernameAndPasswordAuthentication(authenticationContext))
{
return false;
}

if (IsTokenAuthentication(authenticationContext))
{
return false;
}

return true;
}

public static bool IsUsernameAndPasswordAuthentication(this IAuthenticationContext authenticationContext)
{
if (authenticationContext == null)
{
return false;
}

if (string.IsNullOrWhiteSpace(authenticationContext.Username))
{
return false;
}

if (string.IsNullOrWhiteSpace(authenticationContext.Password))
{
return false;
}

return true;
}

public static bool IsTokenAuthentication(this IAuthenticationContext authenticationContext)
{
if (authenticationContext == null)
{
return false;
}

if (string.IsNullOrWhiteSpace(authenticationContext.Token))
{
return false;
}

return true;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
namespace GitTools
{
using Logging;

public static class IRepositoryContextExtensions
{
private static readonly ILog Log = LogProvider.GetCurrentClassLogger();

public static bool Validate(this IRepositoryContext context)
{
if (string.IsNullOrWhiteSpace(context.Url))
{
Log.Error("Repository.Url is required");
return false;
}

if (string.IsNullOrWhiteSpace(context.Branch))
{
Log.Error("Repository.Branch is required");
return false;
}

return true;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ public interface IAuthenticationContext
string Username { get; set; }

string Password { get; set; }

string Token { get; set; }
}
}
4 changes: 3 additions & 1 deletion src/GitTools.Core/Context/Interfaces/IRepositoryContext.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
namespace GitTools
{
public interface IRepositoryContext : IAuthenticationContext
public interface IRepositoryContext
{
IAuthenticationContext Authentication { get; }

string Directory { get; set; }

string Branch { get; set; }
Expand Down
9 changes: 6 additions & 3 deletions src/GitTools.Core/Context/RepositoryContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@
{
public class RepositoryContext : IRepositoryContext
{
public RepositoryContext()
{
Authentication = new AuthenticationContext();
}

public string Directory { get; set; }

public string Branch { get; set; }

public string Url { get; set; }

public string Username { get; set; }

public string Password { get; set; }
public IAuthenticationContext Authentication { get; private set; }
}
}
50 changes: 50 additions & 0 deletions src/GitTools.Core/Git/Extensions/IRepositoryExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
namespace GitTools.Git
{
using System;
using System.Collections.Generic;
using System.Linq;
using LibGit2Sharp;

public static class IRepositoryExtensions
{
private static readonly Dictionary<string, TaggedCommit> Cache = new Dictionary<string, TaggedCommit>();

public static TaggedCommit GetLastTaggedCommit(this IRepository repository)
{
return GetTag(repository, string.Empty);
}

public static TaggedCommit GetFirstCommit(this IRepository repository)
{
var branch = repository.Head;
return new TaggedCommit(branch.Commits.Last(), "Initial Commit");
}

public static TaggedCommit GetTag(this IRepository repository, string fromTag)
{
if (!Cache.ContainsKey(fromTag))
{
Cache.Add(fromTag, GetLastTaggedCommit(repository, t => string.IsNullOrEmpty(fromTag) || t.TagName == fromTag));
}

return Cache[fromTag];
}

public static TaggedCommit GetLastTaggedCommit(this IRepository repository, Func<TaggedCommit, bool> filterTags)
{
var branch = repository.Head;
var tags = repository.Tags
.Select(t => new TaggedCommit((Commit) t.Target, t.Name))
.Where(filterTags)
.ToArray();
var olderThan = branch.Tip.Author.When;
var lastTaggedCommit = branch.Commits.FirstOrDefault(c => c.Author.When <= olderThan && tags.Any(a => a.Commit == c));
if (lastTaggedCommit != null)
{
return tags.FirstOrDefault(a => a.Commit.Sha == lastTaggedCommit.Sha);
}

return new TaggedCommit(branch.Commits.Last(), "Initial Commit");
}
}
}
Loading