Skip to content

A programming framework for agentic AI

check if file exists in repo (#51)

Kosta Petan615db4fdaea0
diff --git a/samples/gh-flow/src/Microsoft.AI.DevTeam/Services/GithubService.cs b/samples/gh-flow/src/Microsoft.AI.DevTeam/Services/GithubService.cs
index e43641e7f..7a1316b9a 100644
--- a/samples/gh-flow/src/Microsoft.AI.DevTeam/Services/GithubService.cs
+++ b/samples/gh-flow/src/Microsoft.AI.DevTeam/Services/GithubService.cs
@@ -51,22 +51,26 @@ public class GithubService : IManageGithub
{
var value = reader.ReadToEnd();
- // Check if the file exists
- var existingFiles = await _ghClient.Repository.Content.GetAllContentsByRef(org, repo, filePath, branch);
- if (existingFiles.Any())
+ try
{
+ // Check if the file exists
+ var existingFiles = await _ghClient.Repository.Content.GetAllContentsByRef(org, repo, filePath, branch);
var existingFile = existingFiles.First();
// If the file exists, update it
var updateChangeSet = await _ghClient.Repository.Content.UpdateFile(
org, repo, filePath,
- new UpdateFileRequest("Updated file via AI", value, existingFile.Sha, branch)); // TODO: add more meaningfull commit message
+ new UpdateFileRequest("Updated file via AI", value, existingFile.Sha, branch)); // TODO: add more meaningful commit message
}
- else
+ catch (NotFoundException)
{
// If the file doesn't exist, create it
var createChangeSet = await _ghClient.Repository.Content.CreateFile(
org, repo, filePath,
- new CreateFileRequest("Created file via AI", value, branch)); // TODO: add more meaningfull commit message
+ new CreateFileRequest("Created file via AI", value, branch)); // TODO: add more meaningful commit message
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, $"Error while uploading file {item.Name}");
}
}
}