Skip to content

Commit bcb7d07

Browse files
committed
2 parents 4b0dfad + 26a263a commit bcb7d07

File tree

2 files changed

+54
-41
lines changed

2 files changed

+54
-41
lines changed

INSTALL.md

Lines changed: 21 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -8,39 +8,13 @@ To get this Azure Function working, you need to:
88

99
Once that is done, you can create an Actions workflow on any repository that the GitHub App is installed for, that listens for the `repository_dispatch` event, and does whatever you want it to do.
1010

11+
> ℹ️ when working with the Azure CLI, remember to use `az login` to log in to Azure, and `az logout` first if you are having problems
12+
1113
## Deploying the Azure Function
1214

1315
You need to create an Azure Function App, and deploy the Azure Function to it.
1416

15-
Before you deploy, you can choose to set a declarative filter for the GitHub events you want to listen for.
16-
17-
This is done in the `fiter.yml` file, with the format shown in `filter.yml.example` and below:
18-
19-
```yaml
20-
# Path: filter.yml
21-
22-
# filter webhook events by type and payload, declaratively
23-
24-
include:
25-
secret_scanning_alert:
26-
action: [created, dismissed, resolved, reopened]
27-
28-
exclude:
29-
secret_scanning_alert:
30-
action: reopened
31-
secret_scanning_alert_location:
32-
33-
```
34-
35-
The corresponding exclude filter for an event name is applied after the include filter.
36-
37-
This example will include any event named `secret_scanning_alert` with an action of `created`, `dismissed`, or `resolved`, `reopened` and will exclude any event named `secret_scanning_alert` with an action of `reopened`. It will also exclude any event named `secret_scanning_alert_location`.
38-
39-
The presence of an include filter here means that excluding `secret_scanning_alert_location` is redundant, as it will never be included in the first place, but it is included to show the syntax.
40-
41-
If you do not want to use a filter, you can delete the `filter.yml` file, or leave it empty.
42-
43-
You do not need to provide both an `include` and `exclude` key.
17+
Before you deploy, set a `filter.yml` if you wish to filter out certain events. See [filtering events](README.md#filtering-events) for more details.
4418

4519
### Creating the Functions App
4620

@@ -71,7 +45,6 @@ AZURE_LOCATION=<location>
7145
AZURE_STORAGE_ACCOUNT=<storage account name>
7246
AZURE_FUNCTION_APP_NAME=<function app name>
7347

74-
az login
7548
az account set --subscription "${AZURE_SUBSCRIPTION_ID}"
7649
az group create --name "${AZURE_RESOURCE_GROUP}" --location "${AZURE_LOCATION}"
7750
az storage account create --name "${AZURE_STORAGE_ACCOUNT}" --location "${AZURE_LOCATION}" --resource-group "${AZURE_RESOURCE_GROUP}" --sku Standard_LRS
@@ -97,7 +70,7 @@ Some of these steps assume you have zipped up the code of this function into `gi
9770
You can do that using:
9871

9972
```bash
100-
zip -r github-webhook-mirror.zip . -x 'node_modules/*' '.vscode/*' 'dist/*' 'local.settings.json' '.git/*' 'github-webhook-mirror.zip'
73+
zip -r github-webhook-mirror.zip . -x '.vscode/*' 'local.settings.json' '.git/*' '.github/*' '.gitignore' '.eslint*' '.funcignore' '*.md' 'CODEOWNERS' 'LICENSE' '*.ts' '*.js.map' 'jest.config.js' 'filter.yml.example' 'github-webhook-mirror.zip'
10174
```
10275

10376
#### Deploying with the Azure Portal
@@ -112,14 +85,22 @@ Select "Zip Deploy", and upload the `github-webhook-mirror.zip` file.
11285

11386
#### Deploying with the Azure CLI
11487

115-
> **TODO**: test this
88+
```bash
89+
AZURE_FUNCTION_APP_NAME=<function app name>
90+
91+
npm run build
92+
func azure functionapp publish "${AZURE_FUNCTION_APP_NAME}" || echo "Failed to publish function app, try running 'az logout' then 'az login', then try again"
93+
```
94+
95+
That may fail if it can't find the function app. If it does, you can try this alternative.
96+
97+
If you have already zipped up the code of this function into `github-webhook-mirror.zip`, you can use:
11698

11799
```bash
118100
AZURE_SUBSCRIPTION_ID=<subscription id>
119101
AZURE_RESOURCE_GROUP=<resource group name>
120102
AZURE_FUNCTION_APP_NAME=<function app name>
121103

122-
az login
123104
az account set --subscription "${AZURE_SUBSCRIPTION_ID}"
124105
az functionapp deployment source config-zip --resource-group "${AZURE_RESOURCE_GROUP}" --name "${AZURE_FUNCTION_APP_NAME}" --src github-webhook-mirror.zip
125106
```
@@ -148,14 +129,11 @@ That should take you to the Function App's page. You should see your Function li
148129

149130
#### Finding the Functions App's URL with the Azure CLI
150131

151-
> **TODO**: test this
152-
153132
```bash
154133
AZURE_SUBSCRIPTION_ID=<subscription id>
155134
AZURE_RESOURCE_GROUP=<resource group name>
156135
AZURE_FUNCTION_APP_NAME=<function app name>
157136

158-
az login
159137
az account set --subscription "${AZURE_SUBSCRIPTION_ID}"
160138
az functionapp show --resource-group "${AZURE_RESOURCE_GROUP}" --name "${AZURE_FUNCTION_APP_NAME}" --query "defaultHostName" --output tsv
161139
```
@@ -194,15 +172,16 @@ You will need a name, a description, a homepage URL (which can just be `https://
194172
- leave the option selected to "Enable SSL verification"
195173
- select the events you want to receive, by giving the app the relevant additional permissions, and then selecting which events should be sent to the webhook
196174
- ⚠️ carefully think about the security implications of giving _anyone with write access_ to your repository access to these events before you choose the events
197-
- click on the "Generate a private key" button. This will automatically download the private key as a `.pem` file. Save the private key somewhere safe - this is the only time you get to download it, and you will need it later
175+
- click on the "Generate a private key" button. This will automatically download the private key as a `.pem` file.
176+
- ⚠️ save the private key somewhere safe - _this is the only time you get to download it_, and you will need it later
198177

199178
[The full GitHub docs](https://docs.github.com/en/enterprise-cloud@latest/apps/creating-github-apps/registering-a-github-app/registering-a-github-app) can help you if you get stuck.
200179

201180
### Use the GitHub API to create a new GitHub App
202181

203182
> **TODO**
204183
205-
This is possible [using a manifest](https://docs.github.com/en/enterprise-cloud@latest/apps/sharing-github-apps/registering-a-github-app-from-a-manifest), but has not been implemented.
184+
This is possible [using a manifest](https://docs.github.com/en/enterprise-cloud@latest/apps/sharing-github-apps/registering-a-github-app-from-a-manifest), but has not yet been implemented here.
206185

207186
## Installing the GitHub App
208187

@@ -217,7 +196,9 @@ You need to install the GitHub App on an organization or repository.
217196

218197
> **TODO**
219198
220-
This is left until the creation of the app has been implemented.
199+
This has not been implemented yet.
200+
201+
This is left until the creation of the app using a manifest has been implemented.
221202

222203
### Configuring the Functions App
223204

@@ -252,7 +233,6 @@ AZURE_SUBSCRIPTION_ID=<subscription id>
252233
AZURE_RESOURCE_GROUP=<resource group name>
253234
AZURE_FUNCTION_APP_NAME=<function app name>
254235

255-
az login
256236
az account set --subscription "${AZURE_SUBSCRIPTION_ID}"
257-
az functionapp config appsettings import --name "${AZURE_FUNCTION_APP_NAME}" --resource-group "${AZURE_RESOURCE_GROUP}" --source local.settings.json
237+
az functionapp config appsettings set --name "${AZURE_FUNCTION_APP_NAME}" --resource-group "${AZURE_RESOURCE_GROUP}" --settings @local.settings.json
258238
```

README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,39 @@ sequenceDiagram
3333
- an Azure account on an Azure subscription
3434
- a GitHub account
3535

36+
## Filter events
37+
38+
Before you deploy, you can choose to set a declarative filter to apply to GitHub events you receive in the Azure Functions App. This is in addition to selecting the events you choose to listen for in the GitHub App.
39+
40+
This is done in the `fiter.yml` file, with the format shown in `filter.yml.example` and below:
41+
42+
```yaml
43+
# Path: filter.yml
44+
45+
# filter webhook events by type and payload, declaratively
46+
47+
include:
48+
secret_scanning_alert:
49+
action: [created, dismissed, resolved, reopened]
50+
51+
exclude:
52+
secret_scanning_alert:
53+
action: reopened
54+
secret_scanning_alert_location:
55+
56+
```
57+
58+
The corresponding exclude filter for an event name is applied after the include filter.
59+
60+
This example will include any event named `secret_scanning_alert` with an action of `created`, `dismissed`, or `resolved`, `reopened` and will exclude any event named `secret_scanning_alert` with an action of `reopened`. It will also exclude any event named `secret_scanning_alert_location`.
61+
62+
The presence of an include filter here means that excluding `secret_scanning_alert_location` is redundant, as it will never be included in the first place, but it is included to show the syntax.
63+
64+
If you do not want to use a filter, you can delete the `filter.yml` file, or leave it empty.
65+
66+
You do not need to provide both an `include` and `exclude` key.
67+
68+
3669
## Installing
3770

3871
See [INSTALL.md](INSTALL.md) for details.

0 commit comments

Comments
 (0)