Skip to content

Commit 0da4a40

Browse files
committed
add option to restrict handling of GH payloads to certain repo urls
1 parent e2a6290 commit 0da4a40

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

lib/action.ml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,11 @@ module Action (Github_api : Api.Github) (Slack_api : Api.Slack) = struct
223223
let signing_key = Context.gh_hook_token_of_secrets secrets repo.url in
224224
Github.validate_signature ?signing_key ~headers body
225225
in
226+
let repo_is_allowed secrets payload =
227+
let repo = Github.repo_of_notification payload in
228+
let allowed_repositories = secrets.allowed_repositories in
229+
List.is_empty allowed_repositories || List.exists allowed_repositories ~f:(String.equal repo.url)
230+
in
226231
try%lwt
227232
let secrets = Context.get_secrets_exn ctx in
228233
match Github.parse_exn headers body with
@@ -231,6 +236,9 @@ module Action (Github_api : Api.Github) (Slack_api : Api.Slack) = struct
231236
match validate_signature secrets payload with
232237
| Error e -> action_error e
233238
| Ok () ->
239+
match repo_is_allowed secrets payload with
240+
| false -> action_error "unsupported repository"
241+
| true ->
234242
( match%lwt refresh_repo_config ctx payload with
235243
| Error e -> action_error e
236244
| Ok () ->

lib/config.atd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,5 @@ type secrets = {
4949
?gh_token : string option; (* GitHub personal access token, if repo access requires it *)
5050
?gh_hook_token : string option; (* GitHub webhook token to secure the webhook *)
5151
~repositories <ocaml default="Common.StringMap.empty"> : gh_repo_secrets map_as_object;
52+
~allowed_repositories <ocaml default="[]"> : string list; (* whitelist of repository URLs to handle notifications for *)
5253
}

0 commit comments

Comments
 (0)