49 lines
1.9 KiB
C#
Executable File
49 lines
1.9 KiB
C#
Executable File
using MarketAlly.AIPlugin;
|
|
using MarketAlly.AIPlugin.Refactoring.Plugins;
|
|
|
|
namespace MarketAlly.AIPlugin.Refactoring.Plugins;
|
|
|
|
[AIPlugin("github-update", "Pull latest changes from remote repository")]
|
|
public class GitHubUpdatePlugin : IAIPlugin
|
|
{
|
|
[AIParameter("Local path to the cloned repository", required: true)]
|
|
public string RepositoryPath { get; set; } = string.Empty;
|
|
|
|
[AIParameter("Whether to force update even if there are local changes", required: false)]
|
|
public bool ForceUpdate { get; set; } = false;
|
|
|
|
public IReadOnlyDictionary<string, Type> SupportedParameters => new Dictionary<string, Type>
|
|
{
|
|
["repositoryPath"] = typeof(string),
|
|
["repositorypath"] = typeof(string),
|
|
["forceUpdate"] = typeof(bool),
|
|
["forceupdate"] = 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 forceUpdate = parameters.ContainsKey("forceUpdate") ? Convert.ToBoolean(parameters["forceUpdate"]) :
|
|
parameters.ContainsKey("forceupdate") ? Convert.ToBoolean(parameters["forceupdate"]) : false;
|
|
|
|
var cloneManager = new GitHubCloneManager();
|
|
var result = await cloneManager.UpdateRepositoryAsync(repositoryPath, forceUpdate);
|
|
|
|
if (result.Success)
|
|
{
|
|
return new AIPluginResult(result, "Repository updated successfully");
|
|
}
|
|
else
|
|
{
|
|
return new AIPluginResult(new Exception(result.Error), "Update operation failed");
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new AIPluginResult(ex, "Update failed");
|
|
}
|
|
}
|
|
} |