Public Access
Make agent file writes append by default
PR and Push Build/Test / build-and-test (push) Failing after 6m36s
PR and Push Build/Test / build-and-test (push) Failing after 6m36s
This commit is contained in:
@@ -51,7 +51,7 @@ public sealed class WorkflowRulesEditorTools
|
||||
return ReadLines(await File.ReadAllTextAsync(rulesPath), from, to);
|
||||
}
|
||||
|
||||
public async Task<string> WriteRules(string yaml)
|
||||
public async Task<string> WriteRules(string yaml, bool replace_file = false)
|
||||
{
|
||||
if (rulesPath is null)
|
||||
{
|
||||
@@ -63,14 +63,20 @@ public sealed class WorkflowRulesEditorTools
|
||||
return "Refused: yaml must not be null.";
|
||||
}
|
||||
|
||||
var validation = ValidateYaml(yaml);
|
||||
var existing = File.Exists(rulesPath)
|
||||
? await File.ReadAllTextAsync(rulesPath)
|
||||
: "";
|
||||
var updated = replace_file
|
||||
? yaml
|
||||
: AppendContent(existing, yaml);
|
||||
var validation = ValidateYaml(updated);
|
||||
if (validation is not null)
|
||||
{
|
||||
return validation;
|
||||
}
|
||||
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(rulesPath)!);
|
||||
await File.WriteAllTextAsync(rulesPath, yaml);
|
||||
await File.WriteAllTextAsync(rulesPath, updated);
|
||||
return rulesPath;
|
||||
}
|
||||
|
||||
@@ -359,6 +365,24 @@ public sealed class WorkflowRulesEditorTools
|
||||
}
|
||||
}
|
||||
|
||||
private static string AppendContent(string existingContent, string content)
|
||||
{
|
||||
if (string.IsNullOrEmpty(existingContent))
|
||||
{
|
||||
return content;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(content))
|
||||
{
|
||||
return existingContent;
|
||||
}
|
||||
|
||||
var separator = existingContent.EndsWith('\n') || existingContent.EndsWith('\r')
|
||||
? ""
|
||||
: "\n";
|
||||
return existingContent + separator + content;
|
||||
}
|
||||
|
||||
private static async Task<string?> RunRipgrepAsync(string rulesPath, string keywords)
|
||||
{
|
||||
try
|
||||
|
||||
Reference in New Issue
Block a user