MarketAlly.AIPlugin.Extensions/MarketAlly.AIPlugin.Refacto.../Plugins/GitHubStatusPlugin.cs

73 lines
3.0 KiB
C#
Executable File

using MarketAlly.AIPlugin;
using MarketAlly.AIPlugin.Refactoring.Plugins;
namespace MarketAlly.AIPlugin.Refactoring.Plugins;
[AIPlugin("github-status", "Get status of cloned repository including commit info and changes")]
public class GitHubStatusPlugin : IAIPlugin
{
[AIParameter("Local path to the cloned repository", required: true)]
public string RepositoryPath { get; set; } = string.Empty;
[AIParameter("Whether to check for remote updates", required: false)]
public bool CheckRemoteUpdates { get; set; } = true;
public IReadOnlyDictionary<string, Type> SupportedParameters => new Dictionary<string, Type>
{
["repositoryPath"] = typeof(string),
["repositorypath"] = typeof(string),
["checkRemoteUpdates"] = typeof(bool),
["checkremoteupdates"] = typeof(bool)
};
public async Task<AIPluginResult> ExecuteAsync(IReadOnlyDictionary<string, object> parameters)
{
try
{
var repositoryPath = (parameters.ContainsKey("repositoryPath") ? parameters["repositoryPath"] :
parameters.ContainsKey("repositorypath") ? parameters["repositorypath"] : null)?.ToString();
var checkRemoteUpdates = parameters.ContainsKey("checkRemoteUpdates") ? Convert.ToBoolean(parameters["checkRemoteUpdates"]) :
parameters.ContainsKey("checkremoteupdates") ? Convert.ToBoolean(parameters["checkremoteupdates"]) : true;
var gitManager = new SimpleGitManager(repositoryPath);
if (!gitManager.IsGitRepository)
{
var errorStatus = new GitRepositoryStatus
{
IsValid = false,
Error = "Not a valid Git repository",
RepositoryPath = repositoryPath
};
return new AIPluginResult(errorStatus, "Repository status check failed");
}
var status = await gitManager.GetRepositoryStatus();
var cloneManager = new GitHubCloneManager();
var repositoryStatus = new GitRepositoryStatus
{
IsValid = true,
RepositoryPath = repositoryPath,
CurrentBranch = status.CurrentBranch,
LatestCommitSha = status.LatestCommitSha,
LatestCommitMessage = status.LatestCommitMessage,
LatestCommitAuthor = status.LatestCommitAuthor,
LatestCommitDate = status.LatestCommitDate,
IsClean = status.IsClean,
StatusOutput = status.StatusOutput
};
if (checkRemoteUpdates)
{
repositoryStatus.HasRemoteUpdates = await cloneManager.CheckForRemoteUpdatesAsync(repositoryPath);
}
return new AIPluginResult(repositoryStatus, "Repository status retrieved successfully");
}
catch (Exception ex)
{
return new AIPluginResult(ex, "Status check failed");
}
}
}