Skip to content

Commit

Permalink
add gerrit (#106)
Browse files Browse the repository at this point in the history
  • Loading branch information
shubhbapna committed Jun 21, 2023
1 parent dcd068d commit 933a774
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 34 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
11 changes: 10 additions & 1 deletion src/domain/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ export interface Platform {

export enum PlatformType {
GITHUB = "github",
GITLAB = "gitlab"
GITLAB = "gitlab",
GERRIT = "gerrit"
}

export const DEFAULT_GITHUB_PLATFORM: Platform = {
Expand All @@ -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"
};
94 changes: 65 additions & 29 deletions src/schema/platform.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
DEFAULT_GERRIT_PLATFORM,
DEFAULT_GITHUB_PLATFORM,
DEFAULT_GITLAB_PLATFORM,
Platform,
Expand All @@ -17,15 +18,15 @@ export const PlatformSchema: JSONSchemaType<Platform> = {
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: {
type: "string",
},
type: {
type: "string",
enum: [PlatformType.GITHUB, PlatformType.GITLAB],
enum: [PlatformType.GITHUB, PlatformType.GITLAB, PlatformType.GERRIT],
},
apiUrl: {
type: "string",
Expand All @@ -35,37 +36,72 @@ export const PlatformSchema: JSONSchemaType<Platform> = {
}
},
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
}
},
},
}
]
};
2 changes: 1 addition & 1 deletion test/util/yaml.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down

0 comments on commit 933a774

Please sign in to comment.