From 5d39f776e10df5bf62f85ded1424246daf0bc7fa Mon Sep 17 00:00:00 2001 From: Jonatan Nilsson Date: Thu, 18 Aug 2022 10:54:38 +0000 Subject: [PATCH] git: Auto replace spaces with underscores in version output. Allows versions to have spaces in their name while keeping it unix friendly folder and file name. --- core/providers/git.mjs | 2 +- package.json | 2 +- test/providers/git.test.mjs | 19 +++++++++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/core/providers/git.mjs b/core/providers/git.mjs index 381e053..e6f1470 100644 --- a/core/providers/git.mjs +++ b/core/providers/git.mjs @@ -29,7 +29,7 @@ export default class GitProvider { if (this.config.git_required_prefix && !asset.name.startsWith(this.config.git_required_prefix)) continue return { - version: item.name, + version: item.name.replace(/ /g, '_'), link: asset.browser_download_url, filename: asset.name, description: item.body, diff --git a/package.json b/package.json index 97ad4a3..e173e1e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "service-core", - "version": "3.0.0", + "version": "3.0.1", "description": "Core boiler plate code to install node server as windows service", "main": "index.mjs", "scripts": { diff --git a/test/providers/git.test.mjs b/test/providers/git.test.mjs index da1d054..7bed1c6 100644 --- a/test/providers/git.test.mjs +++ b/test/providers/git.test.mjs @@ -20,6 +20,25 @@ t.describe('#getLatestVersion()', function() { assert.strictEqual(version.log, '') }) + t.test('should auto replace spaces with underscores result', async function() { + const assertOriginalName = 'The Smell Of Sea' + const assertCorrectName = 'The_Smell_Of_Sea' + const assertLink = 'Over The Future' + const assertFilename = 'test-sc.7z' + let stubber = stub() + let provider = new GitProvider({}, stubber) + + stubber.resolves({ body: [ + { name: assertOriginalName, assets: [{ name: assertFilename, browser_download_url: assertLink }] }, + ]}) + + let version = await provider.getLatestVersion() + assert.strictEqual(version.version, assertCorrectName) + assert.strictEqual(version.link, assertLink) + assert.strictEqual(version.filename, assertFilename) + assert.strictEqual(version.log, '') + }) + t.test('should skip zip files for now', async function() { const assertName = 'Karen' const assertLink = 'My Wings'