From 0e66d1a8bc7291ec70593c3f23f66166ee83535e Mon Sep 17 00:00:00 2001 From: Victor Adewusi Date: Wed, 12 Apr 2023 15:21:42 +0100 Subject: [PATCH] fix(github): update parameters used during upload of release assets (#1000) * fix: update parameters for uploading an asset to a release * test: update tests associated with github asset release * fix: use path.basename * chore: remove mime-types dependency --- packages/shipjs/package.json | 1 - .../__tests__/createGitHubRelease.spec.js | 55 +++++++------------ .../src/step/release/createGitHubRelease.js | 15 ++--- yarn.lock | 2 +- 4 files changed, 28 insertions(+), 45 deletions(-) diff --git a/packages/shipjs/package.json b/packages/shipjs/package.json index 26ffff4f..50ffc4b0 100644 --- a/packages/shipjs/package.json +++ b/packages/shipjs/package.json @@ -48,7 +48,6 @@ "esm": "3.2.25", "globby": "^10.0.1", "inquirer": "7.1.0", - "mime-types": "^2.1.25", "mkdirp": "^1.0.0", "open": "^7.0.0", "prettier": "^2.0.0", diff --git a/packages/shipjs/src/step/release/__tests__/createGitHubRelease.spec.js b/packages/shipjs/src/step/release/__tests__/createGitHubRelease.spec.js index ba2ded0e..6d3bc844 100644 --- a/packages/shipjs/src/step/release/__tests__/createGitHubRelease.spec.js +++ b/packages/shipjs/src/step/release/__tests__/createGitHubRelease.spec.js @@ -1,6 +1,5 @@ import globby from 'globby'; import fs from 'fs'; -import mime from 'mime-types'; import { getRepoInfo } from 'shipjs-lib'; import { Octokit } from '@octokit/rest'; import createGitHubRelease from '../createGitHubRelease'; @@ -9,7 +8,6 @@ jest.mock('@octokit/rest'); jest.mock('globby'); jest.mock('shipjs-lib'); jest.mock('fs'); -jest.mock('mime-types'); const getDefaultParams = ({ assetsToUpload, @@ -32,7 +30,7 @@ describe('createGitHubRelease', () => { beforeEach(() => { createRelease.mockImplementation(() => ({ data: { - upload_url: 'https://dummy/upload/url', // eslint-disable-line camelcase + id: 'releaseId', }, })); @@ -46,7 +44,6 @@ describe('createGitHubRelease', () => { })); fs.readFileSync = jest.fn(); fs.statSync = jest.fn().mockImplementation(() => ({ size: 1024 })); - mime.lookup.mockImplementation(() => 'application/zip'); globby.mockImplementation((path) => Promise.resolve([path])); }); @@ -92,24 +89,20 @@ describe('createGitHubRelease', () => { Array [ Array [ Object { - "file": undefined, - "headers": Object { - "content-length": 1024, - "content-type": "application/zip", - }, + "data": undefined, "name": "path1", - "url": "https://dummy/upload/url", + "owner": "my", + "release_id": "releaseId", + "repo": "repo", }, ], Array [ Object { - "file": undefined, - "headers": Object { - "content-length": 1024, - "content-type": "application/zip", - }, + "data": undefined, "name": "path2", - "url": "https://dummy/upload/url", + "owner": "my", + "release_id": "releaseId", + "repo": "repo", }, ], ] @@ -139,24 +132,20 @@ describe('createGitHubRelease', () => { Array [ Array [ Object { - "file": undefined, - "headers": Object { - "content-length": 1024, - "content-type": "application/zip", - }, + "data": undefined, "name": "path1", - "url": "https://dummy/upload/url", + "owner": "my", + "release_id": "releaseId", + "repo": "repo", }, ], Array [ Object { - "file": undefined, - "headers": Object { - "content-length": 1024, - "content-type": "application/zip", - }, + "data": undefined, "name": "path2", - "url": "https://dummy/upload/url", + "owner": "my", + "release_id": "releaseId", + "repo": "repo", }, ], ] @@ -186,13 +175,11 @@ describe('createGitHubRelease', () => { Array [ Array [ Object { - "file": undefined, - "headers": Object { - "content-length": 1024, - "content-type": "application/zip", - }, + "data": undefined, "name": "path1", - "url": "https://dummy/upload/url", + "owner": "my", + "release_id": "releaseId", + "repo": "repo", }, ], ] diff --git a/packages/shipjs/src/step/release/createGitHubRelease.js b/packages/shipjs/src/step/release/createGitHubRelease.js index 6e11ebac..6c1de9aa 100644 --- a/packages/shipjs/src/step/release/createGitHubRelease.js +++ b/packages/shipjs/src/step/release/createGitHubRelease.js @@ -2,7 +2,6 @@ import path from 'path'; import fs from 'fs'; import globby from 'globby'; import { Octokit } from '@octokit/rest'; -import mime from 'mime-types'; import { getRepoInfo } from 'shipjs-lib'; import runStep from '../runStep'; import { getChangelog } from '../../helper'; @@ -51,7 +50,7 @@ export default async ({ version, config, dir, dryRun }) => }); const { - data: { upload_url }, // eslint-disable-line camelcase + data: { id: releaseId }, } = await octokit.repos.createRelease({ owner, repo, @@ -64,13 +63,11 @@ export default async ({ version, config, dir, dryRun }) => for (const assetPath of assetPaths) { const file = path.resolve(dir, assetPath); await octokit.repos.uploadReleaseAsset({ - file: fs.readFileSync(file), - headers: { - 'content-length': fs.statSync(file).size, - 'content-type': mime.lookup(file), - }, - name: path.basename(file), - url: upload_url, // eslint-disable-line camelcase + data: fs.readFileSync(file), + owner, + repo, + release_id: releaseId, // eslint-disable-line camelcase + name: path.basename(assetPath), }); } } diff --git a/yarn.lock b/yarn.lock index 3d3b8785..5d02c922 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9876,7 +9876,7 @@ mime-db@1.42.0, "mime-db@>= 1.40.0 < 2": resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.42.0.tgz#3e252907b4c7adb906597b4b65636272cf9e7bac" integrity sha512-UbfJCR4UAVRNgMpfImz05smAXK7+c+ZntjaA26ANtkXLlOe947Aag5zdIcKQULAiF9Cq4WxBi9jUs5zkA84bYQ== -mime-types@^2.1.12, mime-types@^2.1.25, mime-types@~2.1.17, mime-types@~2.1.19, mime-types@~2.1.24: +mime-types@^2.1.12, mime-types@~2.1.17, mime-types@~2.1.19, mime-types@~2.1.24: version "2.1.25" resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.25.tgz#39772d46621f93e2a80a856c53b86a62156a6437" integrity sha512-5KhStqB5xpTAeGqKBAMgwaYMnQik7teQN4IAzC7npDv6kzeU6prfkR67bc87J1kWMPGkoaZSq1npmexMgkmEVg==