From f8c75a02f5fcf01bad99f4a9452b1d215cbf2676 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20A=2E=20Bellone?= Date: Tue, 21 Feb 2023 21:19:48 -0300 Subject: [PATCH 1/3] Corrected logic for name matching (mostly for full-URL plugins) --- lib/linters/example-linter.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/linters/example-linter.js b/lib/linters/example-linter.js index 33eb458..b329161 100644 --- a/lib/linters/example-linter.js +++ b/lib/linters/example-linter.js @@ -89,18 +89,22 @@ 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 + refMatches = pluginRef.toString() === id || pluginRef.toString() === `${id}.git` } 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) { From b192d16cd2b0a765e7a68b93419811d8723edd63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20A=2E=20Bellone?= Date: Tue, 21 Feb 2023 21:20:39 -0300 Subject: [PATCH 2/3] Corrected tests for full-url and invalid example --- test/example-linter.test.js | 4 ++-- .../valid-plugin-with-ssh-syntax/README.md | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/test/example-linter.test.js b/test/example-linter.test.js index 0166696..6334ef6 100644 --- a/test/example-linter.test.js +++ b/test/example-linter.test.js @@ -70,7 +70,7 @@ describe('example-linter', () => { describe('valid example with SSH syntax', () => { it('should be valid', async () => { assert(await linter({ - id: 'my-org/example', + id: 'ssh://git@github.com/my-org/example-buildkite-plugin', path: path.join(fixtures, 'valid-plugin-with-ssh-syntax'), silent: true, readme: 'README.md' @@ -80,7 +80,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' diff --git a/test/example-linter/valid-plugin-with-ssh-syntax/README.md b/test/example-linter/valid-plugin-with-ssh-syntax/README.md index d70d61d..c9e0700 100644 --- a/test/example-linter/valid-plugin-with-ssh-syntax/README.md +++ b/test/example-linter/valid-plugin-with-ssh-syntax/README.md @@ -5,4 +5,13 @@ steps: - plugins: - ssh://git@github.com/my-org/example-buildkite-plugin#v1.2.3: option: value +``` + +## Example with .git + +```yaml +steps: + - plugins: + - ssh://git@github.com/my-org/example-buildkite-plugin.git#v1.2.3: + option: value ``` \ No newline at end of file From c88eaa6dbb15110697dd38a24ce47e717440ad26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20A=2E=20Bellone?= Date: Tue, 21 Feb 2023 21:33:10 -0300 Subject: [PATCH 3/3] Allow full-url plugins to be validated with shorthand syntax (note that it may not work on pipelines, though) --- lib/linters/example-linter.js | 5 ++++- test/example-linter.test.js | 10 +++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/linters/example-linter.js b/lib/linters/example-linter.js index b329161..512e442 100644 --- a/lib/linters/example-linter.js +++ b/lib/linters/example-linter.js @@ -96,7 +96,10 @@ module.exports = async function (argv, tap) { hash = pluginRef.hash pluginRef.hash = '' // to get a clean URL - refMatches = pluginRef.toString() === id || pluginRef.toString() === `${id}.git` + + 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 const pluginRef = new URL(`https://github.com/${pluginSpec}`) diff --git a/test/example-linter.test.js b/test/example-linter.test.js index 6334ef6..b16c248 100644 --- a/test/example-linter.test.js +++ b/test/example-linter.test.js @@ -68,7 +68,7 @@ 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://git@github.com/my-org/example-buildkite-plugin', path: path.join(fixtures, 'valid-plugin-with-ssh-syntax'), @@ -76,6 +76,14 @@ describe('example-linter', () => { 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'), + silent: true, + readme: 'README.md' + }, tap)) + }) }) describe('invalid examples', () => { it('should be invalid', async () => {