@cucumber/create-meta
Advanced tools
Comparing version 5.0.0 to 6.0.0
{ | ||
"Azure Pipelines": { | ||
"url": "${BUILD_URI}", | ||
"url": "${BUILD_BUILDURI}", | ||
"buildNumber": "${BUILD_BUILDNUMBER}", | ||
"git": { | ||
@@ -12,7 +13,8 @@ "remote": "${BUILD_REPOSITORY_URI}", | ||
"Bamboo": { | ||
"url": "${bamboo.buildResultsUrl}", | ||
"url": "${bamboo_buildResultsUrl}", | ||
"buildNumber": "${bamboo_buildNumber}", | ||
"git": { | ||
"remote": "${bamboo.planRepository.1.repositoryUrl}", | ||
"revision": "${bamboo.planRepository.1.revision}", | ||
"branch": "${bamboo.planRepository.1.branch}", | ||
"remote": "${bamboo_planRepository_repositoryUrl}", | ||
"revision": "${bamboo_planRepository_revision}", | ||
"branch": "${bamboo_planRepository_branch}", | ||
"tag": null | ||
@@ -23,2 +25,3 @@ } | ||
"url": "${BUDDY_EXECUTION_URL}", | ||
"buildNumber": "${BUDDY_EXECUTION_ID}", | ||
"git": { | ||
@@ -33,2 +36,3 @@ "remote": "${BUDDY_SCM_URL}", | ||
"url": "${BITRISE_BUILD_URL}", | ||
"buildNumber": "${BITRISE_BUILD_NUMBER}", | ||
"git": { | ||
@@ -43,2 +47,3 @@ "remote": "${GIT_REPOSITORY_URL}", | ||
"url": "${CIRCLE_BUILD_URL}", | ||
"buildNumber": "${CIRCLE_BUILD_NUM}", | ||
"git": { | ||
@@ -53,4 +58,5 @@ "remote": "${CIRCLE_REPOSITORY_URL}", | ||
"url": "${CF_BUILD_URL}", | ||
"buildNumber": "${CF_BUILD_ID}", | ||
"git": { | ||
"remote": "${CF_COMMIT_URL}", | ||
"remote": "${CF_COMMIT_URL/(.*)\\/commit.+$/\\1}.git", | ||
"revision": "${CF_REVISION}", | ||
@@ -63,2 +69,3 @@ "branch": "${CF_BRANCH}", | ||
"url": "${CI_BUILD_URL}", | ||
"buildNumber": "${CI_BUILD_NUMBER}", | ||
"git": { | ||
@@ -73,2 +80,3 @@ "remote": "${CI_PULL_REQUEST/(.*)\\/pull\\/\\d+/\\1.git}", | ||
"url": "${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}", | ||
"buildNumber": "${GITHUB_RUN_ID}", | ||
"git": { | ||
@@ -83,2 +91,3 @@ "remote": "${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git", | ||
"url": "${CI_JOB_URL}", | ||
"buildNumber": "${CI_JOB_ID}", | ||
"git": { | ||
@@ -93,2 +102,3 @@ "remote": "${CI_REPOSITORY_URL}", | ||
"url": "${GO_SERVER_URL}/pipelines/${GO_PIPELINE_NAME}/${GO_PIPELINE_COUNTER}/${GO_STAGE_NAME}/${GO_STAGE_COUNTER}", | ||
"buildNumber": "${GO_PIPELINE_NAME}/${GO_PIPELINE_COUNTER}/${GO_STAGE_NAME}/${GO_STAGE_COUNTER}", | ||
"git": { | ||
@@ -103,2 +113,3 @@ "remote": "${GO_SCM_*_PR_URL/(.*)\\/pull\\/\\d+/\\1.git}", | ||
"url": "${BUILD_URL}", | ||
"buildNumber": "${BUILD_NUMBER}", | ||
"git": { | ||
@@ -113,2 +124,3 @@ "remote": "${GIT_URL}", | ||
"url": "${SEMAPHORE_ORGANIZATION_URL}/jobs/${SEMAPHORE_JOB_ID}", | ||
"buildNumber": "${SEMAPHORE_JOB_ID}", | ||
"git": { | ||
@@ -121,13 +133,5 @@ "remote": "${SEMAPHORE_GIT_URL}", | ||
}, | ||
"TeamCity": { | ||
"url": "${teamcity.serverUrl}/app/rest/builds/id:${teamcity.build.id}", | ||
"git": { | ||
"remote": null, | ||
"revision": "${build.vcs.number}", | ||
"branch": "${teamcity.build.branch}", | ||
"tag": null | ||
} | ||
}, | ||
"Travis CI": { | ||
"url": "${TRAVIS_BUILD_WEB_URL}", | ||
"buildNumber": "${TRAVIS_JOB_NUMBER}", | ||
"git": { | ||
@@ -142,2 +146,3 @@ "remote": "https://github.com/${TRAVIS_REPO_SLUG}.git", | ||
"url": "${WERCKER_RUN_URL}", | ||
"buildNumber": "${WERCKER_RUN_URL/.*\\/([^\\/]+)$/\\1}", | ||
"git": { | ||
@@ -144,0 +149,0 @@ "remote": "https://${WERCKER_GIT_DOMAIN}/${WERCKER_GIT_OWNER}/${WERCKER_GIT_REPOSITORY}.git", |
import * as messages from '@cucumber/messages'; | ||
export declare type CiDict = Record<string, CiSystem>; | ||
export declare type Env = Record<string, string | undefined>; | ||
export interface CiSystem { | ||
url: string; | ||
git: { | ||
remote: string | undefined; | ||
branch: string | undefined; | ||
revision: string | undefined; | ||
tag: string | undefined; | ||
}; | ||
} | ||
import { CiDict, Env } from './types'; | ||
export default function createMeta(toolName: string, toolVersion: string, envDict: Env, ciDict?: CiDict): messages.Meta; | ||
@@ -14,0 +4,0 @@ export declare function detectCI(ciDict: CiDict, envDict: Env): messages.Ci | undefined; |
@@ -86,2 +86,3 @@ "use strict"; | ||
const url = evaluateVariableExpression_1.default(ciSystem.url, envDict); | ||
const buildNumber = evaluateVariableExpression_1.default(ciSystem.buildNumber, envDict); | ||
if (url === undefined) { | ||
@@ -92,6 +93,7 @@ // The url is what consumers will use as the primary key for a build | ||
} | ||
let branch = evaluateVariableExpression_1.default(ciSystem.git.branch, envDict); | ||
const branch = evaluateVariableExpression_1.default(ciSystem.git.branch, envDict); | ||
return { | ||
name: ciName, | ||
url, | ||
name: ciName, | ||
buildNumber, | ||
git: { | ||
@@ -98,0 +100,0 @@ remote: removeUserInfoFromUrl(evaluateVariableExpression_1.default(ciSystem.git.remote, envDict)), |
@@ -1,3 +0,3 @@ | ||
import { Env } from "./createMeta"; | ||
import { Env } from './types'; | ||
export default function evaluateVariableExpression(expression: string | undefined, env: Env): string | undefined; | ||
//# sourceMappingURL=evaluateVariableExpression.d.ts.map |
@@ -8,3 +8,3 @@ "use strict"; | ||
try { | ||
const re = new RegExp("\\${(.*?)(?:(?<!\\\\)/(.*)/(.*))?}", 'g'); | ||
const re = new RegExp('\\${(.*?)(?:(?<!\\\\)/(.*)/(.*))?}', 'g'); | ||
return expression.replace(re, (substring, ...args) => { | ||
@@ -20,3 +20,3 @@ const variable = args[0]; | ||
} | ||
const regExp = new RegExp(pattern.replace('\/', '/')); | ||
const regExp = new RegExp(pattern.replace('/', '/')); | ||
const match = regExp.exec(value); | ||
@@ -23,0 +23,0 @@ if (!match) { |
@@ -22,2 +22,3 @@ "use strict"; | ||
CIRCLE_TAG: 'the-tag', | ||
CIRCLE_BUILD_NUM: '234', | ||
}; | ||
@@ -28,2 +29,3 @@ const meta = createMeta_1.default('someTool', '1.2.3', envDict, ciDict_json_1.default); | ||
url: 'the-url', | ||
buildNumber: '234', | ||
git: { | ||
@@ -50,2 +52,3 @@ remote: 'the-remote', | ||
url: 'https://github.com/cucumber/cucumber-ruby/actions/runs/140170388', | ||
buildNumber: '140170388', | ||
git: { | ||
@@ -72,2 +75,3 @@ remote: 'https://github.com/cucumber/cucumber-ruby.git', | ||
url: 'https://github.company.com/cucumber/cucumber-ruby/actions/runs/140170388', | ||
buildNumber: '140170388', | ||
git: { | ||
@@ -84,6 +88,7 @@ remote: 'https://github.company.com/cucumber/cucumber-ruby.git', | ||
const envDict = { | ||
BUILD_URI: 'the-url', | ||
BUILD_BUILDURI: 'the-url', | ||
BUILD_REPOSITORY_URI: 'the-remote', | ||
BUILD_SOURCEBRANCH: 'refs/heads/main', | ||
BUILD_SOURCEVERSION: 'the-revision', | ||
BUILD_BUILDNUMBER: '456', | ||
}; | ||
@@ -94,2 +99,3 @@ const meta = createMeta_1.default('someTool', '1.2.3', envDict, ciDict_json_1.default); | ||
url: 'the-url', | ||
buildNumber: '456', | ||
git: { | ||
@@ -106,6 +112,7 @@ remote: 'the-remote', | ||
const envDict = { | ||
BUILD_URI: 'the-url', | ||
BUILD_BUILDURI: 'the-url', | ||
BUILD_REPOSITORY_URI: 'the-remote', | ||
BUILD_SOURCEBRANCH: 'refs/tags/v1.2.3', | ||
BUILD_SOURCEVERSION: 'the-revision', | ||
BUILD_BUILDNUMBER: '456', | ||
}; | ||
@@ -116,2 +123,3 @@ const meta = createMeta_1.default('someTool', '1.2.3', envDict, ciDict_json_1.default); | ||
url: 'the-url', | ||
buildNumber: '456', | ||
git: { | ||
@@ -126,3 +134,26 @@ remote: 'the-remote', | ||
}); | ||
it('extracts build number from url', () => { | ||
const envDict = { | ||
WERCKER_GIT_BRANCH: 'main', | ||
WERCKER_GIT_COMMIT: '057f8fe233b17629af084064c2a7b8d1dbb795ad', | ||
WERCKER_GIT_DOMAIN: 'github.com', | ||
WERCKER_GIT_OWNER: 'cucumber-ltd', | ||
WERCKER_GIT_REPOSITORY: 'shouty.rb', | ||
WERCKER_RUN_URL: 'https://cihost.com/path/to/build/629af084064c2', | ||
}; | ||
const meta = createMeta_1.default('someTool', '1.2.3', envDict, ciDict_json_1.default); | ||
const ci = { | ||
git: { | ||
branch: 'main', | ||
tag: undefined, | ||
remote: 'https://github.com/cucumber-ltd/shouty.rb.git', | ||
revision: '057f8fe233b17629af084064c2a7b8d1dbb795ad', | ||
}, | ||
name: 'Wercker', | ||
url: 'https://cihost.com/path/to/build/629af084064c2', | ||
buildNumber: '629af084064c2', | ||
}; | ||
assert_1.default.deepStrictEqual(meta.ci, ci); | ||
}); | ||
}); | ||
//# sourceMappingURL=createMetaTest.js.map |
@@ -10,3 +10,3 @@ "use strict"; | ||
it('returns undefined when a variable is undefined', () => { | ||
const expression = "hello-${SOME_VAR}"; | ||
const expression = 'hello-${SOME_VAR}'; | ||
const result = evaluateVariableExpression_1.default(expression, {}); | ||
@@ -16,3 +16,3 @@ assert_1.default.strictEqual(result, undefined); | ||
it('gets a value without replacement', () => { | ||
const expression = "${SOME_VAR}"; | ||
const expression = '${SOME_VAR}'; | ||
const result = evaluateVariableExpression_1.default(expression, { SOME_VAR: 'some_value' }); | ||
@@ -22,3 +22,3 @@ assert_1.default.strictEqual(result, 'some_value'); | ||
it('captures a group', () => { | ||
const expression = "${SOME_REF/refs\\/heads\\/(.*)/\\1}"; | ||
const expression = '${SOME_REF/refs\\/heads\\/(.*)/\\1}'; | ||
const result = evaluateVariableExpression_1.default(expression, { SOME_REF: 'refs/heads/main' }); | ||
@@ -28,9 +28,14 @@ assert_1.default.strictEqual(result, 'main'); | ||
it('works with star wildcard in var', () => { | ||
const expression = "${GO_SCM_*_PR_BRANCH/.*:(.*)/\\1}"; | ||
const result = evaluateVariableExpression_1.default(expression, { GO_SCM_MY_MATERIAL_PR_BRANCH: 'ashwankthkumar:feature-1' }); | ||
const expression = '${GO_SCM_*_PR_BRANCH/.*:(.*)/\\1}'; | ||
const result = evaluateVariableExpression_1.default(expression, { | ||
GO_SCM_MY_MATERIAL_PR_BRANCH: 'ashwankthkumar:feature-1', | ||
}); | ||
assert_1.default.strictEqual(result, 'feature-1'); | ||
}); | ||
it('evaluates a complex expression', () => { | ||
const expression = "hello-${VAR1}-${VAR2/(.*) (.*)/\\2-\\1}-world"; | ||
const result = evaluateVariableExpression_1.default(expression, { VAR1: "amazing", VAR2: "gorgeous beautiful" }); | ||
const expression = 'hello-${VAR1}-${VAR2/(.*) (.*)/\\2-\\1}-world'; | ||
const result = evaluateVariableExpression_1.default(expression, { | ||
VAR1: 'amazing', | ||
VAR2: 'gorgeous beautiful', | ||
}); | ||
assert_1.default.strictEqual(result, 'hello-amazing-beautiful-gorgeous-world'); | ||
@@ -37,0 +42,0 @@ }); |
{ | ||
"name": "@cucumber/create-meta", | ||
"version": "5.0.0", | ||
"version": "6.0.0", | ||
"description": "Produce the meta message for Cucumber JavaScript", | ||
@@ -26,12 +26,12 @@ "main": "dist/src/index.js", | ||
"devDependencies": { | ||
"@types/glob": "7.1.3", | ||
"@types/mocha": "8.2.2", | ||
"@types/node": "15.3.0", | ||
"mocha": "8.4.0", | ||
"@types/glob": "7.1.4", | ||
"@types/mocha": "8.2.3", | ||
"@types/node": "14.17.5", | ||
"mocha": "9.0.2", | ||
"source-map-support": "0.5.19", | ||
"ts-node": "9.1.1", | ||
"typescript": "4.2.4" | ||
"ts-node": "10.0.0", | ||
"typescript": "4.3.5" | ||
}, | ||
"dependencies": { | ||
"@cucumber/messages": "^16.0.0" | ||
"@cucumber/messages": "^17.0.0" | ||
}, | ||
@@ -38,0 +38,0 @@ "directories": { |
{ | ||
"Azure Pipelines": { | ||
"url": "${BUILD_URI}", | ||
"url": "${BUILD_BUILDURI}", | ||
"buildNumber": "${BUILD_BUILDNUMBER}", | ||
"git": { | ||
@@ -12,7 +13,8 @@ "remote": "${BUILD_REPOSITORY_URI}", | ||
"Bamboo": { | ||
"url": "${bamboo.buildResultsUrl}", | ||
"url": "${bamboo_buildResultsUrl}", | ||
"buildNumber": "${bamboo_buildNumber}", | ||
"git": { | ||
"remote": "${bamboo.planRepository.1.repositoryUrl}", | ||
"revision": "${bamboo.planRepository.1.revision}", | ||
"branch": "${bamboo.planRepository.1.branch}", | ||
"remote": "${bamboo_planRepository_repositoryUrl}", | ||
"revision": "${bamboo_planRepository_revision}", | ||
"branch": "${bamboo_planRepository_branch}", | ||
"tag": null | ||
@@ -23,2 +25,3 @@ } | ||
"url": "${BUDDY_EXECUTION_URL}", | ||
"buildNumber": "${BUDDY_EXECUTION_ID}", | ||
"git": { | ||
@@ -33,2 +36,3 @@ "remote": "${BUDDY_SCM_URL}", | ||
"url": "${BITRISE_BUILD_URL}", | ||
"buildNumber": "${BITRISE_BUILD_NUMBER}", | ||
"git": { | ||
@@ -43,2 +47,3 @@ "remote": "${GIT_REPOSITORY_URL}", | ||
"url": "${CIRCLE_BUILD_URL}", | ||
"buildNumber": "${CIRCLE_BUILD_NUM}", | ||
"git": { | ||
@@ -53,4 +58,5 @@ "remote": "${CIRCLE_REPOSITORY_URL}", | ||
"url": "${CF_BUILD_URL}", | ||
"buildNumber": "${CF_BUILD_ID}", | ||
"git": { | ||
"remote": "${CF_COMMIT_URL}", | ||
"remote": "${CF_COMMIT_URL/(.*)\\/commit.+$/\\1}.git", | ||
"revision": "${CF_REVISION}", | ||
@@ -63,2 +69,3 @@ "branch": "${CF_BRANCH}", | ||
"url": "${CI_BUILD_URL}", | ||
"buildNumber": "${CI_BUILD_NUMBER}", | ||
"git": { | ||
@@ -73,2 +80,3 @@ "remote": "${CI_PULL_REQUEST/(.*)\\/pull\\/\\d+/\\1.git}", | ||
"url": "${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}", | ||
"buildNumber": "${GITHUB_RUN_ID}", | ||
"git": { | ||
@@ -83,2 +91,3 @@ "remote": "${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git", | ||
"url": "${CI_JOB_URL}", | ||
"buildNumber": "${CI_JOB_ID}", | ||
"git": { | ||
@@ -93,2 +102,3 @@ "remote": "${CI_REPOSITORY_URL}", | ||
"url": "${GO_SERVER_URL}/pipelines/${GO_PIPELINE_NAME}/${GO_PIPELINE_COUNTER}/${GO_STAGE_NAME}/${GO_STAGE_COUNTER}", | ||
"buildNumber": "${GO_PIPELINE_NAME}/${GO_PIPELINE_COUNTER}/${GO_STAGE_NAME}/${GO_STAGE_COUNTER}", | ||
"git": { | ||
@@ -103,2 +113,3 @@ "remote": "${GO_SCM_*_PR_URL/(.*)\\/pull\\/\\d+/\\1.git}", | ||
"url": "${BUILD_URL}", | ||
"buildNumber": "${BUILD_NUMBER}", | ||
"git": { | ||
@@ -113,2 +124,3 @@ "remote": "${GIT_URL}", | ||
"url": "${SEMAPHORE_ORGANIZATION_URL}/jobs/${SEMAPHORE_JOB_ID}", | ||
"buildNumber": "${SEMAPHORE_JOB_ID}", | ||
"git": { | ||
@@ -121,13 +133,5 @@ "remote": "${SEMAPHORE_GIT_URL}", | ||
}, | ||
"TeamCity": { | ||
"url": "${teamcity.serverUrl}/app/rest/builds/id:${teamcity.build.id}", | ||
"git": { | ||
"remote": null, | ||
"revision": "${build.vcs.number}", | ||
"branch": "${teamcity.build.branch}", | ||
"tag": null | ||
} | ||
}, | ||
"Travis CI": { | ||
"url": "${TRAVIS_BUILD_WEB_URL}", | ||
"buildNumber": "${TRAVIS_JOB_NUMBER}", | ||
"git": { | ||
@@ -142,2 +146,3 @@ "remote": "https://github.com/${TRAVIS_REPO_SLUG}.git", | ||
"url": "${WERCKER_RUN_URL}", | ||
"buildNumber": "${WERCKER_RUN_URL/.*\\/([^\\/]+)$/\\1}", | ||
"git": { | ||
@@ -144,0 +149,0 @@ "remote": "https://${WERCKER_GIT_DOMAIN}/${WERCKER_GIT_OWNER}/${WERCKER_GIT_REPOSITORY}.git", |
@@ -5,17 +5,5 @@ import os from 'os' | ||
import defaultCiDict from './ciDict.json' | ||
import evaluateVariableExpression from "./evaluateVariableExpression"; | ||
import evaluateVariableExpression from './evaluateVariableExpression' | ||
import { CiDict, CiSystem, Env } from './types' | ||
export type CiDict = Record<string,CiSystem> | ||
export type Env = Record<string,string|undefined> | ||
export interface CiSystem { | ||
url: string | ||
git: { | ||
remote: string | undefined | ||
branch: string | undefined | ||
revision: string | undefined | ||
tag: string | undefined | ||
} | ||
} | ||
export default function createMeta( | ||
@@ -63,3 +51,9 @@ toolName: string, | ||
if (detected.length > 1) { | ||
console.error(`@cucumber/create-meta WARNING: Detected more than one CI: ${JSON.stringify(detected, null, 2)}`) | ||
console.error( | ||
`@cucumber/create-meta WARNING: Detected more than one CI: ${JSON.stringify( | ||
detected, | ||
null, | ||
2 | ||
)}` | ||
) | ||
console.error('Using the first one.') | ||
@@ -80,2 +74,3 @@ } | ||
const url = evaluateVariableExpression(ciSystem.url, envDict) | ||
const buildNumber = evaluateVariableExpression(ciSystem.buildNumber, envDict) | ||
if (url === undefined) { | ||
@@ -87,6 +82,7 @@ // The url is what consumers will use as the primary key for a build | ||
let branch = evaluateVariableExpression(ciSystem.git.branch, envDict); | ||
const branch = evaluateVariableExpression(ciSystem.git.branch, envDict) | ||
return { | ||
name: ciName, | ||
url, | ||
name: ciName, | ||
buildNumber, | ||
git: { | ||
@@ -100,2 +96,1 @@ remote: removeUserInfoFromUrl(evaluateVariableExpression(ciSystem.git.remote, envDict)), | ||
} | ||
@@ -1,4 +0,7 @@ | ||
import {Env} from "./createMeta"; | ||
import { Env } from './types' | ||
export default function evaluateVariableExpression(expression: string | undefined, env: Env): string | undefined { | ||
export default function evaluateVariableExpression( | ||
expression: string | undefined, | ||
env: Env | ||
): string | undefined { | ||
if (expression === undefined) { | ||
@@ -8,28 +11,25 @@ return undefined | ||
try { | ||
const re = new RegExp("\\${(.*?)(?:(?<!\\\\)/(.*)/(.*))?}", 'g') | ||
return expression.replace( | ||
re, | ||
(substring, ...args): string => { | ||
const variable = args[0] | ||
const value = getValue(env, variable) | ||
if (value === undefined) { | ||
throw new Error(`Undefined variable: ${variable}`) | ||
} | ||
const pattern = args[1] | ||
if(!pattern) { | ||
return value | ||
} | ||
const regExp = new RegExp(pattern.replace('\/', '/')); | ||
const match = regExp.exec(value) | ||
if(!match) { | ||
throw new Error(`No match for: ${variable}`) | ||
} | ||
let replacement = args[2] | ||
let ref = 1 | ||
for (const group of match.slice(1)) { | ||
replacement = replacement.replace(`\\${ref++}`, group) | ||
} | ||
return replacement | ||
const re = new RegExp('\\${(.*?)(?:(?<!\\\\)/(.*)/(.*))?}', 'g') | ||
return expression.replace(re, (substring, ...args): string => { | ||
const variable = args[0] | ||
const value = getValue(env, variable) | ||
if (value === undefined) { | ||
throw new Error(`Undefined variable: ${variable}`) | ||
} | ||
) | ||
const pattern = args[1] | ||
if (!pattern) { | ||
return value | ||
} | ||
const regExp = new RegExp(pattern.replace('/', '/')) | ||
const match = regExp.exec(value) | ||
if (!match) { | ||
throw new Error(`No match for: ${variable}`) | ||
} | ||
let replacement = args[2] | ||
let ref = 1 | ||
for (const group of match.slice(1)) { | ||
replacement = replacement.replace(`\\${ref++}`, group) | ||
} | ||
return replacement | ||
}) | ||
} catch (err) { | ||
@@ -42,6 +42,6 @@ // There was an undefined variable | ||
function getValue(env: Env, variable: string) { | ||
if(variable.includes('*')) { | ||
if (variable.includes('*')) { | ||
const regexp = new RegExp(variable.replace('*', '.*')) | ||
for (const [name, value] of Object.entries(env)) { | ||
if(regexp.exec(name)) { | ||
if (regexp.exec(name)) { | ||
return value | ||
@@ -51,4 +51,3 @@ } | ||
} | ||
return env[variable]; | ||
return env[variable] | ||
} | ||
@@ -21,2 +21,3 @@ import createMeta from '../src/createMeta' | ||
CIRCLE_TAG: 'the-tag', | ||
CIRCLE_BUILD_NUM: '234', | ||
} | ||
@@ -28,2 +29,3 @@ | ||
url: 'the-url', | ||
buildNumber: '234', | ||
git: { | ||
@@ -52,2 +54,3 @@ remote: 'the-remote', | ||
url: 'https://github.com/cucumber/cucumber-ruby/actions/runs/140170388', | ||
buildNumber: '140170388', | ||
git: { | ||
@@ -76,2 +79,3 @@ remote: 'https://github.com/cucumber/cucumber-ruby.git', | ||
url: 'https://github.company.com/cucumber/cucumber-ruby/actions/runs/140170388', | ||
buildNumber: '140170388', | ||
git: { | ||
@@ -89,6 +93,7 @@ remote: 'https://github.company.com/cucumber/cucumber-ruby.git', | ||
const envDict = { | ||
BUILD_URI: 'the-url', | ||
BUILD_BUILDURI: 'the-url', | ||
BUILD_REPOSITORY_URI: 'the-remote', | ||
BUILD_SOURCEBRANCH: 'refs/heads/main', | ||
BUILD_SOURCEVERSION: 'the-revision', | ||
BUILD_BUILDNUMBER: '456', | ||
} | ||
@@ -100,2 +105,3 @@ | ||
url: 'the-url', | ||
buildNumber: '456', | ||
git: { | ||
@@ -113,6 +119,7 @@ remote: 'the-remote', | ||
const envDict = { | ||
BUILD_URI: 'the-url', | ||
BUILD_BUILDURI: 'the-url', | ||
BUILD_REPOSITORY_URI: 'the-remote', | ||
BUILD_SOURCEBRANCH: 'refs/tags/v1.2.3', | ||
BUILD_SOURCEVERSION: 'the-revision', | ||
BUILD_BUILDNUMBER: '456', | ||
} | ||
@@ -124,2 +131,3 @@ | ||
url: 'the-url', | ||
buildNumber: '456', | ||
git: { | ||
@@ -134,2 +142,27 @@ remote: 'the-remote', | ||
}) | ||
it('extracts build number from url', () => { | ||
const envDict = { | ||
WERCKER_GIT_BRANCH: 'main', | ||
WERCKER_GIT_COMMIT: '057f8fe233b17629af084064c2a7b8d1dbb795ad', | ||
WERCKER_GIT_DOMAIN: 'github.com', | ||
WERCKER_GIT_OWNER: 'cucumber-ltd', | ||
WERCKER_GIT_REPOSITORY: 'shouty.rb', | ||
WERCKER_RUN_URL: 'https://cihost.com/path/to/build/629af084064c2', | ||
} | ||
const meta = createMeta('someTool', '1.2.3', envDict, ciDict) | ||
const ci: messages.Ci = { | ||
git: { | ||
branch: 'main', | ||
tag: undefined, | ||
remote: 'https://github.com/cucumber-ltd/shouty.rb.git', | ||
revision: '057f8fe233b17629af084064c2a7b8d1dbb795ad', | ||
}, | ||
name: 'Wercker', | ||
url: 'https://cihost.com/path/to/build/629af084064c2', | ||
buildNumber: '629af084064c2', | ||
} | ||
assert.deepStrictEqual(meta.ci, ci) | ||
}) | ||
}) |
@@ -1,9 +0,8 @@ | ||
import createMeta from '../src/createMeta' | ||
import assert from 'assert' | ||
import evaluateVariableExpression from "../src/evaluateVariableExpression"; | ||
import evaluateVariableExpression from '../src/evaluateVariableExpression' | ||
describe('createMeta', () => { | ||
it('returns undefined when a variable is undefined', () => { | ||
const expression = "hello-${SOME_VAR}"; | ||
const result = evaluateVariableExpression(expression, {}); | ||
const expression = 'hello-${SOME_VAR}' | ||
const result = evaluateVariableExpression(expression, {}) | ||
assert.strictEqual(result, undefined) | ||
@@ -13,4 +12,4 @@ }) | ||
it('gets a value without replacement', () => { | ||
const expression = "${SOME_VAR}"; | ||
const result = evaluateVariableExpression(expression, {SOME_VAR: 'some_value'}); | ||
const expression = '${SOME_VAR}' | ||
const result = evaluateVariableExpression(expression, { SOME_VAR: 'some_value' }) | ||
assert.strictEqual(result, 'some_value') | ||
@@ -20,4 +19,4 @@ }) | ||
it('captures a group', () => { | ||
const expression = "${SOME_REF/refs\\/heads\\/(.*)/\\1}"; | ||
const result = evaluateVariableExpression(expression, {SOME_REF: 'refs/heads/main'}); | ||
const expression = '${SOME_REF/refs\\/heads\\/(.*)/\\1}' | ||
const result = evaluateVariableExpression(expression, { SOME_REF: 'refs/heads/main' }) | ||
assert.strictEqual(result, 'main') | ||
@@ -27,4 +26,6 @@ }) | ||
it('works with star wildcard in var', () => { | ||
const expression = "${GO_SCM_*_PR_BRANCH/.*:(.*)/\\1}"; | ||
const result = evaluateVariableExpression(expression, {GO_SCM_MY_MATERIAL_PR_BRANCH: 'ashwankthkumar:feature-1'}); | ||
const expression = '${GO_SCM_*_PR_BRANCH/.*:(.*)/\\1}' | ||
const result = evaluateVariableExpression(expression, { | ||
GO_SCM_MY_MATERIAL_PR_BRANCH: 'ashwankthkumar:feature-1', | ||
}) | ||
assert.strictEqual(result, 'feature-1') | ||
@@ -34,6 +35,9 @@ }) | ||
it('evaluates a complex expression', () => { | ||
const expression = "hello-${VAR1}-${VAR2/(.*) (.*)/\\2-\\1}-world"; | ||
const result = evaluateVariableExpression(expression, {VAR1: "amazing", VAR2: "gorgeous beautiful"}); | ||
const expression = 'hello-${VAR1}-${VAR2/(.*) (.*)/\\2-\\1}-world' | ||
const result = evaluateVariableExpression(expression, { | ||
VAR1: 'amazing', | ||
VAR2: 'gorgeous beautiful', | ||
}) | ||
assert.strictEqual(result, 'hello-amazing-beautiful-gorgeous-world') | ||
}) | ||
}) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
54
1117
89275
+ Added@cucumber/messages@17.1.1(transitive)
+ Added@types/uuid@8.3.1(transitive)
- Removed@cucumber/messages@16.0.1(transitive)
- Removed@types/uuid@8.3.0(transitive)
Updated@cucumber/messages@^17.0.0