diff --git a/packages/cypress-cloud/lib/ciProvider/__tests__/ciProvider.test.ts b/packages/cypress-cloud/lib/ciProvider/__tests__/ciProvider.test.ts new file mode 100644 index 0000000..4d5dadb --- /dev/null +++ b/packages/cypress-cloud/lib/ciProvider/__tests__/ciProvider.test.ts @@ -0,0 +1,14 @@ +import { getCommitDefaults } from "../merge"; + +describe("ciProvider", () => { + it("should resolve when provider is null and ghaEventDatais null", () => { + // eslint-disable-next-line turbo/no-undeclared-env-vars + process.env.TEAMCITY_VERSION = "1"; + const result = getCommitDefaults({ + ghaEventData: null, + }); + expect(result).toEqual({ + ghaEventData: null, + }); + }); +}); diff --git a/packages/cypress-cloud/lib/ciProvider.ts b/packages/cypress-cloud/lib/ciProvider/ciProvider.ts similarity index 95% rename from packages/cypress-cloud/lib/ciProvider.ts rename to packages/cypress-cloud/lib/ciProvider/ciProvider.ts index 187ee34..d38ce99 100644 --- a/packages/cypress-cloud/lib/ciProvider.ts +++ b/packages/cypress-cloud/lib/ciProvider/ciProvider.ts @@ -28,10 +28,10 @@ SOFTWARE. */ import debugFn from "debug"; - import _ from "lodash"; -import { ValidationError } from "./errors"; -import { GhaEventData } from "./git"; + +import { ValidationError } from "../errors"; +import { GhaEventData } from "../git"; const debug = debugFn("currents:ci"); @@ -641,7 +641,7 @@ const _providerCommitParams = (): ProviderCommitParamsRes => { }; }; -type CiProviderData = { +export type CiProviderData = { sha?: string; branch?: string; message?: string; @@ -651,7 +651,7 @@ type CiProviderData = { defaultBranch?: string; remoteBranch?: string; runAttempt?: string; - ghaEventData?: GhaEventData; + ghaEventData?: GhaEventData | null; }; interface ProviderCommitParamsRes { @@ -726,36 +726,3 @@ export function getCI(ciBuildId?: string) { provider, }; } - -export function getCommitDefaults(existingInfo: CiProviderData) { - debug("git commit existing info"); - debug(existingInfo); - - const commitParamsObj = getCommitParams(); - - debug("commit info from provider environment variables: %O", commitParamsObj); - - // based on the existingInfo properties - // merge in the commitParams if null or undefined - // defaulting back to null if all fails - // NOTE: only properties defined in "existingInfo" will be returned - const combined = _.transform( - existingInfo, - ( - memo: { [memoKey: string]: string | GhaEventData | null }, - value: string | GhaEventData | null, - key: string - ) => { - return (memo[key] = _.defaultTo( - value || - (commitParamsObj ? commitParamsObj[key as keyof CiProvider] : null), - null - )); - } - ); - - debug("combined git and environment variables from provider"); - debug(combined); - - return combined; -} diff --git a/packages/cypress-cloud/lib/ciProvider/index.ts b/packages/cypress-cloud/lib/ciProvider/index.ts new file mode 100644 index 0000000..8eccac5 --- /dev/null +++ b/packages/cypress-cloud/lib/ciProvider/index.ts @@ -0,0 +1 @@ +export * from "./merge"; diff --git a/packages/cypress-cloud/lib/ciProvider/merge.ts b/packages/cypress-cloud/lib/ciProvider/merge.ts new file mode 100644 index 0000000..fce1271 --- /dev/null +++ b/packages/cypress-cloud/lib/ciProvider/merge.ts @@ -0,0 +1,40 @@ +import debugFn from "debug"; +import _ from "lodash"; + +import { GhaEventData } from "../git"; +import { CiProvider, CiProviderData, getCommitParams } from "./ciProvider"; + +const debug = debugFn("currents:ci"); + +export function getCommitDefaults(existingInfo: CiProviderData) { + debug("git commit existing info"); + debug(existingInfo); + + const commitParamsObj = getCommitParams(); + + debug("commit info from provider environment variables: %O", commitParamsObj); + + // based on the existingInfo properties + // merge in the commitParams if null or undefined + // defaulting back to null if all fails + // NOTE: only properties defined in "existingInfo" will be returned + const combined = _.transform( + existingInfo, + ( + memo: { [memoKey: string]: string | GhaEventData | null }, + value: string | GhaEventData | null, + key: string + ) => { + return (memo[key] = _.defaultTo( + value || + (commitParamsObj ? commitParamsObj[key as keyof CiProvider] : null), + null + )); + } + ); + + debug("combined git and environment variables from provider"); + debug(combined); + + return combined; +}