From d3f2c794124a7983bd458fffb402a53d8b62d6ac Mon Sep 17 00:00:00 2001 From: Yuta Hinokuma Date: Wed, 25 Oct 2017 22:46:01 +0900 Subject: [PATCH 1/9] use enum class --- github_webhook/event.py | 30 ++++++++++++++++++++++++++++++ github_webhook/webhook.py | 5 +++-- 2 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 github_webhook/event.py diff --git a/github_webhook/event.py b/github_webhook/event.py new file mode 100644 index 0000000..196de17 --- /dev/null +++ b/github_webhook/event.py @@ -0,0 +1,30 @@ +from enum import Enum + + +class Event(Enum): + """ + Event enum type + """ + COMMIT_COMMENT = 'commit_comment' + CREATE = 'create' + DELETE = 'delete' + DEPLOYMENT = 'deployment' + DEPLOYMENT_STATUS = 'deployment_status' + FORK = 'fork' + GOLLUM = 'gollum' + ISSUE_COMMENT = 'issue_comment' + ISSUES = 'issues' + MEMBER = 'member' + MEMBERSHIP = 'membership' + PAGE_BUILD = 'page_build' + PING = 'ping' + PUBLIC = 'public' + PULL_REQUEST = 'pull_request' + PULL_REQUEST_REVIEW = 'pull_request_review' + PULL_REQUEST_REVIEW_COMMENT = 'pull_request_review_comment' + PUSH = 'push' + RELEASE = 'release' + REPOSITORY = 'repository' + STATUS = 'status' + TEAM_ADD = 'team_add' + WATCH = 'watch' diff --git a/github_webhook/webhook.py b/github_webhook/webhook.py index 6486566..988f945 100644 --- a/github_webhook/webhook.py +++ b/github_webhook/webhook.py @@ -5,6 +5,7 @@ import six from flask import abort, request +from .event import Event class Webhook(object): @@ -26,7 +27,7 @@ def __init__(self, app, endpoint='/postreceive', secret=None): secret = secret.encode('utf-8') self._secret = secret - def hook(self, event_type='push'): + def hook(self, event_type=Event.push): """ Registers a function as a hook. Multiple hooks can be registered for a given type, but the order in which they are invoke is unspecified. @@ -35,7 +36,7 @@ def hook(self, event_type='push'): """ def decorator(func): - self._hooks[event_type].append(func) + self._hooks[event_type.value].append(func) return func return decorator From 472798d0125ca62b38a9e84b6881a3287cf7b4d5 Mon Sep 17 00:00:00 2001 From: Yuta Hinokuma Date: Wed, 25 Oct 2017 22:48:23 +0900 Subject: [PATCH 2/9] adaption python 2.7 --- requirements.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 requirements.txt diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..dc3292c --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +enum34 From 506ceba2e60a106b045249fe29490dd610e59096 Mon Sep 17 00:00:00 2001 From: Yuta Hinokuma Date: Wed, 25 Oct 2017 22:51:25 +0900 Subject: [PATCH 3/9] use Pascal case --- github_webhook/event.py | 46 ++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/github_webhook/event.py b/github_webhook/event.py index 196de17..7da8f81 100644 --- a/github_webhook/event.py +++ b/github_webhook/event.py @@ -5,26 +5,26 @@ class Event(Enum): """ Event enum type """ - COMMIT_COMMENT = 'commit_comment' - CREATE = 'create' - DELETE = 'delete' - DEPLOYMENT = 'deployment' - DEPLOYMENT_STATUS = 'deployment_status' - FORK = 'fork' - GOLLUM = 'gollum' - ISSUE_COMMENT = 'issue_comment' - ISSUES = 'issues' - MEMBER = 'member' - MEMBERSHIP = 'membership' - PAGE_BUILD = 'page_build' - PING = 'ping' - PUBLIC = 'public' - PULL_REQUEST = 'pull_request' - PULL_REQUEST_REVIEW = 'pull_request_review' - PULL_REQUEST_REVIEW_COMMENT = 'pull_request_review_comment' - PUSH = 'push' - RELEASE = 'release' - REPOSITORY = 'repository' - STATUS = 'status' - TEAM_ADD = 'team_add' - WATCH = 'watch' + Commit_comment = 'commit_comment' + Create = 'create' + Delete = 'delete' + Deployment = 'deployment' + Deployment_status = 'deployment_status' + Fork = 'fork' + Gollum = 'gollum' + Issue_comment = 'issue_comment' + Issues = 'issues' + Member = 'member' + Membership = 'membership' + Page_build = 'page_build' + Ping = 'ping' + Public = 'public' + Pull_request = 'pull_request' + Pull_request_review = 'pull_request_review' + Pull_request_review_comment = 'pull_request_review_comment' + Push = 'push' + Release = 'release' + Repository = 'repository' + Status = 'status' + Team_add = 'team_add' + Watch = 'watch' From b978f76a4e75b03040e3fd48b426871d2ce8d917 Mon Sep 17 00:00:00 2001 From: Yuta Hinokuma Date: Wed, 25 Oct 2017 22:51:42 +0900 Subject: [PATCH 4/9] fix case --- github_webhook/webhook.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github_webhook/webhook.py b/github_webhook/webhook.py index 988f945..b8db3c4 100644 --- a/github_webhook/webhook.py +++ b/github_webhook/webhook.py @@ -27,7 +27,7 @@ def __init__(self, app, endpoint='/postreceive', secret=None): secret = secret.encode('utf-8') self._secret = secret - def hook(self, event_type=Event.push): + def hook(self, event_type=Event.Push): """ Registers a function as a hook. Multiple hooks can be registered for a given type, but the order in which they are invoke is unspecified. From c44967084390ea1ef4959e5f1f59bc29955d9139 Mon Sep 17 00:00:00 2001 From: Yuta Hinokuma Date: Wed, 25 Oct 2017 23:03:03 +0900 Subject: [PATCH 5/9] add Event on __init__.py --- github_webhook/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github_webhook/__init__.py b/github_webhook/__init__.py index 89ffe17..0e102e2 100644 --- a/github_webhook/__init__.py +++ b/github_webhook/__init__.py @@ -8,7 +8,7 @@ :license: Apache License, Version 2.0 """ -from github_webhook.webhook import Webhook +from github_webhook.webhook import (Webhook, Event) # ----------------------------------------------------------------------------- # Copyright 2015 Bloomberg Finance L.P. From 4b348acfa8acb6d74510ee347eaa32825735aa8a Mon Sep 17 00:00:00 2001 From: Yuta Hinokuma Date: Wed, 25 Oct 2017 23:07:07 +0900 Subject: [PATCH 6/9] add Event on __init__.py --- github_webhook/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github_webhook/__init__.py b/github_webhook/__init__.py index 89ffe17..0e102e2 100644 --- a/github_webhook/__init__.py +++ b/github_webhook/__init__.py @@ -8,7 +8,7 @@ :license: Apache License, Version 2.0 """ -from github_webhook.webhook import Webhook +from github_webhook.webhook import (Webhook, Event) # ----------------------------------------------------------------------------- # Copyright 2015 Bloomberg Finance L.P. From 3c6dfb9dc8662230632c903ad16c63b7ac469e62 Mon Sep 17 00:00:00 2001 From: Yuta Hinokuma Date: Wed, 25 Oct 2017 23:08:06 +0900 Subject: [PATCH 7/9] modify README.md --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0f321c9..c25f2cc 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ orginally developed for Bloomberg's GHE install. receives push events all it takes is: ```py -from github_webhook import Webhook +from github_webhook import Webhook, Event from flask import Flask app = Flask(__name__) # Standard Flask app @@ -27,6 +27,12 @@ def hello_world(): def on_push(data): print("Got push with: {0}".format(data)) +@webhook.hook(event_type=Event.Ping) # Defines a handler for the 'ping' event +def on_push(data): + print("Got push with: {0}".format(data)) + + + if __name__ == "__main__": app.run(host="0.0.0.0", port=80) ``` From d016abefdc168c45b32d20078745bb9142b75d2c Mon Sep 17 00:00:00 2001 From: Yuta Hinokuma Date: Wed, 25 Oct 2017 23:10:26 +0900 Subject: [PATCH 8/9] change name Event to EventType --- README.md | 2 +- github_webhook/__init__.py | 2 +- github_webhook/{event.py => event_type.py} | 2 +- github_webhook/webhook.py | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) rename github_webhook/{event.py => event_type.py} (96%) diff --git a/README.md b/README.md index c25f2cc..c21479f 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ orginally developed for Bloomberg's GHE install. receives push events all it takes is: ```py -from github_webhook import Webhook, Event +from github_webhook import Webhook, EventType from flask import Flask app = Flask(__name__) # Standard Flask app diff --git a/github_webhook/__init__.py b/github_webhook/__init__.py index 0e102e2..ecba570 100644 --- a/github_webhook/__init__.py +++ b/github_webhook/__init__.py @@ -8,7 +8,7 @@ :license: Apache License, Version 2.0 """ -from github_webhook.webhook import (Webhook, Event) +from github_webhook.webhook import (Webhook, EventType) # ----------------------------------------------------------------------------- # Copyright 2015 Bloomberg Finance L.P. diff --git a/github_webhook/event.py b/github_webhook/event_type.py similarity index 96% rename from github_webhook/event.py rename to github_webhook/event_type.py index 7da8f81..c7bdf90 100644 --- a/github_webhook/event.py +++ b/github_webhook/event_type.py @@ -1,7 +1,7 @@ from enum import Enum -class Event(Enum): +class EventType(Enum): """ Event enum type """ diff --git a/github_webhook/webhook.py b/github_webhook/webhook.py index b8db3c4..d69d76d 100644 --- a/github_webhook/webhook.py +++ b/github_webhook/webhook.py @@ -5,7 +5,7 @@ import six from flask import abort, request -from .event import Event +from .event_type import EventType class Webhook(object): @@ -27,7 +27,7 @@ def __init__(self, app, endpoint='/postreceive', secret=None): secret = secret.encode('utf-8') self._secret = secret - def hook(self, event_type=Event.Push): + def hook(self, event_type=EventType.Push): """ Registers a function as a hook. Multiple hooks can be registered for a given type, but the order in which they are invoke is unspecified. From c4106dc8fdfa27f87ca6c233990d7695e6071902 Mon Sep 17 00:00:00 2001 From: Yuta Hinokuma Date: Wed, 25 Oct 2017 23:12:07 +0900 Subject: [PATCH 9/9] commit leak --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c21479f..f735d86 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ def hello_world(): def on_push(data): print("Got push with: {0}".format(data)) -@webhook.hook(event_type=Event.Ping) # Defines a handler for the 'ping' event +@webhook.hook(event_type=EventType.Ping) # Defines a handler for the 'ping' event def on_push(data): print("Got push with: {0}".format(data))