diff --git a/AddActionsWorkflow/AddActionsWorkflow.csproj b/AddActionsWorkflow/AddActionsWorkflow.csproj
index 229f0da..4e875ff 100644
--- a/AddActionsWorkflow/AddActionsWorkflow.csproj
+++ b/AddActionsWorkflow/AddActionsWorkflow.csproj
@@ -91,16 +91,22 @@
- 3.5.0
+ 3.6.4
+
+
+ 17.0.507
-
+
+ 0.27.2
+
+
+ 2.0.320
+
+
runtime; build; native; contentfiles; analyzers; buildtransitive
all
-
- compile; build; native; contentfiles; analyzers; buildtransitive
-
diff --git a/AddActionsWorkflow/AddActionsWorkflowPackage.cs b/AddActionsWorkflow/AddActionsWorkflowPackage.cs
index ec72d07..4906883 100644
--- a/AddActionsWorkflow/AddActionsWorkflowPackage.cs
+++ b/AddActionsWorkflow/AddActionsWorkflowPackage.cs
@@ -14,6 +14,7 @@ namespace AddActionsWorkflow;
[Guid(PackageGuids.AddActionsWorkflowString)]
[ProvideOptionPage(typeof(OptionsProvider.GeneralOptions), "GitHub Actions Workflow", "General", 0, 0, true)]
[ProvideProfile(typeof(OptionsProvider.GeneralOptions), "GitHub Actions Workflow", "General", 0, 0, true)]
+[ProvideBindingPath]
public sealed class AddActionsWorkflowPackage : ToolkitPackage
{
protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress progress)
diff --git a/AddActionsWorkflow/Commands/AddWorkflowCommand.cs b/AddActionsWorkflow/Commands/AddWorkflowCommand.cs
index 617b39b..bea720d 100644
--- a/AddActionsWorkflow/Commands/AddWorkflowCommand.cs
+++ b/AddActionsWorkflow/Commands/AddWorkflowCommand.cs
@@ -1,6 +1,6 @@
using AddActionsWorkflow.Options;
using CliWrap;
-using Microsoft;
+using LibGit2Sharp;
using System.Diagnostics;
using System.IO;
using System.Text;
@@ -11,7 +11,7 @@ namespace AddActionsWorkflow;
[Command(PackageIds.AddWorkflowCommand)]
internal sealed class AddWorkflowCommand : BaseCommand
{
- string finaleWorkflowname = "";
+ string finaleWorkflowname = string.Empty;
string branchName = "main";
protected override async Task ExecuteAsync(OleMenuCmdEventArgs e)
@@ -23,7 +23,7 @@ protected override async Task ExecuteAsync(OleMenuCmdEventArgs e)
var options = await General.GetLiveInstanceAsync();
// try to get the repo root
- string repoRoot = await GetGitRootDirAsync(slnDir, options.UseCurrentBranchName);
+ string repoRoot = await GetGitRootDirAsync(dirInfo.FullName, options.UseCurrentBranchName);
var workflowCreated = await CreateWorkflowTemplateAsync(repoRoot, options);
if (workflowCreated)
@@ -88,50 +88,25 @@ internal async Task GetGitRootDirAsync(string workingDirectory, bool use
{
await VS.StatusBar.ShowMessageAsync("Establishing git root directory...");
var rootGitDir = workingDirectory;
- var stdOutBuffer = new StringBuilder();
- var stdErrBuffer = new StringBuilder();
- var result = await Cli.Wrap("git")
- .WithArguments("rev-parse --show-toplevel")
- .WithWorkingDirectory(workingDirectory)
- .WithStandardOutputPipe(PipeTarget.ToStringBuilder(stdOutBuffer))
- .WithStandardErrorPipe(PipeTarget.ToStringBuilder(stdErrBuffer))
- .WithValidation(CommandResultValidation.None)
- .ExecuteAsync();
-
- var stdOut = stdOutBuffer.ToString();
- var stdErr = stdErrBuffer.ToString();
-
- if (result.ExitCode == 0)
+ while (!Directory.Exists(Path.Combine(rootGitDir, ".git")))
{
- rootGitDir = stdOut;
- rootGitDir = rootGitDir.Replace('/', '\\').Replace("\n", "");
-
- if (useCurrentBranch) await GetCurrentBranchNameAsync(workingDirectory);
+ rootGitDir = Path.GetFullPath(Path.Combine(rootGitDir, ".."));
}
- return rootGitDir;
- }
-
- internal async Task GetCurrentBranchNameAsync(string workingDirectory)
- {
- var stdOutBuffer = new StringBuilder();
- var stdErrBuffer = new StringBuilder();
-
- var result = await Cli.Wrap("git")
- .WithArguments("branch --show-current")
- .WithWorkingDirectory(workingDirectory)
- .WithStandardOutputPipe(PipeTarget.ToStringBuilder(stdOutBuffer))
- .WithStandardErrorPipe(PipeTarget.ToStringBuilder(stdErrBuffer))
- .WithValidation(CommandResultValidation.None)
- .ExecuteAsync();
-
- var stdOut = stdOutBuffer.ToString();
- var stdErr = stdErrBuffer.ToString();
-
- if (result.ExitCode == 0)
+ try
+ {
+ using (var repo = new Repository(rootGitDir))
+ {
+ if (useCurrentBranch) branchName = repo.Head.FriendlyName;
+ rootGitDir = repo.Info.WorkingDirectory;
+ }
+ }
+ catch (Exception ex)
{
- branchName = stdOut;
+ Debug.WriteLine(ex.Message);
}
+
+ return rootGitDir;
}
}
diff --git a/AddActionsWorkflow/Commands/LaunchRemoteUrlCommand.cs b/AddActionsWorkflow/Commands/LaunchRemoteUrlCommand.cs
index dd92c1b..de68d3b 100644
--- a/AddActionsWorkflow/Commands/LaunchRemoteUrlCommand.cs
+++ b/AddActionsWorkflow/Commands/LaunchRemoteUrlCommand.cs
@@ -1,12 +1,8 @@
-using AddActionsWorkflow.Options;
-using CliWrap;
-using System;
-using System.Collections.Generic;
+using LibGit2Sharp;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
-using System.Threading.Tasks;
namespace AddActionsWorkflow.Commands;
@@ -17,29 +13,31 @@ protected override async Task ExecuteAsync(OleMenuCmdEventArgs e)
{
// get the repo URI
var dirInfo = new DirectoryInfo((await VS.Solutions.GetCurrentSolutionAsync()).FullPath);
- var slnDir = dirInfo.Parent.FullName;
+
+ string path = dirInfo.FullName;
+
+ while (!Directory.Exists(Path.Combine(path, ".git")))
+ {
+ path = Path.GetFullPath(Path.Combine(path, ".."));
+ }
var stdOutBuffer = new StringBuilder();
var stdErrBuffer = new StringBuilder();
+ var remoteUri = string.Empty;
- var result = await Cli.Wrap("git")
- .WithArguments("remote get-url origin --push")
- .WithWorkingDirectory(slnDir)
- .WithStandardOutputPipe(PipeTarget.ToStringBuilder(stdOutBuffer))
- .WithStandardErrorPipe(PipeTarget.ToStringBuilder(stdErrBuffer))
- .WithValidation(CommandResultValidation.None)
- .ExecuteAsync();
-
- var stdOut = stdOutBuffer.ToString();
- var stdErr = stdErrBuffer.ToString();
-
- if (result.ExitCode == 0)
+ try
{
- _ = Process.Start(stdOut);
- }
- else
+ using (var repo = new Repository(path))
+ {
+ var headRemote = repo.Head.RemoteName;
+ var remote = repo.Network.Remotes.FirstOrDefault(r => r.Name == headRemote);
+ remoteUri = remote.Url;
+ }
+ _ = Process.Start(remoteUri);
+ }
+ catch (Exception ex)
{
- var argError = new UriFormatException(stdErr);
+ var argError = new UriFormatException(ex.Message);
await argError.LogAsync();
}
}
diff --git a/AddActionsWorkflow/Properties/AssemblyInfo.cs b/AddActionsWorkflow/Properties/AssemblyInfo.cs
index 5b0917f..a039274 100644
--- a/AddActionsWorkflow/Properties/AssemblyInfo.cs
+++ b/AddActionsWorkflow/Properties/AssemblyInfo.cs
@@ -15,6 +15,7 @@
[assembly: AssemblyVersion(Vsix.Version)]
[assembly: AssemblyFileVersion(Vsix.Version)]
+[assembly: ProvideCodeBase(CodeBase = @"$PackageFolder$\LibGit2Sharp.dll")]
namespace System.Runtime.CompilerServices
{
diff --git a/AddActionsWorkflow/source.extension.cs b/AddActionsWorkflow/source.extension.cs
index 946f905..bc06a8b 100644
--- a/AddActionsWorkflow/source.extension.cs
+++ b/AddActionsWorkflow/source.extension.cs
@@ -11,7 +11,7 @@ internal sealed partial class Vsix
public const string Name = "Add Actions Workflow";
public const string Description = @"Adds a GitHub Actions workflow to the solution";
public const string Language = "en-US";
- public const string Version = "1.0.0";
+ public const string Version = "1.0.1";
public const string Author = "Tim Heuer";
public const string Tags = "github, actions, devops, workflow";
}
diff --git a/AddActionsWorkflow/source.extension.vsixmanifest b/AddActionsWorkflow/source.extension.vsixmanifest
index 47af382..ad63b32 100644
--- a/AddActionsWorkflow/source.extension.vsixmanifest
+++ b/AddActionsWorkflow/source.extension.vsixmanifest
@@ -1,25 +1,25 @@
-
-
- Add Actions Workflow
- Adds a GitHub Actions workflow to the solution
- https://github.com/timheuer/AddActionsWorkflow
- LICENSE.txt
- https://github.com/timheuer/AddActionsWorkflow
- Resources\Icon.png
- Resources\Icon.png
- github, actions, devops, workflow
-
-
-
-
-
-
-
-
-
-
+
+
+ Add Actions Workflow
+ Adds a GitHub Actions workflow to the solution
+ https://github.com/timheuer/AddActionsWorkflow
+ LICENSE.txt
+ https://github.com/timheuer/AddActionsWorkflow
+ Resources\Icon.png
+ Resources\Icon.png
+ github, actions, devops, workflow
+
+
+
+
+
+
+
+
+
+