Publishes a file to a repository through the GitHub Contents API
npm install github-publish
Stable, but not feature complete
Currently missing support for deletes.
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 published
- GitHubPublisher(token, username, repo, [branch]) – creates a publisher object with an access token for the GitHub API, the
username
of the owner of the repository to publish to and the name of the repository itself asrepo
.
- retrieve(filename) – returns a
Promise
that resolves with either an object containing thecontent
andsha
of the existing file or withfalse
if no such file exists in the repository - publish(filename, content, [options]) – publishes the specified
content
as thefilename
to therepo
of the publisher object.content
should be either astring
or aBuffer
. Returns aPromise
which resolves to thesha
of the created object on success and tofalse
on 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).
- 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