Skip to content

Commit fa53571

Browse files
authored
Merge pull request #92 from ahrefs/yasu/modular-context
Modularize dependencies for GH payload consumption and Slack message sending
2 parents 7a64f21 + 7858bdd commit fa53571

21 files changed

+643
-870
lines changed

documentation/config_docs.md

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
1-
# About
1+
# Repository Configuration
22

3-
Config file is where the variables affecting the behaviour of notabot are defined.
3+
A repository configuration file specifies how notifications should be handled for a given repository. It should be at the root of your monorepo in the main branch. The bot will look for a `notabot.json` file by default, but you can change this behavior with the `--config` flag.
4+
5+
When the bot receives its first incoming GitHub notification, it will query the repository URL to retrieve its configuration file. For subsequent notifications, it will use the cached configuration unless an update is detected.
6+
7+
To update the configuration, simply edit the configuration file and push your changes to GitHub. The bot will detect and apply those changes to the configuration, and will be reflected in the next request onwards.
8+
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.
410

511
# Configuration values
612

713
**example**
814
```json
915
{
10-
"offline": "github-api-cache",
1116
"main_branch_name": "develop",
1217
"status_rules": {
1318
...
@@ -17,16 +22,13 @@ Config file is where the variables affecting the behaviour of notabot are define
1722
},
1823
"label_rules": {
1924
...
20-
},
21-
"suppress_cancelled_events": true
25+
}
2226
}
2327
```
2428

2529
| value | description | optional | default |
2630
|-|-|-|-|
2731
| `main_branch_name` | main branch used for the repo; filtering notifications about merges of main into other branches | Yes | - |
28-
| `offline` | path to github api data when http calls are not allowed; used for testing | Yes | - |
29-
| `suppress_cancelled_events` | supresses status cancelled events | Yes | `true` |
3032
| `status_rules` | status rules config object | No | - |
3133
| `label_rules` | label rules config object | No | - |
3234
| `prefix_rules` | prefix rules config object | No | - |
@@ -68,11 +70,11 @@ A json object with fields of bools for each status type.
6870
| `cancelled` | provide regex to ignore `failure` notifications with a description that matches it | Yes | - |
6971

7072

71-
## Label Config
73+
## Label Options
7274

73-
Label rules apply to PR and issues notifications.
75+
**Label rules** apply to PR and issue notifications. If a payload matches multiple rules, they are all included.
7476

