Pydantic models for GitLab webhook payloads
Project description
Pydantic models for GitLab Webhooks
Module containing Pydantic models for validating bodies from GitLab webhook requests.
Usage
Intended usage is via a single validate_event_header_and_body
function which will validate an
incoming webhook's X-Gitlab-Event
header and the body after being parsed into a Python dict.
from pydantic import ValidationError
from pydantic_gitlab_webhooks import validate_event_header_and_body, validate_event_dict
event_body = {
"object_kind": "access_token",
"group": {
"group_name": "Twitter",
"group_path": "twitter",
"group_id": 35,
"full_path": "twitter"
},
"object_attributes": {
"user_id": 90,
"created_at": "2024-01-24 16:27:40 UTC",
"id": 25,
"name": "acd",
"expires_at": "2024-01-26"
},
"event_name": "expiring_access_token"
}
# Use the value of the "X-Gitlab-Event" header and event body to validate the incoming event.
parsed_event = validate_event_header_and_body(
"Resource Access Token Hook",
event_body
)
assert parsed_event.group.full_path == "twitter"
# Invalid event bodies or hook headers raise Pydantic validation errors
try:
validate_event_header_and_body("invalid hook", event_body)
except ValidationError:
pass # ok - expected error raised
else:
assert False, "ValidationError was not raised"
# Event bodies can be parsed without the header hook if necessary although using the hook header is
# more efficient.
parsed_event = validate_event_dict(event_body)
assert parsed_event.group.full_path == "twitter"
# Individual event models are available from the `pydantic_gitlab_webhooks.events` module. For
# example:
from pydantic_gitlab_webhooks.events import GroupAccessTokenEvent
parsed_event = GroupAccessTokenEvent.model_validate(event_body)
The available event models are:
CommitNoteEvent
DeploymentEvent
EmojiEvent
FeatureFlagEvent
GroupAccessTokenEvent
GroupMemberEvent
IssueEvent
IssueNoteEvent
JobEvent
MergeRequestEvent
MergeRequestNoteEvent
PipelineEvent
ProjectAccessTokenEvent
ProjectEvent
PushEvent
ReleaseEvent
SnippetNoteEvent
SubgroupEvent
TagPushEvent
WikiPageEvent
Making a release
From main
:
npx -p @release-it/conventional-changelog -p @release-it/bumper release-it
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pydantic_gitlab_webhooks-0.1.1.tar.gz
.
File metadata
- Download URL: pydantic_gitlab_webhooks-0.1.1.tar.gz
- Upload date:
- Size: 8.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 63be6f80d47c3cbfee3a9a01ad66e70d69a3d1f99806100ae2a34498d27825d6 |
|
MD5 | 78f5ddce092b1cc3f9bba2d597debb5e |
|
BLAKE2b-256 | fc3f207bca9a60b4cddcadfaf2cc215b9e5c934de424e944c1f5b3eb001bac4f |
Provenance
The following attestation bundles were made for pydantic_gitlab_webhooks-0.1.1.tar.gz
:
Publisher:
publish.yml
on rjw57/pydantic-gitlab-webhooks
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
pydantic_gitlab_webhooks-0.1.1.tar.gz
- Subject digest:
63be6f80d47c3cbfee3a9a01ad66e70d69a3d1f99806100ae2a34498d27825d6
- Sigstore transparency entry: 149251581
- Sigstore integration time:
- Predicate type:
File details
Details for the file pydantic_gitlab_webhooks-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: pydantic_gitlab_webhooks-0.1.1-py3-none-any.whl
- Upload date:
- Size: 12.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ec001f4e3af9e3a9d946a5c75bbc825c5ae3226f8e6be550464a839af2603cb7 |
|
MD5 | 6ad1d6da2fb65a723f4719c465f72962 |
|
BLAKE2b-256 | 202efbd093fb0fd5506030c68543bb8ffe72d8e196ab8a547f392f09112b7187 |
Provenance
The following attestation bundles were made for pydantic_gitlab_webhooks-0.1.1-py3-none-any.whl
:
Publisher:
publish.yml
on rjw57/pydantic-gitlab-webhooks
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
pydantic_gitlab_webhooks-0.1.1-py3-none-any.whl
- Subject digest:
ec001f4e3af9e3a9d946a5c75bbc825c5ae3226f8e6be550464a839af2603cb7
- Sigstore transparency entry: 149251582
- Sigstore integration time:
- Predicate type: