chore: Add comments to public methods
- rename GetRepo to GetDirectoryForRegisteredRepo so it's actually doing what it says
This commit is contained in:
parent
ba07e1618a
commit
fc3fe217e4
7 changed files with 57 additions and 5 deletions
|
|
@ -33,7 +33,17 @@ public class BuildContext : FrostingContext
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ConvertableFilePath CreateModuleManifestScript { get; set; }
|
public ConvertableFilePath CreateModuleManifestScript { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Suffix to tag the build with, defaults to pre-release.
|
||||||
|
/// <para>
|
||||||
|
/// Immediately follows the version number and before the commit hash.
|
||||||
|
/// </para>
|
||||||
|
/// </summary>
|
||||||
public string BuildSuffix { get; set; }
|
public string BuildSuffix { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Disable the commit hash from being added
|
||||||
|
/// </summary>
|
||||||
public bool DisableCommitHash { get; set; }
|
public bool DisableCommitHash { get; set; }
|
||||||
|
|
||||||
public BuildContext(ICakeContext context)
|
public BuildContext(ICakeContext context)
|
||||||
|
|
@ -45,7 +55,7 @@ public class BuildContext : FrostingContext
|
||||||
PowershellModuleOutputDir = context.Directory("../") + context.Directory("output") + context.Directory("PowershellModule");
|
PowershellModuleOutputDir = context.Directory("../") + context.Directory("output") + context.Directory("PowershellModule");
|
||||||
var buildScriptDirectory = context.Directory("./Scripts");
|
var buildScriptDirectory = context.Directory("./Scripts");
|
||||||
CreateModuleManifestScript = buildScriptDirectory + context.File("CreateModuleManifest.ps1");
|
CreateModuleManifestScript = buildScriptDirectory + context.File("CreateModuleManifest.ps1");
|
||||||
BuildSuffix = context.Configuration.GetValue(nameof(BuildSuffix));
|
BuildSuffix = context.Configuration.GetValue(nameof(BuildSuffix)) ?? "pre-release";
|
||||||
DisableCommitHash = context.Configuration.GetBoolValue(nameof(DisableCommitHash));
|
DisableCommitHash = context.Configuration.GetBoolValue(nameof(DisableCommitHash));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -6,8 +6,14 @@ namespace Build;
|
||||||
|
|
||||||
public class Helpers
|
public class Helpers
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Returns a formatted version of the assembly that contains PowerShell cmdlets
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="powershelModuleOutputLocation"></param>
|
||||||
|
/// <returns></returns>
|
||||||
public static string GetPowershellModuleVersion(string powershelModuleOutputLocation)
|
public static string GetPowershellModuleVersion(string powershelModuleOutputLocation)
|
||||||
{
|
{
|
||||||
|
// When the project name changes, this dll will also need to be updated
|
||||||
var moduleVersionInfo = FileVersionInfo.GetVersionInfo(Path.Combine(powershelModuleOutputLocation, "PowershellModule.dll"));
|
var moduleVersionInfo = FileVersionInfo.GetVersionInfo(Path.Combine(powershelModuleOutputLocation, "PowershellModule.dll"));
|
||||||
|
|
||||||
// It's (almost) impossible to not have a product version tag here. There is a reason why the implementation
|
// It's (almost) impossible to not have a product version tag here. There is a reason why the implementation
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,6 @@ public static class Program
|
||||||
{
|
{
|
||||||
return new CakeHost()
|
return new CakeHost()
|
||||||
.UseContext<BuildContext>()
|
.UseContext<BuildContext>()
|
||||||
// Uncomment this if you don't want to set the suffix via the run profile program arguments
|
|
||||||
.UseCakeSetting(nameof(BuildContext.BuildSuffix), "pre-release")
|
|
||||||
.Run(args);
|
.Run(args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -26,12 +26,22 @@ public class DatabaseManager
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Runs the given action within a new database connection
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="dbAction"></param>
|
||||||
public void InConnection(Action<SQLiteConnection> dbAction)
|
public void InConnection(Action<SQLiteConnection> dbAction)
|
||||||
{
|
{
|
||||||
using var conn = new SQLiteConnection(_databaseLocation.FullName);
|
using var conn = new SQLiteConnection(_databaseLocation.FullName);
|
||||||
dbAction(conn);
|
dbAction(conn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Runs the given func in a new database connection, returning the result
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="dbAction"></param>
|
||||||
|
/// <typeparam name="T"></typeparam>
|
||||||
|
/// <returns></returns>
|
||||||
public T InConnection<T>(Func<SQLiteConnection, T> dbAction)
|
public T InConnection<T>(Func<SQLiteConnection, T> dbAction)
|
||||||
{
|
{
|
||||||
using var conn = new SQLiteConnection(_databaseLocation.FullName);
|
using var conn = new SQLiteConnection(_databaseLocation.FullName);
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,10 @@ public class GitManager
|
||||||
InitialiseRegistrations();
|
InitialiseRegistrations();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the current <see cref="GitManager"/> instance. If no instance has been created, returns a new instance
|
||||||
|
/// and then the same instance every call after.
|
||||||
|
/// </summary>
|
||||||
public static GitManager Instance => GitManagerInstance.Value;
|
public static GitManager Instance => GitManagerInstance.Value;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -128,6 +132,11 @@ public class GitManager
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Unregisters a git repo registration by name. If no registration exists an exception will be thrown.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="registrationName"></param>
|
||||||
|
/// <exception cref="Exception"></exception>
|
||||||
public void UnregisterRepo(string registrationName)
|
public void UnregisterRepo(string registrationName)
|
||||||
{
|
{
|
||||||
_db.InConnection(conn =>
|
_db.InConnection(conn =>
|
||||||
|
|
@ -195,7 +204,13 @@ public class GitManager
|
||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetRepo(string? registeredName)
|
/// <summary>
|
||||||
|
/// Returns the file location for a git repo registration by name.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="registeredName"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
/// <exception cref="Exception"></exception>
|
||||||
|
public string GetDirectoryForRegisteredRepo(string? registeredName)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(registeredName))
|
if (string.IsNullOrEmpty(registeredName))
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,21 @@
|
||||||
namespace ModuleCore.Git.Models;
|
namespace ModuleCore.Git.Models;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Details for a registered git repo
|
||||||
|
/// </summary>
|
||||||
public class GitRegistration
|
public class GitRegistration
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Display name for the registration. Can either be the name of the repo retrieved from git, or a user supplied
|
||||||
|
/// alias
|
||||||
|
/// </summary>
|
||||||
public required string Name { get; set; }
|
public required string Name { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Location on disk for the top level of the registered git repo. Not guaranteed to exist on disk
|
||||||
|
/// </summary>
|
||||||
public required string Location { get; set; }
|
public required string Location { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Current branch for the git repo
|
||||||
|
/// </summary>
|
||||||
public required string CurrentBranch { get; set; }
|
public required string CurrentBranch { get; set; }
|
||||||
}
|
}
|
||||||
|
|
@ -21,7 +21,7 @@ public class ShowGitRepoRegistrationCommand : PSCmdlet
|
||||||
|
|
||||||
protected override void BeginProcessing()
|
protected override void BeginProcessing()
|
||||||
{
|
{
|
||||||
var location = GitManager.Instance.GetRepo(Name);
|
var location = GitManager.Instance.GetDirectoryForRegisteredRepo(Name);
|
||||||
|
|
||||||
// By default instead of doing the same as cd, we instead do pushd so a user can popd straight back to where
|
// By default instead of doing the same as cd, we instead do pushd so a user can popd straight back to where
|
||||||
// they came from.
|
// they came from.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue