-
Notifications
You must be signed in to change notification settings - Fork 11
Added first support for issue trackers #10
Changes from 5 commits
eb748fa
31688f6
6d4f4ca
23bfa4d
cb187f9
914e704
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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> | ||
<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()); | ||
} | ||
} | ||
} |
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> |
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; } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be a SecureString? https://msdn.microsoft.com/en-us/library/system.security.securestring(v=vs.110).aspx There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
---|---|---|
@@ -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"); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
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 runnuget pack -version 1.10.0
There was a problem hiding this comment.
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.