A Gleam library for using GitHub repositories as backend storage. GitStore provides a simple API to create, read, update, and delete files in GitHub repositories through the GitHub REST API.
📁 File Operations: Create, read, update, and delete files in GitHub repositories
gleam add git_store@1Create a GitHubConfig with your repository details and authentication token:
import git_store
// Using the convenience function (recommended)
let config = git_store.new_config(
owner: "your-username",
repo: "your-repository",
token: "ghp_your-github-token"
)Direct construction
import git_store.{GitHubConfig}
let config = GitHubConfig(
owner: "your-username",
repo: "your-repository",
token: "ghp_your-github-token",
base_url: "https://api.github.com"
)For GitHub Enterprise
import git_store
let config = git_store.new_enterprise_config(
owner: "your-org",
repo: "your-repo",
token: "your-token",
base_url: "https://github.your-company.com/api/v3"
)import git_store
import gleam/io
import gleam/string
pub fn main() -> Nil {
let config = git_store.new_config(
owner: "your-username",
repo: "your-repository",
token: "your-github-token"
)
// Create a new file
case git_store.create_file(config, "hello.txt", "Hello, World!") {
Ok(_) -> io.println("File created successfully")
Error(err) -> io.println("Error: " <> string.inspect(err))
}
// Read a file
case git_store.get_file(config, "hello.txt") {
Ok(response) -> {
case response {
types.GitHubGetFileResponse(content, _, _, _) ->
io.println("File content: " <> content)
_ -> io.println("Unexpected response")
}
}
Error(err) -> io.println("Error: " <> string.inspect(err))
}
// Update a file
case git_store.update_file(config, "hello.txt", "Hello, Updated World!") {
Ok(_) -> io.println("File updated successfully")
Error(err) -> io.println("Error: " <> string.inspect(err))
}
// Delete a file
case git_store.delete_file(config, "hello.txt") {
Ok(_) -> io.println("File deleted successfully")
Error(err) -> io.println("Error: " <> string.inspect(err))
}
}get_file(config, path)- Retrieve a file from the repositorycreate_file(config, filename, content)- Create a new fileupdate_file(config, filename, content)- Update an existing filedelete_file(config, filename)- Delete a file
GitHubConfig(
owner: String, // Repository owner/organization
repo: String, // Repository name
token: String, // GitHub personal access token
base_url: String // GitHub API base URL
)ParsingError(String)- JSON parsing or response format errorsHTTPError(String)- HTTP request failuresNoFileFound(String)- File not found in repositoryGitHubError- General GitHub API errors
GitStore automatically generates commit messages with operation prefixes:
add: filename- For file creationupdate: filename- For file updatesdelete: filename- For file deletion
gleam run # Run the project
gleam test # Run the testsFurther documentation can be found at https://hexdocs.pm/git_store.