@benjifs/github-store
v0.2.0
Published
Interact with a GitHub repository using the GitHub contents API
Downloads
121
Readme
GitHub Store
This project was designed to work with @benjifs/micropub but it should be usable with other projects that need to interact with the GitHub Contents API.
There is also a compatible version to work with a GitLab repository: @benjifs/gitlab-store.
Install
npm install @benjifs/github-store
Setup
You need one of the following tokens to work with the contents API:
- Personal access token (classic) with the
reposcope selected. - Fine-grained personal access token for the repository you want access
to with
Read and writeaccess to Contents andReadaccess to Metadata.
Usage
import GitHubStore from '@benjifs/github-store'
const {
GITHUB_TOKEN,
GITHUB_USER,
GITHUB_REPO,
} = process.env
const store = new GitHubStore({
token: GITHUB_TOKEN, // required
user: GITHUB_USER, // required
repo: GITHUB_REPO, // required
// branch: 'main', // default: default branch for repo
// committer: { // default: the authenticated user
// name: 'committer name',
// email: '[email protected]'
// },
})
// ...
const uploaded = await store.createFile('src/example.txt', 'this is a test')