mirror of
				https://github.com/microsoft/autogen.git
				synced 2025-10-31 01:40:58 +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(); |                                 var value = reader.ReadToEnd(); | ||||||
| 
 | 
 | ||||||
|  |                                 try | ||||||
|  |                                 { | ||||||
|                                     // Check if the file exists |                                     // Check if the file exists | ||||||
|                                     var existingFiles = await _ghClient.Repository.Content.GetAllContentsByRef(org, repo, filePath, branch); |                                     var existingFiles = await _ghClient.Repository.Content.GetAllContentsByRef(org, repo, filePath, branch); | ||||||
|                                 if (existingFiles.Any()) |  | ||||||
|                                 { |  | ||||||
|                                     var existingFile = existingFiles.First(); |                                     var existingFile = existingFiles.First(); | ||||||
|                                     // If the file exists, update it |                                     // If the file exists, update it | ||||||
|                                     var updateChangeSet = await _ghClient.Repository.Content.UpdateFile( |                                     var updateChangeSet = await _ghClient.Repository.Content.UpdateFile( | ||||||
|                                         org, repo, filePath, |                                         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 |                                     // If the file doesn't exist, create it | ||||||
|                                     var createChangeSet = await _ghClient.Repository.Content.CreateFile( |                                     var createChangeSet = await _ghClient.Repository.Content.CreateFile( | ||||||
|                                         org, repo, filePath, |                                         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
	 Kosta Petan
						Kosta Petan