Repository: mukund-murali/bitbucket-webhooks (language: python)

Issue:
How to get branch name on repo push?
Hey great library! I'm trying to use `repo_push` but I cannot find how to get the branch name where the changes were pushed?

I was checking the [event_schemas](https://github.com/mukund-murali/bitbucket-webhooks/blob/master/bitbucket_webhooks/event_schemas.py#L7) for `RepoPush` and it doesn't seem to have it.

So the question is. Can I know to which branch something was pushed?

Thanks!


Discussion / hints:
Hi @Woile , thank you! So, the event [payload](https://support.atlassian.com/bitbucket-cloud/docs/event-payloads/) has the branch info under the `push` key. But it's getting currently excluded. I'll include the extra fields, but you'll have to process the data by yourself in your application.

I'll make the change by tonight. But if you want it earlier, please feel free to raise a PR.
Thanks! No rush at all, I'm evaluating if I can use. I like the design here is simple :)

Fix patch:
diff --git a/.gitignore b/.gitignore
index 3481434..aa93c90 100644
--- a/.gitignore
+++ b/.gitignore
@@ -129,4 +129,7 @@ dmypy.json
 .pyre/
 
 # Editor
-.vscode
\ No newline at end of file
+.vscode
+
+
+.DS_Store
\ No newline at end of file
diff --git a/bitbucket_webhooks/base_schemas.py b/bitbucket_webhooks/base_schemas.py
index 8691975..5372b44 100644
--- a/bitbucket_webhooks/base_schemas.py
+++ b/bitbucket_webhooks/base_schemas.py
@@ -41,7 +41,7 @@ class Meta:
     name = mo.fields.String()
 
 
-class Commit(mo.Model):
+class CommitHash(mo.Model):
     class Meta:
         unknown = mo.EXCLUDE
 
@@ -54,7 +54,7 @@ class Meta:
 
     repository = mo.NestedModel(Repository)
     branch = mo.NestedModel(Branch)
-    commit = mo.NestedModel(Commit)
+    commit = mo.NestedModel(CommitHash)
 
 
 class Participant(mo.Model):
@@ -79,7 +79,7 @@ class Meta:
     author = mo.NestedModel(User)
     source = mo.NestedModel(ChangeLocation)
     destination = mo.NestedModel(ChangeLocation)
-    merge_commit = mo.NestedModel(Commit, allow_none=True)
+    merge_commit = mo.NestedModel(CommitHash, allow_none=True)
     participants = mo.fields.List(mo.NestedModel(Participant))
     reviewers = mo.fields.List(mo.NestedModel(User))
     closed_by = mo.NestedModel(User, allow_none=True)
@@ -126,3 +126,23 @@ class Meta:
     inline = mo.NestedModel(InlineComment)
     created_on = mo.fields.DateTime()
     updated_on = mo.fields.DateTime()
+
+
+class RepoPushChange(mo.Model):
+    class Meta:
+        unknown = mo.EXCLUDE
+
+    new = mo.fields.Dict()
+    old = mo.fields.Dict()
+    links = mo.fields.Dict()
+    created = mo.fields.Bool()
+    forced = mo.fields.Bool()
+    closed = mo.fields.Bool()
+    commits = mo.fields.List(mo.fields.Dict())
+
+
+class RepoPushData(mo.Model):
+    class Meta:
+        unknown = mo.EXCLUDE
+
+    changes = mo.fields.List(mo.NestedModel(RepoPushChange))
diff --git a/bitbucket_webhooks/event_schemas.py b/bitbucket_webhooks/event_schemas.py
index b0cf300..b44344c 100644
--- a/bitbucket_webhooks/event_schemas.py
+++ b/bitbucket_webhooks/event_schemas.py
@@ -10,6 +10,7 @@ class Meta:
 
     actor = mo.NestedModel(base_schemas.User)
     repository = mo.NestedModel(base_schemas.Repository)
+    push = mo.NestedModel(base_schemas.RepoPushData)
 
 
 # Pull request events
diff --git a/setup.py b/setup.py
index 8e714cf..bb70b42 100644
--- a/setup.py
+++ b/setup.py
@@ -11,7 +11,7 @@
 
 setup(
     name="bitbucket-webhooks",
-    version="0.0.10",
+    version="0.0.11",
     description="Routes bitbucket webhook API event payloads to consumable decorators with payload serialized to python objects.",
     long_description=long_description,
     long_description_content_type="text/markdown",


Test patch:
diff --git a/tests/test_router.py b/tests/test_router.py
index 67593df..0ecad60 100644
--- a/tests/test_router.py
+++ b/tests/test_router.py
@@ -19,6 +19,9 @@ def test_num_handlers() -> None:
 @hooks.repo_push
 def _repo_push_handler_1(event: event_schemas.RepoPush) -> str:
     assert event.repository.name == "webhook-test-project"
+    change = event.push.changes[0]
+    assert change.new["name"] == "test-branch"
+    assert change.commits[0]["message"] == "Add new line\n"
     return "repo_pushed_1"