-
-
Notifications
You must be signed in to change notification settings - Fork 365
/
Codefresh.ts
69 lines (61 loc) · 1.75 KB
/
Codefresh.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
63
64
65
66
67
68
69
import { Env, CISource } from "../ci_source"
import { ensureEnvKeysExist, ensureEnvKeysAreInt } from "../ci_source_helpers"
/**
* ### CI Setup
*
* To set up Danger on Codefresh, create a freestyle step in your Codefresh yaml configuration:
*
* ```yml
* Danger:
* title: Run Danger
* image: node:latest
* working_directory: ${{main_clone}}
* entry_point: '/bin/bash'
* cmd:
* - '-ce'
* - |
* npm install -g yarn
* yarn add danger --dev
* yarn danger ci --failOnErrors
* when:
* steps:
* - name: main_clone
* on:
* - success
* ```
*
* The `failOnErrors` option is required in order to ensure that the step fails properly when Danger fails. If you don't wnat this behavior, you can remove this option.
*
* Don't forget to add the `DANGER_GITHUB_API_TOKEN` variable to your pipeline settings so that Danger can properly post comments to your pull request.
*
*/
export class Codefresh implements CISource {
constructor(private readonly env: Env) {}
get name(): string {
return "Codefresh"
}
get isCI(): boolean {
return ensureEnvKeysExist(this.env, ["CF_BUILD_ID", "CF_BUILD_URL"])
}
get isPR(): boolean {
return (
ensureEnvKeysExist(this.env, ["CF_PULL_REQUEST_NUMBER"]) &&
ensureEnvKeysAreInt(this.env, ["CF_PULL_REQUEST_NUMBER"])
)
}
get pullRequestID(): string {
if (this.env.CF_PULL_REQUEST_NUMBER) {
return this.env.CF_PULL_REQUEST_NUMBER
} else {
return ""
}
}
get repoSlug(): string {
const owner = this.env.CF_REPO_OWNER
const reponame = this.env.CF_REPO_NAME
return owner && reponame ? `${owner}/${reponame}` : ""
}
get ciRunURL() {
return this.env.CF_BUILD_URL
}
}