75-
**example**
77+
**Example**
7678
```json
7779
"label_rules": {
7880
"default_channel": "default",
@@ -81,21 +83,18 @@ Label rules apply to PR and issues notifications.
8183
"allow": [
8284
"backend"
8385
],
84-
"ignore": [],
8586
"channel": "backend"
8687
},
8788
{
8889
"allow": [
8990
"a1"
9091
],
91-
"ignore": [],
9292
"channel": "a1-bot"
9393
},
9494
{
9595
"allow": [
9696
"a3"
9797
],
98-
"ignore": [],
9998
"channel": "a3"
10099
},
101100
{
@@ -113,24 +112,24 @@ Label rules apply to PR and issues notifications.
113112

114113
| value | description | optional | default |
115114
|-|-|-|-|
116-
| `default_channel` | default channel to notify if no rules match | Yes | no channels will be notified on default |
115+
| `default_channel` | default channel to notify if no rules match | Yes | don't notify any channel |
117116
| `rules` | list of `label_rule` objects | No | - |
118117

119118
### Label Rule
120119

120+
A **label rule** specifies whether or not a Slack channel should be notified, based on the labels present in the given payload. For each rule, `ignore` is a blacklist of labels that should not notify the rule's channel, and `allow` is a whitelist of labels that should. If a label exists in both lists, the `ignore` list takes precedence. If an empty `ignore` list is provided, nothing is ignored. If an empty `allow` list is provided, everything is allowed. Both are optional; if neither are provided, the rule will always generate a notification for its channel.
121+
121122
| value | description | optional | default |
122123
|-|-|-|-|
123-
| `allow` | whitelist of label values that match this rule; if list is empty it vacuously satisfies the rule | No | - |
124-
| `ignore` | blacklist of label values; any labels matching will not match the rule | No | - |
125-
| `channel` | channel to use as webhook if matching this label rule | No | - |
126-
127-
## Prefix Config
124+
| `allow` | if notifications match any label in this list, they should be routed to the channel | Yes | all labels allowed if no list provided |
125+
| `ignore` | if notifications match any label in this list, they shouldn't be routed to the channel (even if they match any allow labels) | Yes | - |
126+
| `channel` | channel to use as webhook if the rule is matched | No | - |
128127

129-
Prefix rules apply to filenames. If a filename satisfies a prefix rule, the rule's channel will be notified.
128+
## Prefix Options
130129

131-
The prefix config object is exactly the same as **Label Config** except its `rules` are list of `prefix_rule` objects.
130+
**Prefix rules** apply to push, commit comment, and status notifications. If a filename satisfies a prefix rule, the rule's channel will be notified. If a filename matches multiple rules, only the one that is matched by the *longest prefix* is included.
132131

133-
**example**
132+
**Example**
134133
```json
135134
"prefix_rules": {
136135
"default_channel": "default",
@@ -139,31 +138,28 @@ The prefix config object is exactly the same as **Label Config** except its `rul
139138
"allow": [
140139
"backend/a1"
141140
],
142-
"ignore": [],
143141
"channel": "a1"
144142
},
145143
{
146144
"allow": [
147145
"backend/a5",
148146
"backend/a4"
149147
],
150-
"ignore": [],
151148
"channel": "backend"
152149
},
153150
{
154-
"allow": [],
155-
"ignore": [],
156151
"channel": "all-push-events"
157152
}
158153
]
159154
},
160155
```
161156

162-
163157
### Prefix Rule
164158

159+
A **prefix rule** specifies whether or not a Slack channel should be notified, based on the filenames present in the commits associated with the given payload. The semantics for the `allow` and `ignore` fields are the same as those for label rules (see above).
160+
165161
| value | description | optional | default |
166162
|-|-|-|-|
167-
| `allow` | whitelist of strings that if prefixed in the filename matches the rule | No | - |
168-
| `ignore` | blacklist of strings that if prefixed in the filename does not match the rule | No | - |
169-
| `channel` | channel to use as webhook if matching this prefix rule | No | - |
163+
| `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+
| `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+
| `channel` | channel to use as webhook if the rule is matched | No | - |

documentation/secret_docs.md

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
# About
1+
# Secrets
22

3-
Secret file is where sensitive information such as the urls used for webhooks and other tokens are stored.
3+
A secrets file stores sensitive information. Unlike the repository configuration file, it should not be checked into the monorepo's version control. Instead, store it locally at a location accessible by the bot.
44

5-
# Secret Values
5+
# Options
6+
7+
**Example**
68

7-
**example**
89
```json
910
{
1011
"slack_hooks": [
@@ -42,36 +43,14 @@ Secret file is where sensitive information such as the urls used for webhooks an
4243

4344
| value | description | optional | default |
4445
|-|-|-|-|
45-
| `slack_hooks` | list of webhook config objects | No | - |
46+
| `slack_hooks` | list of channel names (`channel`) and their corresponding webhook endpoint (`url`) | No | - |
4647
| `gh_token` | specify to grant the bot access to private repositories; omit for public repositories | Yes | - |
4748
| `gh_hook_token` | specify to ensure the bot only receives GitHub notifications from pre-approved repositories | Yes | - |
4849

4950
## `gh_token`
5051

51-
### Token generation
52-
53-
Some event notifications (e.g., status, commit comment) require a personal token to be addded to the configuration. To create a personal token, take the following steps:
54-
1. Verify your email address, if needed.
55-
1. In the upper-right corner of any page, click your profile photo, then click **Settings**.
56-
1. In the left sidebar, click **Developer settings**.
57-
1. In the left sidebar, click **Personal access tokens**.
58-
1. Click **Generate new token**.
59-
1. Give your token a descriptive name in the **Note** section.
60-
1. Grant ***repo*** scope.
61-
1. Click **Generate token**.
62-
1. Copy the token to `secrets.json` file in a `gh_token` field.
63-
64-
For more detailed instructions on token generation, refer to https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line.
65-
52+
Some operations, such as fetching a config file from a private repository, or the commit corresponding to a commit comment event, require a personal access token. Refer [here](https://docs.github.com/en/free-pro-team@latest/github/authenticating-to-github/creating-a-personal-access-token) for detailed instructions on token generation.
6653

6754
## `gh_hook_token`
68-
For more information on `gh_hook_token` see [developer.github.com/webhooks/securing](https://developer.github.com/webhooks/securing/)
6955

70-
## Webhook Config
71-
72-
Channels that are defined in rules in config will be mapped to urls defined in the webhook
73-
74-
| value | description | optional | default |
75-
|-|-|-|-|
76-
| `url` | url to call to send the message | No | - |
77-
| `channel` | name of the channel where the message will be posted as used in config | No | - |
56+
Refer [here](https://docs.github.com/en/free-pro-team@latest/developers/webhooks-and-events/securing-your-webhooks) for more information on securing webhooks with a token.

0 commit comments

Comments
 (0)