-
-
Notifications
You must be signed in to change notification settings - Fork 362
/
dslGenerator.ts
62 lines (54 loc) · 1.79 KB
/
dslGenerator.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import { Platform } from "../platforms/platform"
import { DangerDSLJSONType } from "../dsl/DangerDSL"
import { CliArgs } from "../dsl/cli-args"
import { CISource } from "../ci_source/ci_source"
import { emptyGitJSON } from "../platforms/github/GitHubGit"
import { Command } from "commander"
export const jsonDSLGenerator = async (
platform: Platform,
source: CISource,
program: Command
): Promise<DangerDSLJSONType> => {
const useSimpleDSL = platform.getPlatformReviewSimpleRepresentation && source.useEventDSL
const git = useSimpleDSL ? emptyGitJSON() : await platform.getPlatformGitRepresentation()
const getDSLFunc = useSimpleDSL
? platform.getPlatformReviewSimpleRepresentation
: platform.getPlatformReviewDSLRepresentation
const platformDSL = await getDSLFunc!()
const cliArgs: CliArgs = {
base: program.base,
dangerfile: program.dangerfile,
externalCiProvider: program.externalCiProvider,
id: program.id,
textOnly: program.textOnly,
verbose: program.verbose,
staging: program.staging,
}
const dslPlatformName = jsonDSLPlatformName(platform)
return {
git,
[dslPlatformName]: platformDSL,
settings: {
github: {
accessToken: process.env["DANGER_GITHUB_API_TOKEN"] || process.env["GITHUB_TOKEN"] || "NO_TOKEN",
additionalHeaders: {},
baseURL: process.env["DANGER_GITHUB_API_BASE_URL"] || process.env["GITHUB_URL"] || undefined,
},
cliArgs,
},
}
}
const jsonDSLPlatformName = (platform: Platform): string => {
switch (platform.name) {
case "BitBucketServer":
return "bitbucket_server"
case "BitBucketCloud":
return "bitbucket_cloud"
case "GitLab":
return "gitlab"
case "GitHub":
return "github"
default:
return platform.name.split(" ").join("_")
}
}