mirror of
https://github.com/zulip/zulip.git
synced 2025-11-02 13:03:29 +00:00
gitlab: Fix event_name -> object_kind defaulting.
94457732c1 changed this from:
```py
event_name = payload.get("event_name", payload.get("object_kind")).tame(check_string)
```
...to:
```py
event_name = payload.get("event_name", payload["object_kind"]).tame(check_string)
```
Which causes a failure when `event_name` exists but `object_kind` does
not, since the default is evaluated first.
Switch to an `if` statement to clarify the fallbacks better.
This commit is contained in:
committed by
Anders Kaseorg
parent
a671ae9749
commit
d0c5389d60
32
zerver/webhooks/gitlab/fixtures/repository_update.json
Normal file
32
zerver/webhooks/gitlab/fixtures/repository_update.json
Normal file
@@ -0,0 +1,32 @@
|
||||
{
|
||||
"event_name": "repository_update",
|
||||
"user_id": 1,
|
||||
"user_name": "John Smith",
|
||||
"user_email": "admin@example.com",
|
||||
"user_avatar": "https://s.gravatar.com/avatar/d4c74594d841139328695756648b6bd6?s=8://s.gravatar.com/avatar/d4c74594d841139328695756648b6bd6?s=80",
|
||||
"project_id": 1,
|
||||
"project": {
|
||||
"name":"Example",
|
||||
"description":"",
|
||||
"web_url":"http://example.com/jsmith/example",
|
||||
"avatar_url":null,
|
||||
"git_ssh_url":"git@example.com:jsmith/example.git",
|
||||
"git_http_url":"http://example.com/jsmith/example.git",
|
||||
"namespace":"Jsmith",
|
||||
"visibility_level":0,
|
||||
"path_with_namespace":"jsmith/example",
|
||||
"default_branch":"master",
|
||||
"homepage":"http://example.com/jsmith/example",
|
||||
"url":"git@example.com:jsmith/example.git",
|
||||
"ssh_url":"git@example.com:jsmith/example.git",
|
||||
"http_url":"http://example.com/jsmith/example.git"
|
||||
},
|
||||
"changes": [
|
||||
{
|
||||
"before":"8205ea8d81ce0c6b90fbe8280d118cc9fdad6130",
|
||||
"after":"4045ea7a3df38697b3730a20fb73c8bed8a3e69e",
|
||||
"ref":"refs/heads/master"
|
||||
}
|
||||
],
|
||||
"refs":["refs/heads/master"]
|
||||
}
|
||||
@@ -496,7 +496,10 @@ def get_event(request: HttpRequest, payload: WildValue, branches: Optional[str])
|
||||
event = validate_extract_webhook_http_header(request, "X-GitLab-Event", "GitLab")
|
||||
if event == "System Hook":
|
||||
# Convert the event name to a GitLab event title
|
||||
event_name = payload.get("event_name", payload["object_kind"]).tame(check_string)
|
||||
if "event_name" in payload:
|
||||
event_name = payload["event_name"].tame(check_string)
|
||||
else:
|
||||
event_name = payload["object_kind"].tame(check_string)
|
||||
event = event_name.split("__")[0].replace("_", " ").title()
|
||||
event = f"{event} Hook"
|
||||
if event in ["Confidential Issue Hook", "Issue Hook", "Merge Request Hook", "Wiki Page Hook"]:
|
||||
|
||||
Reference in New Issue
Block a user