|
1 | | -type JsonPrimitiveTypeTag = 'number' | 'string' | 'boolean' |
2 | | -type JsonArrayTypeTag = `${JsonPrimitiveTypeTag}[]` |
| 1 | +import { Struct, Str, Num, Bool, TypeDef } from '../types' |
3 | 2 |
|
4 | | -export type JsonTypeDef = |
5 | | - | JsonPrimitiveTypeTag |
6 | | - | JsonArrayTypeTag |
7 | | - | { [key: string]: JsonTypeDef } |
| 3 | +const userSchema = Struct({ |
| 4 | + login: Str(), |
| 5 | + id: Num(), |
| 6 | +}) |
8 | 7 |
|
9 | | -const abstractGithubIssueEventDef: JsonTypeDef = { |
10 | | - //action: 'string', |
11 | | - issue: { |
12 | | - id: 'number', |
13 | | - number: 'number', |
14 | | - title: 'string', |
15 | | - body: 'string', |
16 | | - state: 'string', |
17 | | - url: 'string', |
18 | | - html_url: 'string', |
19 | | - }, |
20 | | - repository: { |
21 | | - id: 'number', |
22 | | - name: 'string', |
23 | | - full_name: 'string', |
24 | | - url: 'string', |
25 | | - html_url: 'string', |
26 | | - private: 'boolean', |
27 | | - owner: { |
28 | | - login: 'string', |
29 | | - id: 'number', |
30 | | - }, |
31 | | - }, |
32 | | -} |
| 8 | +const issueSchema = Struct({ |
| 9 | + id: Num(), |
| 10 | + number: Num(), |
| 11 | + title: Str(), |
| 12 | + body: Str(), |
| 13 | + state: Str(), |
| 14 | + url: Str(), |
| 15 | + html_url: Str(), |
| 16 | +}) |
| 17 | + |
| 18 | +const repositorySchema = Struct({ |
| 19 | + id: Num(), |
| 20 | + name: Str(), |
| 21 | + full_name: Str(), |
| 22 | + url: Str(), |
| 23 | + html_url: Str(), |
| 24 | + private: Bool(), |
| 25 | + owner: userSchema, |
| 26 | +}) |
| 27 | + |
| 28 | +const labelSchema = Struct({ |
| 29 | + id: Num(), |
| 30 | + url: Str(), |
| 31 | + color: Str(), |
| 32 | + name: Str(), |
| 33 | +}) |
33 | 34 |
|
34 | | -const supportedEvents: Record<string, JsonTypeDef> = { |
35 | | - 'github.issues.opened': abstractGithubIssueEventDef, |
36 | | - 'github.issues.edited': { |
37 | | - ...abstractGithubIssueEventDef, |
38 | | - changes: { |
39 | | - body: { from: 'string' }, |
40 | | - title: { from: 'string' }, |
41 | | - }, |
42 | | - }, |
43 | | - 'github.issues.labeled': { |
44 | | - ...abstractGithubIssueEventDef, |
45 | | - label: { |
46 | | - id: 'number', |
47 | | - url: 'string', |
48 | | - color: 'string', |
49 | | - name: 'string', |
50 | | - default: 'boolean', |
51 | | - }, |
52 | | - }, |
| 35 | +const supportedEvents: Record<string, TypeDef<never>> = { |
| 36 | + 'github.issues.opened': Struct({ |
| 37 | + issue: issueSchema, |
| 38 | + repository: repositorySchema, |
| 39 | + }), |
| 40 | + 'github.issues.edited': Struct({ |
| 41 | + issue: issueSchema, |
| 42 | + repository: repositorySchema, |
| 43 | + changes: Struct({ |
| 44 | + body: Struct({ from: Str() }), |
| 45 | + title: Struct({ from: Str() }), |
| 46 | + }), |
| 47 | + }), |
| 48 | + 'github.issues.labeled': Struct({ |
| 49 | + action: Str(), |
| 50 | + issue: issueSchema, |
| 51 | + repository: repositorySchema, |
| 52 | + label: labelSchema, |
| 53 | + }), |
53 | 54 | } |
54 | 55 |
|
55 | 56 | export default supportedEvents |
0 commit comments