github-release-cli
Advanced tools
+216
-179
@@ -15,2 +15,6 @@ 'use strict'; | ||
| var _toArray2 = require('babel-runtime/helpers/toArray'); | ||
| var _toArray3 = _interopRequireDefault(_toArray2); | ||
| var _path = require('path'); | ||
@@ -28,2 +32,6 @@ | ||
| var _minimatch = require('minimatch'); | ||
| var _minimatch2 = _interopRequireDefault(_minimatch); | ||
| var _package = require('../package.json'); | ||
@@ -35,6 +43,12 @@ | ||
| /* eslint no-console: 0 */ | ||
| _commander2.default.version(_package2.default.version).usage('<command> [<args>]').option('-T, --token <token>', 'OAuth2 token').option('-o, --owner <owner>', 'owner').option('-r, --repo <repo>', 'repo').option('-t, --tag <tag>', 'tag').option('-n, --name <name>', 'name').option('-b, --body <body>', 'body', false); /* eslint no-console: 0 */ | ||
| /* eslint max-len: 0 */ | ||
| _commander2.default.version(_package2.default.version).option('-T, --token <token>', 'OAuth2 token').option('-o, --owner <owner>', 'owner').option('-r, --repo <repo>', 'repo').option('-t, --tag <tag>', 'tag').option('-n, --name <name>', 'name').option('-b, --body <body>', 'body', false).parse(process.argv); | ||
| _commander2.default.parse(process.argv); | ||
| var _program$args = (0, _toArray3.default)(_commander2.default.args), | ||
| command = _program$args[0], | ||
| args = _program$args.slice(1); | ||
| var github = new _github2.default({ | ||
@@ -47,3 +61,2 @@ version: '3.0.0', | ||
| }); | ||
| var files = _commander2.default.args; | ||
@@ -103,221 +116,245 @@ github.authenticate({ | ||
| var main = function () { | ||
| var _ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee() { | ||
| var owner, repo, tag, name, body, release, releaseOptions, assets, i, asset, _i, file; | ||
| var fn = { | ||
| 'upload': function () { | ||
| var _ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee() { | ||
| var owner, repo, tag, name, body, files, release, releaseOptions, i, file; | ||
| return _regenerator2.default.wrap(function _callee$(_context) { | ||
| while (1) { | ||
| switch (_context.prev = _context.next) { | ||
| case 0: | ||
| owner = _commander2.default.owner, repo = _commander2.default.repo, tag = _commander2.default.tag, name = _commander2.default.name, body = _commander2.default.body; | ||
| files = args; | ||
| release = void 0; | ||
| _context.prev = 3; | ||
| return _regenerator2.default.wrap(function _callee$(_context) { | ||
| while (1) { | ||
| switch (_context.prev = _context.next) { | ||
| case 0: | ||
| owner = _commander2.default.owner, repo = _commander2.default.repo, tag = _commander2.default.tag, name = _commander2.default.name, body = _commander2.default.body; | ||
| _context.prev = 1; | ||
| console.log('> releases#getReleaseByTag'); | ||
| _context.next = 7; | ||
| return getReleaseByTag({ | ||
| owner: owner, | ||
| repo: repo, | ||
| tag: tag | ||
| }); | ||
| console.log('> releases#getReleaseByTag'); | ||
| _context.next = 5; | ||
| return getReleaseByTag({ | ||
| owner: owner, | ||
| repo: repo, | ||
| tag: tag | ||
| }); | ||
| case 7: | ||
| release = _context.sent; | ||
| _context.next = 12; | ||
| break; | ||
| case 5: | ||
| release = _context.sent; | ||
| case 10: | ||
| _context.prev = 10; | ||
| _context.t0 = _context['catch'](3); | ||
| if (release) { | ||
| _context.next = 14; | ||
| break; | ||
| } | ||
| case 12: | ||
| _context.prev = 12; | ||
| console.log('> releases#createRelease'); | ||
| _context.next = 10; | ||
| return createRelease({ | ||
| owner: owner, | ||
| repo: repo, | ||
| tag_name: tag, | ||
| name: name || tag, | ||
| body: body || '' | ||
| }); | ||
| if (release) { | ||
| _context.next = 20; | ||
| break; | ||
| } | ||
| case 10: | ||
| release = _context.sent; | ||
| console.log('> releases#createRelease'); | ||
| _context.next = 17; | ||
| return createRelease({ | ||
| owner: owner, | ||
| repo: repo, | ||
| tag_name: tag, | ||
| name: name || tag, | ||
| body: body || '' | ||
| }); | ||
| console.log('ok', release); | ||
| _context.next = 22; | ||
| break; | ||
| case 14: | ||
| if (!(release.body !== body)) { | ||
| _context.next = 22; | ||
| case 17: | ||
| release = _context.sent; | ||
| _context.next = 26; | ||
| break; | ||
| } | ||
| console.log('> releases#editRelease'); | ||
| releaseOptions = { | ||
| owner: owner, | ||
| repo: repo, | ||
| id: release.id, | ||
| tag_name: tag, | ||
| name: name || tag | ||
| }; | ||
| case 20: | ||
| if (!(body && release.body !== body)) { | ||
| _context.next = 26; | ||
| break; | ||
| } | ||
| if (body) { | ||
| releaseOptions.body = body || ''; | ||
| } | ||
| _context.next = 20; | ||
| return editRelease(releaseOptions); | ||
| console.log('> releases#editRelease'); | ||
| releaseOptions = { | ||
| owner: owner, | ||
| repo: repo, | ||
| id: release.id, | ||
| tag_name: tag, | ||
| name: name || tag, | ||
| body: body || '' | ||
| }; | ||
| _context.next = 25; | ||
| return editRelease(releaseOptions); | ||
| case 20: | ||
| release = _context.sent; | ||
| case 25: | ||
| release = _context.sent; | ||
| console.log('ok', release); | ||
| case 26: | ||
| if (!(files.length > 0)) { | ||
| _context.next = 37; | ||
| break; | ||
| } | ||
| case 22: | ||
| console.log('> releases#uploadAsset'); | ||
| i = 0; | ||
| console.log('> releases#getAssets'); | ||
| _context.next = 25; | ||
| return getAssets({ | ||
| owner: owner, | ||
| repo: repo, | ||
| id: release.id | ||
| }); | ||
| case 29: | ||
| if (!(i < files.length)) { | ||
| _context.next = 37; | ||
| break; | ||
| } | ||
| case 25: | ||
| assets = _context.sent; | ||
| file = files[i]; | ||
| console.log('assets=%d', assets.length); | ||
| console.log('#%d name="%s" filePath="%s"', i + 1, _path2.default.basename(file), file); | ||
| _context.next = 34; | ||
| return uploadAsset({ | ||
| owner: owner, | ||
| repo: repo, | ||
| id: release.id, | ||
| filePath: file, | ||
| name: _path2.default.basename(file) | ||
| }); | ||
| assets = assets.filter(function (asset) { | ||
| // Example: | ||
| // 'cnc-1.1.0-latest-08c256a-linux-x64.tar.gz' | ||
| // ["cnc-1.1.0-latest-08c256a-linux-x64.tar.gz", "cnc", "1.1.0-latest-08c256a", "linux", "x64", "tar.gz"] | ||
| var pattern = new RegExp(/([a-zA-Z0-9][a-zA-Z0-9\-]*)\-(\d+\.\d+\.\d+(?:\-[a-zA-Z0-9][a-zA-Z0-9\-]*)?)(?:\-(mac|win|linux|tinyweb))(?:(?:\-([a-zA-Z0-9_\-]+))?\.(.*))/); | ||
| case 34: | ||
| ++i; | ||
| _context.next = 29; | ||
| break; | ||
| return files.some(function (file) { | ||
| var r1 = asset.name.match(pattern); | ||
| var r2 = _path2.default.basename(file).match(pattern); | ||
| case 37: | ||
| _context.next = 42; | ||
| break; | ||
| if (r1 === null || r2 === null) { | ||
| console.error('Unable to match file: asset="%s", file="%s"', asset.name, _path2.default.basename(file)); | ||
| return false; | ||
| } | ||
| case 39: | ||
| _context.prev = 39; | ||
| _context.t1 = _context['catch'](12); | ||
| // 0: full | ||
| // 1: name | ||
| // 2: version | ||
| // 3: platform | ||
| // 4: arch | ||
| // 5: extname | ||
| console.error(_context.t1); | ||
| // Skip checking for #0 (full) and #2 (version) | ||
| r1[0] = r1[2] = undefined; | ||
| r2[0] = r2[2] = undefined; | ||
| case 42: | ||
| case 'end': | ||
| return _context.stop(); | ||
| } | ||
| } | ||
| }, _callee, undefined, [[3, 10], [12, 39]]); | ||
| })); | ||
| // compact | ||
| r1 = r1.filter(function (r) { | ||
| return r !== undefined && r !== null; | ||
| }); | ||
| r2 = r2.filter(function (r) { | ||
| return r !== undefined && r !== null; | ||
| }); | ||
| return function upload() { | ||
| return _ref.apply(this, arguments); | ||
| }; | ||
| }(), | ||
| 'delete': function () { | ||
| var _ref2 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee2() { | ||
| var owner, repo, tag, name, body, patterns, release, assets, deleteAssets, i, asset; | ||
| return _regenerator2.default.wrap(function _callee2$(_context2) { | ||
| while (1) { | ||
| switch (_context2.prev = _context2.next) { | ||
| case 0: | ||
| owner = _commander2.default.owner, repo = _commander2.default.repo, tag = _commander2.default.tag, name = _commander2.default.name, body = _commander2.default.body; | ||
| patterns = args; | ||
| release = void 0; | ||
| _context2.prev = 3; | ||
| // compare two arrays | ||
| return r1.length === r2.length && r1.every(function (v, i) { | ||
| return v === r2[i]; | ||
| }); | ||
| console.log('> releases#getReleaseByTag'); | ||
| _context2.next = 7; | ||
| return getReleaseByTag({ | ||
| owner: owner, | ||
| repo: repo, | ||
| tag: tag | ||
| }); | ||
| }); | ||
| if (!(assets.length > 0)) { | ||
| _context.next = 39; | ||
| case 7: | ||
| release = _context2.sent; | ||
| _context2.next = 14; | ||
| break; | ||
| } | ||
| console.log('> releases#deleteAsset'); | ||
| i = 0; | ||
| case 10: | ||
| _context2.prev = 10; | ||
| _context2.t0 = _context2['catch'](3); | ||
| case 31: | ||
| if (!(i < assets.length)) { | ||
| _context.next = 39; | ||
| break; | ||
| } | ||
| console.error(_context2.t0); | ||
| return _context2.abrupt('return'); | ||
| asset = assets[i]; | ||
| case 14: | ||
| _context2.prev = 14; | ||
| console.log('#%d', i + 1, { | ||
| id: asset.id, | ||
| name: asset.name, | ||
| label: asset.label, | ||
| state: asset.state, | ||
| size: asset.size, | ||
| download_count: asset.download_count, | ||
| created_at: asset.created_at, | ||
| updated_at: asset.updated_at | ||
| }); | ||
| _context.next = 36; | ||
| return deleteAsset({ | ||
| owner: owner, | ||
| repo: repo, | ||
| id: asset.id | ||
| }); | ||
| console.log('> releases#getAssets'); | ||
| _context2.next = 18; | ||
| return getAssets({ | ||
| owner: owner, | ||
| repo: repo, | ||
| id: release.id | ||
| }); | ||
| case 36: | ||
| ++i; | ||
| _context.next = 31; | ||
| break; | ||
| case 18: | ||
| assets = _context2.sent; | ||
| deleteAssets = assets.filter(function (asset) { | ||
| return patterns.some(function (pattern) { | ||
| return (0, _minimatch2.default)(asset.name, pattern); | ||
| }); | ||
| }); | ||
| case 39: | ||
| if (!(files.length > 0)) { | ||
| _context.next = 50; | ||
| break; | ||
| } | ||
| console.log('assets=%d, deleteAssets=%d', assets.length, deleteAssets.length); | ||
| console.log('> releases#uploadAsset'); | ||
| _i = 0; | ||
| if (!(deleteAssets.length > 0)) { | ||
| _context2.next = 32; | ||
| break; | ||
| } | ||
| case 42: | ||
| if (!(_i < files.length)) { | ||
| _context.next = 50; | ||
| break; | ||
| } | ||
| console.log('> releases#deleteAsset'); | ||
| i = 0; | ||
| file = files[_i]; | ||
| case 24: | ||
| if (!(i < deleteAssets.length)) { | ||
| _context2.next = 32; | ||
| break; | ||
| } | ||
| console.log('#%d name="%s" filePath="%s"', _i + 1, _path2.default.basename(file), file); | ||
| _context.next = 47; | ||
| return uploadAsset({ | ||
| owner: owner, | ||
| repo: repo, | ||
| id: release.id, | ||
| filePath: file, | ||
| name: _path2.default.basename(file) | ||
| }); | ||
| asset = deleteAssets[i]; | ||
| case 47: | ||
| ++_i; | ||
| _context.next = 42; | ||
| break; | ||
| console.log('#%d', i + 1, { | ||
| id: asset.id, | ||
| name: asset.name, | ||
| label: asset.label, | ||
| state: asset.state, | ||
| size: asset.size, | ||
| download_count: asset.download_count, | ||
| created_at: asset.created_at, | ||
| updated_at: asset.updated_at | ||
| }); | ||
| _context2.next = 29; | ||
| return deleteAsset({ | ||
| owner: owner, | ||
| repo: repo, | ||
| id: asset.id | ||
| }); | ||
| case 50: | ||
| _context.next = 55; | ||
| break; | ||
| case 29: | ||
| ++i; | ||
| _context2.next = 24; | ||
| break; | ||
| case 52: | ||
| _context.prev = 52; | ||
| _context.t0 = _context['catch'](1); | ||
| case 32: | ||
| _context2.next = 37; | ||
| break; | ||
| console.error(_context.t0); | ||
| case 34: | ||
| _context2.prev = 34; | ||
| _context2.t1 = _context2['catch'](14); | ||
| case 55: | ||
| case 'end': | ||
| return _context.stop(); | ||
| console.error(_context2.t1); | ||
| case 37: | ||
| case 'end': | ||
| return _context2.stop(); | ||
| } | ||
| } | ||
| } | ||
| }, _callee, undefined, [[1, 52]]); | ||
| })); | ||
| }, _callee2, undefined, [[3, 10], [14, 34]]); | ||
| })); | ||
| return function main() { | ||
| return _ref.apply(this, arguments); | ||
| }; | ||
| }(); | ||
| return function _delete() { | ||
| return _ref2.apply(this, arguments); | ||
| }; | ||
| }() | ||
| }[command]; | ||
| main(); | ||
| typeof fn === 'function' && fn(); |
+4
-3
| { | ||
| "name": "github-release-cli", | ||
| "version": "0.2.2", | ||
| "description": "A command-line tool for uploading release assets to a GitHub repository", | ||
| "version": "0.3.0", | ||
| "description": "A command-line tool for managing release assets on a GitHub repository", | ||
| "homepage": "https://github.com/cheton/github-release-cli", | ||
@@ -33,3 +33,4 @@ "author": "Cheton Wu <cheton@gmail.com>", | ||
| "commander": "^2.9.0", | ||
| "github": "^8.1.1" | ||
| "github": "^8.1.1", | ||
| "minimatch": "^3.0.3" | ||
| }, | ||
@@ -36,0 +37,0 @@ "devDependencies": { |
+39
-16
@@ -5,3 +5,3 @@ # github-release-cli [](https://travis-ci.org/cheton/github-release-cli) | ||
| A command-line tool for uploading release assets to a GitHub repository. | ||
| A command-line tool for managing release assets on a GitHub repository. | ||
@@ -14,3 +14,2 @@ ## Installation | ||
| ## Command Line Usage | ||
@@ -21,3 +20,3 @@ | ||
| ``` | ||
| Usage: github-release [options] [file ...] | ||
| Usage: github-release <command> [<args>] | ||
@@ -36,2 +35,30 @@ Options: | ||
| ### Upload | ||
| ```sh | ||
| github-release upload \ | ||
| --owner cheton \ | ||
| --repo github-release-cli \ | ||
| --tag "v0.1.0" \ | ||
| --name "v0.1.0" \ | ||
| --body "This release contains bug fixes and imporvements, including:\n..." \ | ||
| archive.zip index.html app.min.css app.min.js | ||
| ``` | ||
| ### Delete | ||
| You can use glob expressions to match files: | ||
| ```sh | ||
| github-release delete \ | ||
| --owner cheton \ | ||
| --repo github-release-cli \ | ||
| --tag "v0.1.0" \ | ||
| --name "v0.1.0" \ | ||
| archive.zip index.html "app.*" | ||
| ``` | ||
| ## Examples | ||
| https://github.com/cncjs/cncjs-pendant-tinyweb/blob/master/.travis.yml | ||
| ## Secure Setup | ||
@@ -43,3 +70,3 @@ | ||
| ``` | ||
| ```sh | ||
| curl \ | ||
@@ -53,3 +80,3 @@ -u 'username' \ | ||
| ``` | ||
| ```sh | ||
| curl \ | ||
@@ -68,3 +95,3 @@ -u 'username' \ | ||
| ``` | ||
| ```sh | ||
| export GITHUB_TOKEN=your_token | ||
@@ -77,12 +104,12 @@ ``` | ||
| ``` | ||
| ```sh | ||
| COMMIT_LOG=`git log -1 --format='%ci %H %s'` | ||
| github-release \ | ||
| github-release upload \ | ||
| --owner=cheton \ | ||
| --repo=github-release-cli \ | ||
| --tag="${TRAVIS_BRANCH}" \ | ||
| --tag="latest" \ | ||
| --name="${TRAVIS_BRANCH}" \ | ||
| --body="${COMMIT_LOG}" \ | ||
| "releases/file.zip" \ | ||
| "releases/file.tar.gz" | ||
| "releases/myapp-0.1.0-win-x32.exe" \ | ||
| "releases/myapp-0.1.0-win-x64.exe" | ||
| ``` | ||
@@ -92,3 +119,3 @@ | ||
| ``` | ||
| ```sh | ||
| travis encrypt GITHUB_TOKEN=your_token | ||
@@ -100,8 +127,4 @@ ``` | ||
| ## Examples | ||
| https://github.com/cncjs/cncjs/blob/master/.travis.yml | ||
| ## License | ||
| MIT |
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
18060
13.64%282
11.9%0
-100%121
23.47%4
33.33%+ Added
+ Added
+ Added
+ Added
+ Added