Skip to content

Commit

Permalink
fix(config): allow no platform as input
Browse files Browse the repository at this point in the history
Signed-off-by: kilianpaquier <kilian@kilianpaquier.com>
  • Loading branch information
kilianpaquier committed Oct 26, 2024
1 parent acaa328 commit 6e2ced6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
2 changes: 1 addition & 1 deletion lib/models/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export enum Platform {
GITEA = "gitea",
GITHUB = "github",
GITLAB = "gitlab",
NULL = "",
NULL = "null",
}

/**
Expand Down
8 changes: 4 additions & 4 deletions lib/verify-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ const validTargetsArray = (targets: Partial<Target>[]): boolean => targets.
/**
* validPlatform validates an input string platform.
*
* @param stringPlatform the platform to validate.
* @param input the platform to validate.
*
* @returns true if the input platform is valid.
*/
const validPlatform = (stringPlatform: string): boolean => Boolean(Object.values(Platform).
find(platform => platform.toString() === stringPlatform))
const validPlatform = (input: Platform): boolean => Boolean(Object.values(Platform).
find(platform => input === platform))

/**
* ensureDefaults takes as input a partial backmerge configuration, alongside environment variables
Expand Down Expand Up @@ -73,7 +73,7 @@ export const verifyConfig = (config: BackmergeConfig): void => {
commit: [isString, stringNotEmpty],
debug: [isBoolean], // shouldn't happen since it comes from semantic-release config
dryRun: [isBoolean], // shouldn't happen since it comes from semantic-release config
platform: [isString, validPlatform],
platform: [validPlatform],
repositoryUrl: [isString, stringNotEmpty], // shouldn't happen since it comes from semantic-release config
targets: [isArray, validTargetsArray],
title: [isString, stringNotEmpty],
Expand Down
10 changes: 4 additions & 6 deletions test/verify-config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,20 +186,18 @@ describe("verifyConfig", () => {
matcher.toThrowError(getConfigError("targets", targets).message)
})

test("should throw an invalid platform with base url", () => {
test("should be fine with minimal inputs", () => {
// Arrange
const config = ensureDefault({
baseUrl: "https://example.com",
}, { GITHUB_TOKEN: "some token" })
const config = ensureDefault({ repositoryUrl: "some repository url" }, { GITHUB_TOKEN: "some token" })

// Act
const matcher = expect(() => verifyConfig(config))

// Assert
matcher.toThrowError(getConfigError("platform", "").message)
matcher.not.toThrowError()
})

test("should be fine with base url", () => {
test("should be fine with some inputs", () => {
// Arrange
const config = ensureDefault({
baseUrl: "https://example.com",
Expand Down

0 comments on commit 6e2ced6

Please sign in to comment.