You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+13-9Lines changed: 13 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,31 +1,35 @@
1
-
# Notabot
1
+
# Monorobot
2
2
3
-
Notifications bot server to receive notifications from webhooks and post them to slack
3
+
A Slackbot for GitHub monorepos. Configure how repo notifications should be routed to specified Slack channels based on file prefixes, issue/PR labels, and CI build statuses.
4
4
5
5
## Setting Up
6
6
7
-
Install dependencies, if needed:
7
+
Install dependencies via OPAM.
8
8
9
9
```sh
10
10
opam install --deps-only .
11
11
```
12
12
13
-
Build with
13
+
Then, build with Dune.
14
14
15
15
```sh
16
16
make
17
17
```
18
18
19
-
and use resulting `_build/default/src/notabot.exe` binary.
20
-
21
19
## Running
22
20
23
-
At startup time, secrets are read from the local `secrets.json` file. The main configuration is read remotely from a `notabot.json` file in the default branch, and its schema is defined in `lib/notabot.atd`.
21
+
Run the `_build/default/src/notabot.exe` binary. The following commands are supported.
22
+
23
+
-`run`: Launch the HTTP server
24
+
-`check_gh <GH_PAYLOAD>`: read a Github notification from a file and display the actions that will be taken (used for testing)
25
+
-`check_slack <SLACK_PAYLOAD> <SLACK_WEBHOOK>`: read a Slack notification from a file and send it to a webhook (used for testing)
24
26
25
27
### Documentation
26
28
27
-
*[config](./documentation/config_docs.md)
28
-
*[secret](./documentation/secret_docs.md)
29
+
The bot expects two configuration files to be present.
@@ -8,67 +8,30 @@ To update the configuration, simply edit the configuration file and push your ch
8
8
9
9
Refer [here](https://docs.github.com/en/free-pro-team@latest/developers/webhooks-and-events/webhook-events-and-payloads) for more information on GitHub event payload structure.
10
10
11
-
#Configuration values
11
+
## Options
12
12
13
-
**example**
13
+
**Example**
14
14
```json
15
15
{
16
16
"main_branch_name": "develop",
17
-
"status_rules": {
18
-
...
19
-
},
20
17
"prefix_rules": {
21
18
...
22
19
},
23
20
"label_rules": {
24
21
...
22
+
},
23
+
"status_rules": {
24
+
...
25
25
}
26
26
}
27
27
```
28
28
29
29
| value | description | optional | default |
30
30
|-|-|-|-|
31
31
|`main_branch_name`| main branch used for the repo; filtering notifications about merges of main into other branches | Yes | - |
32
-
|`status_rules`| status rules config object | No | - |
33
32
|`label_rules`| label rules config object | No | - |
34
33
|`prefix_rules`| prefix rules config object | No | - |
35
-
36
-
## Status Config
37
-
38
-
**example**
39
-
```json
40
-
"status_rules": {
41
-
"allowed_pipelines": [
42
-
"default",
43
-
"buildkite/pipeline2"
44
-
],
45
-
"status": {
46
-
"pending": false,
47
-
"success": "once",
48
-
"failure": true,
49
-
"error": true,
50
-
"cancelled": "^\\(Build #[0-9]+ canceled by .+\\|Failed (exit status 255)\\)$"
51
-
}
52
-
},
53
-
```
54
-
55
-
| value | description | optional | default |
56
-
|-|-|-|-|
57
-
|`title`| if defines a whitelist of values for the github payload. If not specified, all is permitted. | Yes | - |
58
-
|`status`| a `status_state` config object | No | - |
59
-
60
-
### Status State
61
-
62
-
A json object with fields of bools for each status type.
63
-
64
-
| value | description | optional | default |
65
-
|-|-|-|-|
66
-
|`pending`|`true` to notify; `false` to ignore | No | - |
67
-
|`success`|`true` to notify; `false` to notify all; `"once"` to notify the first and ignore subsequent consecutive successes| No | - |
68
-
|`failure`|`true` to notify; `false` to ignore | No | - |
69
-
|`error`|`true` to notify; `false` to ignore | No | - |
70
-
|`cancelled`| provide regex to ignore `failure` notifications with a description that matches it | Yes | - |
71
-
34
+
|`status_rules`| status rules config object | No | - |
72
35
73
36
## Label Options
74
37
@@ -163,3 +126,101 @@ A **prefix rule** specifies whether or not a Slack channel should be notified, b
163
126
|`allow`| if commit files match any prefix in this list, they should be routed to the channel | Yes | all prefixes allowed if no list provided |
164
127
|`ignore`| if commit files match any prefix in this list, they shouldn't be routed to the channel (even if they match any allow prefixes) | Yes | - |
165
128
|`channel`| channel to use as webhook if the rule is matched | No | - |
129
+
130
+
## Status Options
131
+
132
+
Monorobot supports additional behavior for GitHub status notifications, which are typically triggered by CI builds. A payload of this type contains:
133
+
134
+
- A `context` field, whose value is the name of the CI pipeline the notificiation is about
135
+
- A `state` field, whose value is either `success`, `failure`, `pending`, or `error`
136
+
137
+
The following takes place when a status notification is received.
138
+
139
+
1. Check whether a status notification should be *allowed* for further processing or *ignored*, according to a list of **status rules**. The bot will check the list *in order*, and use the policy defined by the first rule that the notification satisfies. If no rule matches, the default behavior of the status state is used:
140
+
-`pending`: `ignore`
141
+
-`failure`: `allow`
142
+
-`error`: `allow`
143
+
-`success`: `allow_once`
144
+
1. For those payloads allowed by step 1, if it isn't a main branch build notification, route to the default channel to reduce spam in topic channels. Otherwise, check the notification commit's files according to the prefix rules.
145
+
146
+
Internally, the bot keeps track of the status of the last allowed payload, for a given pipeline and branch. This information is used to evaluate the status rules (see below).
147
+
148
+
**Example**
149
+
150
+
```json
151
+
"status_rules": {
152
+
"allowed_pipelines": [
153
+
"default",
154
+
"buildkite/pipeline2"
155
+
],
156
+
"rules": [
157
+
{
158
+
"on": ["failure"],
159
+
"when": {
160
+
"match": {
161
+
"field": "description",
162
+
"re": "^\\(Build #[0-9]+ canceled by .+\\|Failed (exit status 255)\\)$"
163
+
}
164
+
},
165
+
"policy": "ignore"
166
+
},
167
+
{ "on": ["pending"], "policy": "ignore"},
168
+
{ "on": ["failure", "error"], "policy": "allow"},
169
+
{ "on": ["success"], "policy": "allow_once"}
170
+
]
171
+
}
172
+
```
173
+
174
+
| value | description | optional | default |
175
+
|-|-|-|-|
176
+
|`allowed_pipelines`| a list of pipeline names; if specified, payloads whose pipeline name is not in the list will be ignored immediately, without checking the **status rules**; otherwise, all pipelines will be included in the status rule check | Yes | - |
177
+
|`rules`| a list of **status rules** to determine whether to *allow* or *ignore* a payload for further processing | No | - |
178
+
179
+
### Status Rules
180
+
181
+
A **status rule** specifies whether a GitHub status notification should generate a Slack notification, given the notification's status and the last allowed build status. There are three policy options for handling payloads:
182
+
183
+
-`allow`: Notify every time.
184
+
-`ignore`: Suppress every time.
185
+
-`allow_once`: Only notify if the last allowed status notification's build status for the given pipeline and branch differs from the current one. Useful for suppressing consecutive build success notifications.
186
+
187
+
For example, the rule:
188
+
```
189
+
{ "on": A, "when": B, "policy": C }
190
+
```
191
+
is interpreted as:
192
+
193
+
> "on a notification with a build state in `A`, when condition `B` is met, adopt the policy `C`".
194
+
195
+
| value | description | optional | default |
196
+
|-|-|-|-|
197
+
|`on`| a list of build states that can trigger this rule | No | - |
198
+
|`when`| a **status condition** object which, if specified, must be true for the rule to match | Yes | - |
199
+
|`policy`| a policy option (one of `allow`, `ignore`, `allow_once`) | No | - |
200
+
201
+
### Status Conditions
202
+
203
+
You can optionally provide a **status condition** to specify additional requirements that a notification payload should meet, in order for a status rule's policy to apply.
204
+
205
+
-`all_of`: Matches if every sub-condition in a list is true. Value should be the list of sub-conditions.
206
+
-`one_of`: Matches if at least one sub-condition in a list is true. Value should be the list of sub-conditions.
207
+
```json
208
+
{
209
+
"all_of/one_of": [ condition1, condition2, ...]
210
+
}
211
+
```
212
+
-`not`: Matches if a sub-condition is false. Value should be the sub-condition.
213
+
```json
214
+
{
215
+
"not": condition
216
+
}
217
+
```
218
+
-`match`: Matches a text field in the payload against a regular expression. Value should be an object of the form:
0 commit comments