-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
60 additions
and
38 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
packages/cypress-cloud/lib/ciProvider/__tests__/ciProvider.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./merge"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |