Skip to content
This repository has been archived by the owner on Oct 20, 2018. It is now read-only.

Latest commit

 

History

History
289 lines (265 loc) · 6.6 KB

README.md

File metadata and controls

289 lines (265 loc) · 6.6 KB

octokit-release-asset-upload

Upload files to a GitHub Release from Node and the browser

Build Status Coverage Status Greenkeeper badge

⚠️ currently not working in browser

See #1 for more information.

Usage

See options below. The octokitReleaseAssetUpload method resolves with the response from the GitHub API and an additional .release property which is the release response.

See list of potential errors below.

As Node module

// npm install @gr2m/release-asset-upload
const octokitReleaseAssetUpload = require('@gr2m/release-asset-upload')
const fs = require('fs')

octokitReleaseAssetUpload({
  owner: 'octokit-fixture-org',
  repo: 'release-assets',
  tag: 'v1.0.0',
  username: 'your-username',
  password: 'secret'
  file: fs.createReadStream('example.png'),
  name: 'example.png',
  contentType: 'image/png',
  contentLength: fs.statSync('example.png').size
})

In Browser

<input type="file" id="input">
<script src="octokit-release-asset-upload.min.js"></script>
<script>
octokitReleaseAssetUpload({
  owner: 'octokit-fixture-org',
  repo: 'release-assets',
  tag: 'v1.0.0',
  username: 'your-username',
  password: 'secret'
  file: document.getElementById('input').files[0]
})
</script>

CLI

$ npx octokit-release-asset-upload \
  https://github.com/gr2m/octokit-release-asset-upload/releases/tag/v1.0.0 \
  ./example.png \
  --username="your-username" \
  --password="secret" \

Options

Option Type Description
owner String Required. Name of repository owner (username or organization)
repo String Required. Name of repository
username Object Required unless token is set
password Object Required unless token is set
token Object Required unless username and password are set
file File Required. Node: A file read stream, a String or a Buffer

Browser: a File Object
tag String Name of the tag the release is assigned to, e.g. v1.0.0. Defaults to latest
type String The file media type. Required if file is a Node read stream, a String, or a Buffer. Defaults to mime type of file otherwise.
size Number The size of the file in bytes. Required if file is a Node read stream. Defaults to size of file otherwise.
name String The file name of the asset. Required if file is a Node read stream, a String, or a Buffer. Defaults to name of file otherwise.
label String An alternate short description of the asset. Used in place of the filename on the GitHub release file list UI.
replace Boolean When uploading an asset with an existing `name`, the upload will fail with an `already_exists` error. To replace the existing asset instead in that case, set `replace` to `true`. Defaults to `false`.

Errors

Status Message Description
400 Invalid options See message for more details
401 Credentials missing / Bad credentials Either the past credentials are invalid, or no credentials have been passed.
422 Validation Failed An asset with the passed name already exists. Run with replace: true to overwrite it.

Similar solutions

Contribute

All contributions are welcome ❤️ See CONTRIBUTING.md for more details

LICENSE

MIT