A high-level file system utility for GitHub repositories, built on the GitHub OpenAPI client. Supports reading, writing, deleting, listing, and checking file existence via the GitHub Contents API.
- ?? Read file content from a GitHub repository
- ?? Write new files with commit messages and optional branch targeting
- ? Delete files with SHA validation
- ?? List directory contents
- ? Check for file existence
- ?? Built on top of a typed OpenAPI GitHub client
dotnet add package Soenneker.GitHub.FileStorebuilder.Services.AddGitHubFileStoreAsSingleton();This will register all necessary dependencies, including the underlying GitHub OpenAPI client.
?? Note: The GitHub access token must be provided via configuration under the key: GitHub:Token.
public class MyService
{
private readonly IGitHubFileStore _store;
public MyService(IGitHubFileStore store)
{
_store = store;
}
public async Task Run()
{
string content = await _store.Read("owner", "repo", "README.md");
await _store.Create("owner", "repo", "newfile.txt", "Hello world!");
bool exists = await _store.Exists("owner", "repo", "README.md");
var files = await _store.List("owner", "repo", "docs");
await _store.Delete("owner", "repo", "oldfile.txt");
}
}