Skip to content

Commit

Permalink
[GitHubGoMod] Ignore comment after version (fixes #10079) (#10080)
Browse files Browse the repository at this point in the history
* [GithubGoMod] Ignore comment after version (fixes #10079)

* add unit tests for GithubGoModGoVersion.transform

---------

Co-authored-by: chris48s <[email protected]>
  • Loading branch information
maratori and chris48s committed Apr 7, 2024
1 parent 60056fc commit caea759
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion services/github/github-go-mod.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
26 changes: 26 additions & 0 deletions services/github/github-go-mod.spec.js
Original file line number Diff line number Diff line change
@@ -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)
})
})

0 comments on commit caea759

Please sign in to comment.