Skip to content

Commit caea759

Browse files
maratorichris48s
andauthored
[GitHubGoMod] Ignore comment after version (fixes #10079) (#10080)
* [GithubGoMod] Ignore comment after version (fixes #10079) * add unit tests for GithubGoModGoVersion.transform --------- Co-authored-by: chris48s <git@chris-shaw.dev>
1 parent 60056fc commit caea759

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

services/github/github-go-mod.service.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const queryParamSchema = Joi.object({
99
filename: Joi.string(),
1010
}).required()
1111

12-
const goVersionRegExp = /^go (.+)$/m
12+
const goVersionRegExp = /^go ([^/\s]+)(\s*\/.+)?$/m
1313

1414
const filenameDescription =
1515
'The `filename` param can be used to specify the path to `go.mod`. By default, we look for `go.mod` in the repo root'

services/github/github-go-mod.spec.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { expect } from 'chai'
2+
import { test, given } from 'sazerac'
3+
import { InvalidResponse } from '../index.js'
4+
import GithubGoModGoVersion from './github-go-mod.service.js'
5+
6+
describe('GithubGoModGoVersion', function () {
7+
describe('valid cases', function () {
8+
test(GithubGoModGoVersion.transform, () => {
9+
given('go 1.18').expect({ go: '1.18' })
10+
given('go 1.18 // inline comment').expect({ go: '1.18' })
11+
given('go 1.18// inline comment').expect({ go: '1.18' })
12+
given('go 1.18 /* block comment */').expect({ go: '1.18' })
13+
given('go 1.18/* block comment */').expect({ go: '1.18' })
14+
given('go 1').expect({ go: '1' })
15+
given('go 1.2.3').expect({ go: '1.2.3' })
16+
given('go string').expect({ go: 'string' })
17+
})
18+
})
19+
20+
describe('invalid cases', function () {
21+
expect(() => GithubGoModGoVersion.transform('')).to.throw(InvalidResponse)
22+
expect(() =>
23+
GithubGoModGoVersion.transform("doesn't start with go"),
24+
).to.throw(InvalidResponse)
25+
})
26+
})

0 commit comments

Comments
 (0)