mirror of
https://github.com/microsoft/autogen.git
synced 2025-10-27 15:59:35 +00:00
check if file exists in repo (#51)
This commit is contained in:
parent
4808f2145a
commit
615db4fdae
@ -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}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user