Repository navigation
Expand file tree
/
Copy pathtypes.ts
More file actions
175 lines (165 loc) · 5.41 KB
/
Copy pathtypes.ts
File metadata and controls
175 lines (165 loc) · 5.41 KB
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
// the same loose shape @actions/github's WebhookPayload has, owned here so the
// handlers do not import from @actions/*
export interface PayloadRepository {
[key: string]: any
full_name?: string
name: string
owner: {
[key: string]: any
login: string
name?: string
}
html_url?: string
}
export interface WebhookPayload {
[key: string]: any
repository?: PayloadRepository
issue?: {
[key: string]: any
number: number
html_url?: string
body?: string
}
pull_request?: {
[key: string]: any
number: number
html_url?: string
body?: string
}
sender?: {
[key: string]: any
type: string
}
action?: string
installation?: {
id: number
[key: string]: any
}
comment?: {
id: number
[key: string]: any
}
}
/**
* Context is the event being handled: the GitHub event name, its webhook
* payload and the repository it concerns. Handlers read nothing else from the
* runtime, so every adapter (GitHub Actions today) builds one of these from
* whatever it receives.
*/
export interface Context {
eventName: string
payload: WebhookPayload
repo: { owner: string, repo: string }
}
/** the configuration inputs a handler may ask for; `action.yml` lists the same seven */
export type InputName
= | 'github-token'
| 'prow-commands'
| 'jobs'
| 'dry-run'
| 'merge-method'
| 'config'
| 'cat-api-key'
export interface Inputs {
/** returns the trimmed value, '' when unset; with `required` throws when unset */
get: (name: InputName, options?: { required?: boolean }) => string
}
export interface Logger {
debug: (message: string) => void
info: (message: string) => void
/** a message surfaced prominently by the runtime, e.g. an annotation on Actions */
notice: (message: string) => void
warning: (message: string) => void
error: (message: string) => void
/** asks the runtime to redact the value from its logs */
setSecret: (value: string) => void
}
/**
* RunState is everything a handler memoizes for the duration of one event:
* configuration, repository labels, OWNERS trees and the warnings already
* shown. An adapter creates one per event so that nothing leaks across events
* or repositories in a long-lived process. Values are `unknown`-typed promises
* on purpose: the owning module casts, and this file imports nothing from it.
*/
export interface RunState {
configs: Map<string, Promise<unknown>>
repoLabels: Map<string, Promise<string[]>>
ownerGroups: Map<string, Promise<string[]>>
ownerWarnings: Set<string>
trees: Map<string, Promise<unknown>>
hasOwners: Map<string, Promise<boolean>>
pullRequestOwners: Map<string, Promise<unknown>>
pullRequestTips: Map<string, Promise<string>>
/** org membership and collaborator answers, per repository and login */
authChecks: Map<string, Promise<boolean>>
/** the logins that commented on an issue, lower-cased */
issueCommenters: Map<string, Promise<string[]>>
/** the root OWNERS file of the default branch, '' when there is none */
rootOwners: Map<string, Promise<string>>
/** the github clients built from the token input */
clients: Map<string, unknown>
tideEvaluated: Set<number>
/** the token's own login, keyed by API root: one token per event */
tokenLogins: Map<string, Promise<string | undefined>>
warned: Set<'merge-queue-unavailable' | 'merge-method-ignored'>
}
export function newRunState(): RunState {
return {
configs: new Map(),
repoLabels: new Map(),
ownerGroups: new Map(),
ownerWarnings: new Set(),
trees: new Map(),
hasOwners: new Map(),
pullRequestOwners: new Map(),
pullRequestTips: new Map(),
authChecks: new Map(),
issueCommenters: new Map(),
rootOwners: new Map(),
clients: new Map(),
tideEvaluated: new Set(),
tokenLogins: new Map(),
warned: new Set(),
}
}
/**
* Platform is everything a handler needs from the runtime it runs on. The
* GitHub Actions adapter backs it with `@actions/core`, `@actions/github` and
* the runner's `GITHUB_*` environment.
*/
export interface Platform {
inputs: Inputs
log: Logger
/** the event this run handles */
context: () => Context
/** the REST API root; differs on GitHub Enterprise Server */
apiBaseUrl: () => string
/** the name of the workflow currently running, when the runtime has one */
currentWorkflowName: () => string | undefined
/** marks the run as failed with the given message */
fail: (message: string) => void
/** the memoized state of the event being handled */
state: () => RunState
/** what the runtime's token can and cannot do */
capabilities: () => Capabilities
/**
* defer waits `delayMs` and then continues. A runtime that may hold a
* request open (Actions, a Node server) resolves `continue` after the delay;
* one that may not (Workers) enqueues `resume` for later and resolves
* `deferred`, and the caller returns without doing the work now.
*/
defer: (delayMs: number, resume: Deferred) => Promise<'continue' | 'deferred'>
}
/** what to re-enter after a deferral; the Context is the event being handled */
export interface Deferred {
kind: 'require-matching-label'
context: Context
}
export interface Capabilities {
/**
* whether `pull_request` and `pull_request_review` events for a pull request
* from a fork come with a token that cannot write: true for GITHUB_TOKEN in
* an Actions run, false for a GitHub App's installation token
*/
readOnlyForkToken: boolean
}