From 933a774a58e240327434fd04c21bbf7e8a4b9d42 Mon Sep 17 00:00:00 2001 From: Shubh Bapna <38372682+shubhbapna@users.noreply.github.com> Date: Wed, 21 Jun 2023 08:06:13 -0400 Subject: [PATCH] add gerrit (#106) --- package-lock.json | 4 +- package.json | 2 +- src/domain/platform.ts | 11 ++++- src/schema/platform.ts | 94 +++++++++++++++++++++++++++++------------- test/util/yaml.test.ts | 2 +- 5 files changed, 79 insertions(+), 34 deletions(-) diff --git a/package-lock.json b/package-lock.json index 2b4e82a..bf607c7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@kie/build-chain-configuration-reader", - "version": "3.1.3", + "version": "3.1.4", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@kie/build-chain-configuration-reader", - "version": "3.1.3", + "version": "3.1.4", "license": "Apache-2.0", "dependencies": { "ajv": "^8.11.0", diff --git a/package.json b/package.json index 76ba206..3e3ae1c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@kie/build-chain-configuration-reader", - "version": "3.1.3", + "version": "3.1.4", "description": "A library to read build-chain tool configuration files", "main": "build/src/index.js", "types": "build/src/index.d.ts", diff --git a/src/domain/platform.ts b/src/domain/platform.ts index 1cf23ce..fbd9a73 100644 --- a/src/domain/platform.ts +++ b/src/domain/platform.ts @@ -9,7 +9,8 @@ export interface Platform { export enum PlatformType { GITHUB = "github", - GITLAB = "gitlab" + GITLAB = "gitlab", + GERRIT = "gerrit" } export const DEFAULT_GITHUB_PLATFORM: Platform = { @@ -26,4 +27,12 @@ export const DEFAULT_GITLAB_PLATFORM: Platform = { serverUrl: "https://gitlab.com", apiUrl: "https://gitlab.com/api/v4", tokenId: "GITLAB_TOKEN" +}; + +export const DEFAULT_GERRIT_PLATFORM: Platform = { + id: "gerrit-public", + type: PlatformType.GERRIT, + serverUrl: "https://gerrit.googlesource.com", + apiUrl: "https://gerrit.googlesource.com", + tokenId: "GERRIT_TOKEN" }; \ No newline at end of file diff --git a/src/schema/platform.ts b/src/schema/platform.ts index c33cfae..3c53379 100644 --- a/src/schema/platform.ts +++ b/src/schema/platform.ts @@ -1,4 +1,5 @@ import { + DEFAULT_GERRIT_PLATFORM, DEFAULT_GITHUB_PLATFORM, DEFAULT_GITLAB_PLATFORM, Platform, @@ -17,7 +18,7 @@ export const PlatformSchema: JSONSchemaType = { type: "string", not: { type: "string", - enum: [DEFAULT_GITHUB_PLATFORM.id, DEFAULT_GITLAB_PLATFORM.id] + enum: [DEFAULT_GITHUB_PLATFORM.id, DEFAULT_GITLAB_PLATFORM.id, DEFAULT_GERRIT_PLATFORM.id] } }, serverUrl: { @@ -25,7 +26,7 @@ export const PlatformSchema: JSONSchemaType = { }, type: { type: "string", - enum: [PlatformType.GITHUB, PlatformType.GITLAB], + enum: [PlatformType.GITHUB, PlatformType.GITLAB, PlatformType.GERRIT], }, apiUrl: { type: "string", @@ -35,37 +36,72 @@ export const PlatformSchema: JSONSchemaType = { } }, required: ["apiUrl", "id", "type", "serverUrl", "tokenId"], - if: { - properties: { - type: { - enum: [PlatformType.GITHUB], + allOf: [ + { + if: { + properties: { + type: { + enum: [PlatformType.GITHUB], + }, + }, + }, + then: { + properties: { + apiUrl: { + default: DEFAULT_GITHUB_PLATFORM.apiUrl, + }, + serverUrl: { + default: DEFAULT_GITHUB_PLATFORM.serverUrl, + }, + tokenId: { + default: DEFAULT_GITHUB_PLATFORM.tokenId + } + }, }, }, - }, - then: { - properties: { - apiUrl: { - default: DEFAULT_GITHUB_PLATFORM.apiUrl, + { + if: { + properties: { + type: { + enum: [PlatformType.GITLAB], + }, + }, }, - serverUrl: { - default: DEFAULT_GITHUB_PLATFORM.serverUrl, + then: { + properties: { + apiUrl: { + default: DEFAULT_GITLAB_PLATFORM.apiUrl, + }, + serverUrl: { + default: DEFAULT_GITLAB_PLATFORM.serverUrl, + }, + tokenId: { + default: DEFAULT_GITLAB_PLATFORM.tokenId + } + }, }, - tokenId: { - default: DEFAULT_GITHUB_PLATFORM.tokenId - } - }, - }, - else: { - properties: { - apiUrl: { - default: DEFAULT_GITLAB_PLATFORM.apiUrl, + }, + { + if: { + properties: { + type: { + enum: [PlatformType.GERRIT], + }, + }, }, - serverUrl: { - default: DEFAULT_GITLAB_PLATFORM.serverUrl, + then: { + properties: { + apiUrl: { + default: DEFAULT_GERRIT_PLATFORM.apiUrl, + }, + serverUrl: { + default: DEFAULT_GERRIT_PLATFORM.serverUrl, + }, + tokenId: { + default: DEFAULT_GERRIT_PLATFORM.tokenId + } + }, }, - tokenId: { - default: DEFAULT_GITLAB_PLATFORM.tokenId - } - }, - }, + } + ] }; diff --git a/test/util/yaml.test.ts b/test/util/yaml.test.ts index 673b952..62dcdc6 100644 --- a/test/util/yaml.test.ts +++ b/test/util/yaml.test.ts @@ -448,7 +448,7 @@ describe("schema 2.3", () => { test.each([ ["incorrect version", 2.2, "github", "ghes"], - ["incorrect platform type", 2.3, "gerrit", "ghes"], + ["incorrect platform type", 2.3, "random", "ghes"], ["incorrect id. using reserved id", 2.3, "github", DEFAULT_GITHUB_PLATFORM.id] ])("failure: platforms validation with %p", async (_title, version, platformType, platformId) => { const data = {