From d487290a4283dce81f3d870c80601ba14ddf492d Mon Sep 17 00:00:00 2001 From: Marat Reymers <16486128+maratori@users.noreply.github.com> Date: Sat, 6 Apr 2024 23:07:38 +0200 Subject: [PATCH 1/2] [GithubGoMod] Ignore comment after version (fixes #10079) --- services/github/github-go-mod.service.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/github/github-go-mod.service.js b/services/github/github-go-mod.service.js index ed678e38f9f29..77f2080b52492 100644 --- a/services/github/github-go-mod.service.js +++ b/services/github/github-go-mod.service.js @@ -9,7 +9,7 @@ const queryParamSchema = Joi.object({ filename: Joi.string(), }).required() -const goVersionRegExp = /^go (.+)$/m +const goVersionRegExp = /^go ([^/\s]+)(\s*\/.+)?$/m const filenameDescription = 'The `filename` param can be used to specify the path to `go.mod`. By default, we look for `go.mod` in the repo root' From ef8681bb382c1a1ef484d50f6f3f6f1e225efcdb Mon Sep 17 00:00:00 2001 From: chris48s Date: Sun, 7 Apr 2024 08:47:56 +0100 Subject: [PATCH 2/2] add unit tests for GithubGoModGoVersion.transform --- services/github/github-go-mod.spec.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 services/github/github-go-mod.spec.js diff --git a/services/github/github-go-mod.spec.js b/services/github/github-go-mod.spec.js new file mode 100644 index 0000000000000..cec2276509d80 --- /dev/null +++ b/services/github/github-go-mod.spec.js @@ -0,0 +1,26 @@ +import { expect } from 'chai' +import { test, given } from 'sazerac' +import { InvalidResponse } from '../index.js' +import GithubGoModGoVersion from './github-go-mod.service.js' + +describe('GithubGoModGoVersion', function () { + describe('valid cases', function () { + test(GithubGoModGoVersion.transform, () => { + given('go 1.18').expect({ go: '1.18' }) + given('go 1.18 // inline comment').expect({ go: '1.18' }) + given('go 1.18// inline comment').expect({ go: '1.18' }) + given('go 1.18 /* block comment */').expect({ go: '1.18' }) + given('go 1.18/* block comment */').expect({ go: '1.18' }) + given('go 1').expect({ go: '1' }) + given('go 1.2.3').expect({ go: '1.2.3' }) + given('go string').expect({ go: 'string' }) + }) + }) + + describe('invalid cases', function () { + expect(() => GithubGoModGoVersion.transform('')).to.throw(InvalidResponse) + expect(() => + GithubGoModGoVersion.transform("doesn't start with go"), + ).to.throw(InvalidResponse) + }) +})