6.0.0 • Published 1 year ago
github-publish v6.0.0
GitHub Publish
Publishes a file to a repository through the GitHub Contents API
Installation
NPM
npm install github-publishCurrent status
Stable, but not feature complete
Currently missing support for deletes.
Usage
import { GitHubPublisher } from 'github-publish';
const publisher = new GitHubPublisher('token123', 'voxpelli', 'voxpelli.github.com');
const result = await publisher.publish('_post/2015-07-17-example-post.md', 'file content');
// If "result" is truthy then the post was successfully publishedClasses
- GitHubPublisher(token, username, repo, branch) – creates a publisher object with an access token for the GitHub API, the
usernameof the owner of the repository to publish to and the name of the repository itself asrepo.
GitHubPublisher methods
- retrieve(filename) – returns a
Promisethat resolves with either an object containing thecontentandshaof the existing file or withfalseif no such file exists in the repository - publish(filename, content, options) – publishes the specified
contentas thefilenameto therepoof the publisher object.contentshould be either astringor aBuffer. Returns aPromisewhich resolves to theshaof the created object on success and tofalseon failure (failure is likely caused by a collision with a pre-existing file, as long as one haven't specified that it should be overridden).
publish() options
- force – whether to replace any pre-existing file no matter what
- message – a custom commit message. Default is
new content - sha – the sha of an existing file that one wants to replace