Skip to content

Commit

Permalink
Merge pull request #463 from buildkite-plugins/toote_full_url_plugin_bug
Browse files Browse the repository at this point in the history
Full URL plugin bug
  • Loading branch information
pzeballos authored Feb 22, 2023
2 parents b97bd28 + c88eaa6 commit da0f92e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
19 changes: 13 additions & 6 deletions lib/linters/example-linter.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,25 @@ module.exports = async function (argv, tap) {
return pluginRegexp.test(pluginSpec)
}

let pluginRef, expectedPath
let hash, refMatches
try {
// full URL plugins
pluginRef = new URL(pluginSpec)
expectedPath = `/${id}-buildkite-plugin`
const pluginRef = new URL(pluginSpec)
hash = pluginRef.hash

pluginRef.hash = '' // to get a clean URL

const fullURLOptions = [id, `${id}.git`]
const shorthandOptions = [`/${id}-buildkite-plugin`, `/${id}-buildkite-plugin.git`]
refMatches = fullURLOptions.includes(pluginRef.toString()) || shorthandOptions.includes(pluginRef.pathname)
} catch (err) {
// assume it is just the name, build the URL (almost) and try again
pluginRef = new URL(`https://github.com/${pluginSpec}`)
expectedPath = `/${id}`
const pluginRef = new URL(`https://github.com/${pluginSpec}`)
hash = pluginRef.hash
refMatches = pluginRef.pathname === `/${id}`
}

return pluginRef.pathname === expectedPath && pluginRef.hash.startsWith('#v')
return refMatches && hash && hash.startsWith('#v')
}

function extractPluginConfigs (exampleYaml) {
Expand Down
12 changes: 10 additions & 2 deletions test/example-linter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,15 @@ describe('example-linter', () => {
})
})
describe('valid example with SSH syntax', () => {
it('should be valid', async () => {
it('should be valid with full url', async () => {
assert(await linter({
id: 'ssh://[email protected]/my-org/example-buildkite-plugin',
path: path.join(fixtures, 'valid-plugin-with-ssh-syntax'),
silent: true,
readme: 'README.md'
}, tap))
})
it('should be valid with plugin id', async () => {
assert(await linter({
id: 'my-org/example',
path: path.join(fixtures, 'valid-plugin-with-ssh-syntax'),
Expand All @@ -80,7 +88,7 @@ describe('example-linter', () => {
describe('invalid examples', () => {
it('should be invalid', async () => {
assert.isFalse(await linter({
id: 'invalid-examples',
id: 'invalid-plugin',
path: path.join(fixtures, 'invalid-examples'),
silent: true,
readme: 'README.md'
Expand Down
9 changes: 9 additions & 0 deletions test/example-linter/valid-plugin-with-ssh-syntax/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,13 @@ steps:
- plugins:
- ssh://[email protected]/my-org/example-buildkite-plugin#v1.2.3:
option: value
```
## Example with .git
```yaml
steps:
- plugins:
- ssh://[email protected]/my-org/example-buildkite-plugin.git#v1.2.3:
option: value
```

0 comments on commit da0f92e

Please sign in to comment.