Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ungoldman/gh-release
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v4.0.4
Choose a base ref
...
head repository: ungoldman/gh-release
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v5.0.0
Choose a head ref
  • 16 commits
  • 5 files changed
  • 4 contributors

Commits on Dec 11, 2020

  1. chore(deps): bump actions/setup-node from v2.1.2 to v2.1.3

    Bumps [actions/setup-node](https://github.com/actions/setup-node) from v2.1.2 to v2.1.3.
    - [Release notes](https://github.com/actions/setup-node/releases)
    - [Commits](actions/setup-node@v2.1.2...27082ce)
    
    Signed-off-by: dependabot[bot] <support@github.com>
    dependabot[bot] authored Dec 11, 2020
    Copy the full SHA
    a9e7840 View commit details
  2. chore(deps-dev): bump sitedown from 4.0.0 to 5.0.0

    Bumps [sitedown](https://github.com/hypermodules/sitedown) from 4.0.0 to 5.0.0.
    - [Release notes](https://github.com/hypermodules/sitedown/releases)
    - [Changelog](https://github.com/hypermodules/sitedown/blob/master/CHANGELOG.md)
    - [Commits](ungoldman/sitedown@v4.0.0...v5.0.0)
    
    Signed-off-by: dependabot[bot] <support@github.com>
    dependabot[bot] authored Dec 11, 2020
    Copy the full SHA
    c28276d View commit details
  3. Merge pull request #119 from hypermodules/dependabot/npm_and_yarn/sit…

    …edown-5.0.0
    
    chore(deps-dev): bump sitedown from 4.0.0 to 5.0.0
    bcomnes authored Dec 11, 2020
    Copy the full SHA
    0001b25 View commit details
  4. Merge pull request #118 from hypermodules/dependabot/github_actions/a…

    …ctions/setup-node-v2.1.3
    
    chore(deps): bump actions/setup-node from v2.1.2 to v2.1.3
    bcomnes authored Dec 11, 2020
    Copy the full SHA
    d4d36cb View commit details

Commits on Jan 16, 2021

  1. Use octokit instead of simple-get

    For some reason, simple-get would just timeout when using gh-release on some orgs.  I thought it was an issue with the device token permissions, but its not.  The GitHub API is weird, and finicky, and IME using octokit, despite its constant churn, is probably the best approach here.  It also generally improves errors that get returned, though most of our error handling I left the same.
    
    I've tested the following scenarios:
    - Normal working scenario
    - Missing tag
    - Bad credentials
    - Asset uploads
    
    Everything still seems to work.
    bcomnes committed Jan 16, 2021
    Copy the full SHA
    949a104 View commit details
  2. Update bin/cli.js

    Co-authored-by: Nate Goldman <ungoldman@gmail.com>
    bcomnes and ungoldman committed Jan 16, 2021
    Copy the full SHA
    d7e8241 View commit details
  3. Copy the full SHA
    33440b3 View commit details
  4. BETA changelog

    bcomnes committed Jan 16, 2021
    Copy the full SHA
    faaf96e View commit details
  5. CHANGELOG

    bcomnes committed Jan 16, 2021
    Copy the full SHA
    a8bfd86 View commit details
  6. 4.0.5-beta.0

    bcomnes committed Jan 16, 2021
    Copy the full SHA
    69545d1 View commit details
  7. Merge pull request #117 from hypermodules/fix-timeouts

    Use octokit instead of simple-get
    bcomnes authored Jan 16, 2021
    Copy the full SHA
    315c638 View commit details
  8. Automerge dependabot actions updates

    This way trivial actions updates just land, and nobody has to do anything
    bcomnes authored Jan 16, 2021
    Copy the full SHA
    16d884d View commit details
  9. Merge pull request #121 from hypermodules/bcomnes-patch-1

    Automerge dependabot actions updates
    bcomnes authored Jan 16, 2021
    Copy the full SHA
    cf5b189 View commit details
  10. chore(deps): bump actions/setup-node from v2.1.3 to v2.1.4 (#120)

    Bumps [actions/setup-node](https://github.com/actions/setup-node) from v2.1.3 to v2.1.4.
    - [Release notes](https://github.com/actions/setup-node/releases)
    - [Commits](actions/setup-node@v2.1.3...c46424e)
    
    Signed-off-by: dependabot[bot] <support@github.com>
    
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored Jan 16, 2021
    Copy the full SHA
    a5b90b0 View commit details
  11. CHANGELOG

    bcomnes committed Jan 16, 2021
    Copy the full SHA
    a1de36e View commit details
  12. 5.0.0

    bcomnes committed Jan 16, 2021
    Copy the full SHA
    04e4fe8 View commit details
Showing with 81 additions and 78 deletions.
  1. +11 −2 .github/workflows/test.yml
  2. +15 −0 CHANGELOG.md
  3. +1 −1 bin/cli.js
  4. +50 −71 index.js
  5. +4 −4 package.json
13 changes: 11 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: tests

on: [push]
on: [push, pull_request]

jobs:
test:
@@ -14,8 +14,17 @@ jobs:
steps:
- uses: actions/checkout@v2.3.4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2.1.2
uses: actions/setup-node@v2.1.4
with:
node-version: ${{ matrix.node-version }}
- run: npm i
- run: npm test

automerge:
needs: test
runs-on: ubuntu-latest
steps:
- uses: fastify/github-action-merge-dependabot@v1.1.1
if: ${{ github.actor == 'dependabot[bot]' && github.event_name == 'pull_request' && contains(github.head_ref, 'dependabot/github_actions') }}
with:
github-token: ${{secrets.github_token}}
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -6,10 +6,25 @@ Project versioning adheres to [Semantic Versioning](http://semver.org/).
Commit convention is based on [Conventional Commits](http://conventionalcommits.org).
Change log format is based on [Keep a Changelog](http://keepachangelog.com/).

## [5.0.0](https://github.com/hypermodules/gh-release/compare/v4.0.5-beta.0...v5.0.0) - 2021-01-16

- A release of 4.0.5-beta.0 as a breaking change
- BREAKING CHANGE: new underlying request library (@octokit/rest) in use to fix edge case where releases would time out.
- No API changes, it should be safe to upgrade, but there is a risk of new bugs. Please update at your convenience.

## [4.0.5-beta.0](https://github.com/hypermodules/gh-release/compare/v4.0.4...v4.0.5-beta.0) - 2020-12-04

- Replace `simple-get` with `@octokit/rest`. This should fix some spurious timeout bugs.
- Republish on correct npm channel.

## [4.0.4](https://github.com/hypermodules/gh-release/compare/v4.0.3...v4.0.4) - 2020-12-04

- Republish of 4.0.3 due to a bad beta version publish on the latest npm tag.

## [4.0.4-beta.0](https://github.com/hypermodules/gh-release/compare/v4.0.3...v4.0.4-beta.0) - 2020-12-04

- Replace `simple-get` with `@octokit/rest`. This should fix some spurious timeout bugs.

## [4.0.3](https://github.com/hypermodules/gh-release/compare/v4.0.2...v4.0.3) - 2020-09-30

- update-notifier version 5.0.0 (drops old node, and bugfixes)
2 changes: 1 addition & 1 deletion bin/cli.js
Original file line number Diff line number Diff line change
@@ -157,7 +157,7 @@ function performRelease (options) {
}

function handleError (err) {
const msg = err.message || JSON.stringify(err)
const msg = err.message || JSON.stringify(err, null, 2)
console.log(chalk.red(msg))
process.exit(1)
}
121 changes: 50 additions & 71 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const extend = require('deep-extend')
const get = require('simple-get')
const format = require('util').format
const path = require('path')
const ghReleaseAssets = require('gh-release-assets')
const getDefaults = require('./bin/lib/get-defaults')
const Emitter = require('events').EventEmitter
const { Octokit } = require('@octokit/rest')

const clientId = '04dac3c40b7e49b11f38'

@@ -81,65 +81,30 @@ function _Release (options, emitter, callback) {
}

// err if auth info not provided (token or user/pass)
if (!getAuth(options)) return callback(new Error('missing auth info'))
if (!getToken(options)) return callback(new Error('missing auth info'))

const commitOptsPath = format('/repos/%s/%s/commits/%s', options.owner, options.repo, options.target_commitish)
const commitOptsUrl = options.endpoint.replace(/\/+$/, '') + commitOptsPath

// check if commit exists on remote
const commitOpts = extend(getAuth(options), {
method: 'GET',
url: commitOptsUrl
const octokit = new Octokit({
auth: getToken(options),
baseUrl: options.endpoint
})

get.concat(commitOpts, function (err, res, body) {
if (err || res.statusCode === 404) {
const errorMessage = format('Target commitish %s not found in %s/%s', options.target_commitish, options.owner, options.repo)
return callback(new Error(errorMessage))
}

const releaseOptsPath = format('/repos/%s/%s/releases', options.owner, options.repo)
const releaseOptsUrl = options.endpoint.replace(/\/+$/, '') + releaseOptsPath

const releaseOpts = extend(getAuth(options), {
url: releaseOptsUrl,
body: {
tag_name: options.tag_name,
target_commitish: options.target_commitish,
name: options.name,
body: options.body,
draft: options.draft,
prerelease: options.prerelease,
repo: options.repo,
owner: options.owner
}
})

octokit.repos.getCommit({
owner: options.owner,
repo: options.repo,
ref: options.target_commitish
}).then(results => {
if (options.dryRun) return callback(null, options)

get.concat(releaseOpts, function (err, res, body) {
if (err) {
return callback(err)
}

if (res.statusCode === 404) {
const authErrorMessage = format('404 Not Found. Review gh-release oAuth Organization access: https://github.com/settings/connections/applications/%s', clientId)
return callback(new Error(authErrorMessage))
}

if (body.errors) {
if (body.errors[0].code !== 'already_exists') {
return callback(body.errors)
}

const errorMessage = format('Release already exists for tag %s in %s/%s', options.tag_name, options.owner, options.repo)
return callback(new Error(errorMessage))
}

if (body.message === 'Bad credentials') {
return callback(new Error('GitHub says password is no bueno. please clear your cache manually. https://github.com/hypermodules/gh-release#config-location'))
}

octokit.repos.createRelease({
tag_name: options.tag_name,
target_commitish: options.target_commitish,
name: options.name,
body: options.body,
draft: options.draft,
prerelease: options.prerelease,
repo: options.repo,
owner: options.owner
}).then(results => {
if (options.assets) {
const assets = options.assets.map(function (asset) {
if (typeof asset === 'object') {
@@ -153,7 +118,7 @@ function _Release (options, emitter, callback) {
})

const assetOptions = {
url: body.upload_url,
url: results.data.upload_url,
assets: assets
}

@@ -165,7 +130,7 @@ function _Release (options, emitter, callback) {

const assetUpload = ghReleaseAssets(assetOptions, function (err) {
if (err) return callback(err)
return callback(null, body)
return callback(null, results.data)
})
assetUpload.on('upload-asset', function (name) {
emitter.emit('upload-asset', name)
@@ -177,9 +142,33 @@ function _Release (options, emitter, callback) {
emitter.emit('uploaded-asset', name)
})
} else {
callback(null, body)
callback(null, results.data)
}
}).catch(err => {
// Create Release error handling
if (err.status === 404) {
const notFoundError = new Error(format('404 Not Found. Review gh-release oAuth Organization access: https://github.com/settings/connections/applications/%s', clientId))
notFoundError.wrapped = err
return callback(notFoundError)
}
if (err.errors) {
if (err.errors[0].code !== 'already_exists') {
return callback(err)
}

const errorMessage = format('Release already exists for tag %s in %s/%s', options.tag_name, options.owner, options.repo)
return callback(new Error(errorMessage))
}
return callback(err)
})
}).catch(err => {
// Check target error handling
if (err.status === 404) {
const errorMessage = format('Target commitish %s not found in %s/%s', options.target_commitish, options.owner, options.repo)
return callback(new Error(errorMessage))
} else {
return callback(err)
}
})
}

@@ -206,24 +195,14 @@ function validate (options) {
}
}

function getAuth (options) {
const defaultRequest = {
method: 'POST',
json: true,
headers: {
'User-Agent': 'gh-release'
}
}

function getToken (options) {
if (options.auth.token) {
defaultRequest.headers.Authorization = 'token ' + options.auth.token
return options.auth.token
} else if (options.auth.username && options.auth.password) {
defaultRequest.auth = options.auth
return options.auth
} else {
return false
}

return defaultRequest
}

Release.OPTIONS = OPTIONS
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "gh-release",
"description": "Create a release for a node package on github.",
"version": "4.0.4",
"version": "5.0.0",
"author": "Nate Goldman <ungoldman@gmail.com> (http://ungoldman.com/)",
"bin": {
"gh-release": "./bin/cli.js"
@@ -21,16 +21,16 @@
"Ted Janeczko <tjaneczko@brightcove.com>"
],
"dependencies": {
"ghauth": "^5.0.0",
"@octokit/rest": "^18.0.9",
"chalk": "^4.1.0",
"changelog-parser": "^2.0.0",
"deep-extend": "^0.6.0",
"gauge": "^v2.7.4",
"gh-release-assets": "^2.0.0",
"ghauth": "^5.0.0",
"github-url-to-object": "^4.0.4",
"inquirer": "^7.3.3",
"shelljs": "^0.8.4",
"simple-get": "^4.0.0",
"update-notifier": "^5.0.0",
"yargs": "^16.0.3"
},
@@ -40,7 +40,7 @@
"live-server": "^1.1.0",
"npm-run-all": "^4.1.5",
"rimraf": "^3.0.2",
"sitedown": "^4.0.0",
"sitedown": "^5.0.0",
"snazzy": "^9.0.0",
"standard": "^16.0.2",
"tap-spec": "^5.0.0",