/
index.ts
144 lines (127 loc) · 4.74 KB
/
index.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import { GitHubInstallationSettings } from "./GitHubRepoSettings"
/**
* Should look like one of the following:
* - "dangerfile.js"
* - "/path/to/dangerfile.ts"
* - "repo/slug@to/dangerfile.ts"
*/
export type DangerfileReferenceString = string
/**
* An event string would be something like:
* - "pull_request.*"
* - "pull_request.updated"
* - "ping"
* - "issue.*"
*/
export type PerilEventString = string
// TODO: Figure out how to separate things users put in settings, and stuff we need inside peril
/** An individual integration of Danger via Peril, this is like the org */
export interface GitHubInstallation extends PerilInstallationSettings {
/** The associated name of the installation owner */
login: string
/** An image url for the installation owner */
avatarURL: string
/** An image url for the installation owner */
envVars?: any
}
export interface PerilSettingsRepoJSON {
/**
* In our DB this is represented as a JSON type, so you should anticipate have settings
* as a nullable type. These are the entire installation settings.
*/
settings: GitHubInstallationSettings
/** Having rules in here would mean that it would happen on _any_ event, another JSON type in the DB */
rules: RunnerRuleset
/**
* Scheduled tasks to run using a cron-like syntax.
*
* This uses [node-schedule](https://github.com/node-schedule/node-schedule) under the hood. The
* object is similar to the rules section, in that you define a cron-string with the following format:
*
* * * * * * *
* ┬ ┬ ┬ ┬ ┬ ┬
* │ │ │ │ │ |
* │ │ │ │ │ └ day of week (0 - 7) (0 or 7 is Sun)
* │ │ │ │ └───── month (1 - 12)
* │ │ │ └────────── day of month (1 - 31)
* │ │ └─────────────── hour (0 - 23)
* │ └──────────────────── minute (0 - 59)
* └───────────────────────── second (0 - 59, OPTIONAL)
*
* Which would look something like:
*
* "scheduler": {
* "0 0 12 * * ?": "daily_at_twelve",
* "0 9 * * 1-5": "weekday_wakeup_email"
* }
*
* in practice. There's a lot of great resources on the net showing the general syntax. The values
* are tasks which are defined in the tasks object.
*/
scheduler: TaskObject
/**
* Individual tasks which a Peril can schedule, either via the Dangerfile API or via the
* scheduler object below.
*/
tasks: RunnerRuleset
/**
* A set of repos and their additional event hooks, these are
* in addition to the ones provided by `"rules"` which are applied
* to every repo.
*
* "repos" : {
* "orta/ORStackView": {
* "issue.created": "orta/peril@lock_issues.ts"
* }
* }
*
*/
repos: UniqueRepoRuleset
}
/** An individual integration of Danger via Peril, this is like the org */
export interface PerilInstallationSettings extends PerilSettingsRepoJSON {
/**
* The ID Integration, this is used when talking to GitHub mainly, but is used
* as a unique ID in our db
*/
iID: number
/**
* The path to the settings repo and json file
* e.g. danger/peril-settings@settings.json
*
* Filled in automatically when using JSON db, and
* is the initial string when working in the public mode
*/
perilSettingsJSONURL: DangerfileReferenceString
}
export interface UniqueRepoRuleset {
[name: string]: RunnerRuleset
}
export interface TaskObject {
[name: string]: string
}
export interface RunnerRuleset {
[name: string]: DangerfileReferenceString | DangerfileReferenceString[]
}
export interface GithubRepo {
/** The installation that this repo is connected to */
installationID: number
/** The full name of the slug for this repo, note these could not be unique (GitHub Enterprise?) */
fullName: string
/** Runner rules ID reference, another JSON type in the DB */
rules: RunnerRuleset
}
export interface DatabaseAdaptor {
/** A once per server start setup function */
setup: () => Promise<void>
/** Gets an integrations settings */
getInstallation: (installationID: number) => Promise<GitHubInstallation | null>
/** Updates an integrations settings */
updateInstallation: (installationID: number) => Promise<GitHubInstallation | null>
/** Saves an Integration */
saveInstallation: (installation: GitHubInstallation) => Promise<GitHubInstallation>
/** Deletes the operation */
deleteInstallation: (installationID: number) => Promise<void>
/** Gets an integrations settings */
getSchedulableInstallations: () => Promise<GitHubInstallation[]>
}