-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* release/1.1.0: Update 1.1.0 release notes Use preview LibGit2Sharp for all monikers Test ubuntu-18.04 Add GitHub actions Update to LibGit2Sharp v0.27.0-preview-0102 Added some tests. Added more basic configuration methods. Initial commit of the get config method.
- Loading branch information
Showing
7 changed files
with
315 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
name: Build | ||
on: | ||
pull_request: | ||
push: | ||
branches: | ||
- master | ||
- develop | ||
- hotfix/* | ||
|
||
jobs: | ||
build: | ||
name: Build | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
os: [ubuntu-18.04, ubuntu-latest, macos-latest] | ||
steps: | ||
- name: Get the sources | ||
uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Install .NET Core SDK 3.1.x | ||
uses: actions/setup-dotnet@v1 | ||
with: | ||
dotnet-version: '3.1.x' | ||
|
||
- name: Install .NET Core SDK | ||
uses: actions/setup-dotnet@v1 | ||
|
||
- if: matrix.os == 'windows-latest' | ||
name: Run Cake script Windows | ||
run: | | ||
./build.ps1 | ||
- if: matrix.os != 'windows-latest' | ||
name: Run Cake script Posix | ||
run: | | ||
./build.sh | ||
- name: Upload Artifacts | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
name: artifacts | ||
path: artifacts | ||
|
||
- name: Upload NuGet Package | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
name: nuget | ||
path: nuget |
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,226 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Cake.Core; | ||
using Cake.Core.Annotations; | ||
using Cake.Core.IO; | ||
using Cake.Git.Extensions; | ||
using LibGit2Sharp; | ||
|
||
namespace Cake.Git | ||
{ | ||
public static partial class GitAliases | ||
{ | ||
/// <summary> | ||
/// Gets the specified configuration value. | ||
/// </summary> | ||
/// | ||
/// <example> | ||
/// <code> | ||
/// var configValue = GitConfigGet<string>("user.email"); | ||
/// </code> | ||
/// </example> | ||
/// | ||
/// <param name="context">The context.</param> | ||
/// <param name="repositoryDirectoryPath">Repository path.</param> | ||
/// <param name="key">The configuration key.</param> | ||
/// | ||
/// <typeparam name="T">The expected type of configuration.</typeparam> | ||
/// | ||
/// <returns>The value of the specified configuration key.</returns> | ||
/// | ||
/// <exception cref="ArgumentNullException"></exception> | ||
/// <exception cref="ArgumentException"></exception> | ||
/// <exception cref="KeyNotFoundException">Configuration value not found.</exception> | ||
[CakeMethodAlias] | ||
[CakeAliasCategory("Configuration")] | ||
public static T GitConfigGet<T>( | ||
this ICakeContext context, | ||
DirectoryPath repositoryDirectoryPath, | ||
string key) | ||
{ | ||
if (context is null) | ||
{ | ||
throw new ArgumentNullException(nameof(context)); | ||
} | ||
|
||
if (repositoryDirectoryPath is null) | ||
{ | ||
throw new ArgumentException(nameof(repositoryDirectoryPath)); | ||
} | ||
|
||
return context.UseRepository( | ||
repositoryDirectoryPath, | ||
repository => | ||
{ | ||
var config = repository.Config.Get<T>(key) | ||
?? throw new KeyNotFoundException("Configuration not found."); | ||
return config.Value; | ||
}); | ||
} | ||
|
||
/// <summary> | ||
/// Gets the specified configuration value. If the specified value is not found it will return the specified | ||
/// default value. | ||
/// </summary> | ||
/// | ||
/// <example> | ||
/// <code> | ||
/// var configValue = GitConfigGet("user.email", "[email protected]"); | ||
/// </code> | ||
/// </example> | ||
/// | ||
/// <param name="context">The context.</param> | ||
/// <param name="repositoryDirectoryPath">Repository path.</param> | ||
/// <param name="key">The configuration key.</param> | ||
/// <param name="defaultValue">The default value to use if the configuration isn't present.</param> | ||
/// | ||
/// <typeparam name="T">The expected type of configuration.</typeparam> | ||
/// | ||
/// <returns>The value of the specified configuration key.</returns> | ||
/// | ||
/// <exception cref="ArgumentNullException"></exception> | ||
/// <exception cref="ArgumentException"></exception> | ||
[CakeMethodAlias] | ||
[CakeAliasCategory("Configuration")] | ||
public static T GitConfigGet<T>( | ||
this ICakeContext context, | ||
DirectoryPath repositoryDirectoryPath, | ||
string key, | ||
T defaultValue) | ||
{ | ||
if (context is null) | ||
{ | ||
throw new ArgumentNullException(nameof(context)); | ||
} | ||
|
||
if (repositoryDirectoryPath is null) | ||
{ | ||
throw new ArgumentException(nameof(repositoryDirectoryPath)); | ||
} | ||
|
||
return context.UseRepository( | ||
repositoryDirectoryPath, | ||
repository => repository.Config.GetValueOrDefault<T>(key)); | ||
} | ||
|
||
/// <summary> | ||
/// Gets the specified configuration value. If the specified value is not found it will return the specified | ||
/// default value. | ||
/// </summary> | ||
/// | ||
/// <example> | ||
/// <code> | ||
/// GitConfigSet("user.email", "[email protected]"); | ||
/// </code> | ||
/// </example> | ||
/// | ||
/// <param name="context">The context.</param> | ||
/// <param name="repositoryDirectoryPath">Repository path.</param> | ||
/// <param name="key">The configuration key.</param> | ||
/// <param name="newValue">The new value.</param> | ||
/// | ||
/// <typeparam name="T">The type of configuration.</typeparam> | ||
/// | ||
/// <exception cref="ArgumentNullException"></exception> | ||
/// <exception cref="ArgumentException"></exception> | ||
[CakeMethodAlias] | ||
[CakeAliasCategory("Configuration")] | ||
public static void GitConfigSetLocal<T>( | ||
this ICakeContext context, | ||
DirectoryPath repositoryDirectoryPath, | ||
string key, | ||
T newValue) | ||
{ | ||
if (context is null) | ||
{ | ||
throw new ArgumentNullException(nameof(context)); | ||
} | ||
|
||
if (repositoryDirectoryPath is null) | ||
{ | ||
throw new ArgumentException(nameof(repositoryDirectoryPath)); | ||
} | ||
|
||
context.UseRepository(repositoryDirectoryPath, repository => repository.Config.Set(key, newValue, ConfigurationLevel.Local)); | ||
} | ||
|
||
/// <summary> | ||
/// Unsets the specified local configuration key. | ||
/// </summary> | ||
/// | ||
/// <example> | ||
/// <code> | ||
/// GitConfigUnsetLocal("user.email", "[email protected]"); | ||
/// </code> | ||
/// </example> | ||
/// | ||
/// <param name="context">The context.</param> | ||
/// <param name="repositoryDirectoryPath">Repository path.</param> | ||
/// <param name="key">The configuration key.</param> | ||
/// | ||
/// <returns>Whether the key was unset.</returns> | ||
/// | ||
/// <exception cref="ArgumentNullException"></exception> | ||
/// <exception cref="ArgumentException"></exception> | ||
[CakeMethodAlias] | ||
[CakeAliasCategory("Configuration")] | ||
public static void GitConfigUnsetLocal( | ||
this ICakeContext context, | ||
DirectoryPath repositoryDirectoryPath, | ||
string key) | ||
{ | ||
if (context is null) | ||
{ | ||
throw new ArgumentNullException(nameof(context)); | ||
} | ||
|
||
if (repositoryDirectoryPath is null) | ||
{ | ||
throw new ArgumentException(nameof(repositoryDirectoryPath)); | ||
} | ||
|
||
context.UseRepository(repositoryDirectoryPath, repository => repository.Config.Unset(key)); | ||
} | ||
|
||
/// <summary> | ||
/// Returns whether a configuration value exists with the specifed key. | ||
/// </summary> | ||
/// | ||
/// <example> | ||
/// <code> | ||
/// if (GetConfigurationExists<string>("user.email") | ||
/// { | ||
/// //.. | ||
/// } | ||
/// </code> | ||
/// </example> | ||
/// | ||
/// <param name="context">The context.</param> | ||
/// <param name="repositoryDirectoryPath">Repository path.</param> | ||
/// <param name="key">The configuration key.</param> | ||
/// | ||
/// <typeparam name="T">The expected configuration type.</typeparam> | ||
/// | ||
/// <returns>Whether a configuration exists with the specified key.</returns> | ||
/// | ||
/// <exception cref="ArgumentNullException"></exception> | ||
/// <exception cref="ArgumentException"></exception> | ||
[CakeMethodAlias] | ||
[CakeAliasCategory("Configuration")] | ||
public static bool GitConfigExists<T>(this ICakeContext context, DirectoryPath repositoryDirectoryPath, string key) | ||
{ | ||
if (context is null) | ||
{ | ||
throw new ArgumentNullException(nameof(context)); | ||
} | ||
|
||
if (repositoryDirectoryPath is null) | ||
{ | ||
throw new ArgumentException(nameof(repositoryDirectoryPath)); | ||
} | ||
|
||
return context.UseRepository(repositoryDirectoryPath, repository => repository.Config.Get<T>(key) != null); | ||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -839,6 +839,22 @@ Task("Git-Log-Tag") | |
} | ||
}); | ||
|
||
Task("Git-Config") | ||
.Does(() => | ||
{ | ||
GitConfigSetLocal(testInitalRepo, "user.email", "[email protected]"); | ||
if (GitConfigExists<string>(testInitalRepo, "user.email")) | ||
{ | ||
string email = GitConfigGet<string>(testInitalRepo, "user.email"); | ||
if (!string.Equals("[email protected]", email)) | ||
{ | ||
throw new InvalidOperationException("Wrong email in configuration."); | ||
} | ||
} | ||
}); | ||
|
||
|
||
|
||
Task("Git-Tag") | ||
|
@@ -924,7 +940,8 @@ Task("Default-Tests") | |
.IsDependentOn("Git-AllTags") | ||
.IsDependentOn("Git-AllTags-Annotated") | ||
.IsDependentOn("Git-AllTags-Targets") | ||
.IsDependentOn("Git-Clean"); | ||
.IsDependentOn("Git-Clean") | ||
.IsDependentOn("Git-Config"); | ||
|
||
Task("Local-Tests") | ||
.IsDependentOn("Git-Init") | ||
|
@@ -960,7 +977,8 @@ Task("Local-Tests") | |
.IsDependentOn("Git-AllTags") | ||
.IsDependentOn("Git-AllTags-Annotated") | ||
.IsDependentOn("Git-AllTags-Targets") | ||
.IsDependentOn("Git-Clean"); | ||
.IsDependentOn("Git-Clean") | ||
.IsDependentOn("Git-Config"); | ||
|
||
/////////////////////////////////////////////////////////////////////////////// | ||
// EXECUTION | ||
|