-
Notifications
You must be signed in to change notification settings - Fork 70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Made module exclusively Python3 #14
Open
AidanDelaney
wants to merge
2
commits into
bloomberg:master
Choose a base branch
from
AidanDelaney:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,15 +2,15 @@ | |
|
||
setup( | ||
name="github-webhook", | ||
version="1.0.2", | ||
version="2.0.0", | ||
description="Very simple, but powerful, microframework for writing Github webhooks in Python", | ||
url="https://github.com/bloomberg/python-github-webhook", | ||
author="Alex Chamberlain, Fred Phillips, Daniel Kiss, Daniel Beer", | ||
author_email="[email protected], [email protected], [email protected], [email protected]", | ||
license="Apache 2.0", | ||
packages=["github_webhook"], | ||
install_requires=["flask", "six"], | ||
tests_require=["mock", "pytest"], | ||
install_requires=["flask>=1.0.2"], | ||
tests_require=["pytest"], | ||
classifiers=[ | ||
"Development Status :: 4 - Beta", | ||
"Framework :: Flask", | ||
|
@@ -21,7 +21,6 @@ | |
"Operating System :: MacOS :: MacOS X", | ||
"Operating System :: Microsoft :: Windows", | ||
"Operating System :: POSIX", | ||
"Programming Language :: Python :: 2", | ||
"Programming Language :: Python :: 3", | ||
"Topic :: Software Development :: Version Control", | ||
], | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
|
||
import pytest | ||
import werkzeug | ||
from flask import Flask | ||
|
||
try: | ||
from unittest import mock | ||
|
@@ -128,6 +129,165 @@ def test_request_had_headers(webhook, handler, mock_request): | |
webhook._postreceive() | ||
|
||
|
||
# From https://developer.github.com/v3/activity/events/types/#pushevent | ||
example_push_event = { | ||
"ref": "refs/tags/simple-tag", | ||
"before": "a10867b14bb761a232cd80139fbd4c0d33264240", | ||
"after": "0000000000000000000000000000000000000000", | ||
"created": False, | ||
"deleted": True, | ||
"forced": False, | ||
"base_ref": None, | ||
"compare": "https://github.com/Codertocat/Hello-World/compare/a10867b14bb7...000000000000", | ||
"commits": [], | ||
"head_commit": None, | ||
"repository": { | ||
"id": 135493233, | ||
"node_id": "MDEwOlJlcG9zaXRvcnkxMzU0OTMyMzM=", | ||
"name": "Hello-World", | ||
"full_name": "Codertocat/Hello-World", | ||
"owner": { | ||
"name": "Codertocat", | ||
"email": "[email protected]", | ||
"login": "Codertocat", | ||
"id": 21031067, | ||
"node_id": "MDQ6VXNlcjIxMDMxMDY3", | ||
"avatar_url": "https://avatars1.githubusercontent.com/u/21031067?v=4", | ||
"gravatar_id": "", | ||
"url": "https://api.github.com/users/Codertocat", | ||
"html_url": "https://github.com/Codertocat", | ||
"followers_url": "https://api.github.com/users/Codertocat/followers", | ||
"following_url": "https://api.github.com/users/Codertocat/following{/other_user}", | ||
"gists_url": "https://api.github.com/users/Codertocat/gists{/gist_id}", | ||
"starred_url": "https://api.github.com/users/Codertocat/starred{/owner}{/repo}", | ||
"subscriptions_url": "https://api.github.com/users/Codertocat/subscriptions", | ||
"organizations_url": "https://api.github.com/users/Codertocat/orgs", | ||
"repos_url": "https://api.github.com/users/Codertocat/repos", | ||
"events_url": "https://api.github.com/users/Codertocat/events{/privacy}", | ||
"received_events_url": "https://api.github.com/users/Codertocat/received_events", | ||
"type": "User", | ||
"site_admin": False, | ||
}, | ||
"private": False, | ||
"html_url": "https://github.com/Codertocat/Hello-World", | ||
"description": None, | ||
"fork": False, | ||
"url": "https://github.com/Codertocat/Hello-World", | ||
"forks_url": "https://api.github.com/repos/Codertocat/Hello-World/forks", | ||
"keys_url": "https://api.github.com/repos/Codertocat/Hello-World/keys{/key_id}", | ||
"collaborators_url": "https://api.github.com/repos/Codertocat/Hello-World/collaborators{/collaborator}", | ||
"teams_url": "https://api.github.com/repos/Codertocat/Hello-World/teams", | ||
"hooks_url": "https://api.github.com/repos/Codertocat/Hello-World/hooks", | ||
"issue_events_url": "https://api.github.com/repos/Codertocat/Hello-World/issues/events{/number}", | ||
"events_url": "https://api.github.com/repos/Codertocat/Hello-World/events", | ||
"assignees_url": "https://api.github.com/repos/Codertocat/Hello-World/assignees{/user}", | ||
"branches_url": "https://api.github.com/repos/Codertocat/Hello-World/branches{/branch}", | ||
"tags_url": "https://api.github.com/repos/Codertocat/Hello-World/tags", | ||
"blobs_url": "https://api.github.com/repos/Codertocat/Hello-World/git/blobs{/sha}", | ||
"git_tags_url": "https://api.github.com/repos/Codertocat/Hello-World/git/tags{/sha}", | ||
"git_refs_url": "https://api.github.com/repos/Codertocat/Hello-World/git/refs{/sha}", | ||
"trees_url": "https://api.github.com/repos/Codertocat/Hello-World/git/trees{/sha}", | ||
"statuses_url": "https://api.github.com/repos/Codertocat/Hello-World/statuses/{sha}", | ||
"languages_url": "https://api.github.com/repos/Codertocat/Hello-World/languages", | ||
"stargazers_url": "https://api.github.com/repos/Codertocat/Hello-World/stargazers", | ||
"contributors_url": "https://api.github.com/repos/Codertocat/Hello-World/contributors", | ||
"subscribers_url": "https://api.github.com/repos/Codertocat/Hello-World/subscribers", | ||
"subscription_url": "https://api.github.com/repos/Codertocat/Hello-World/subscription", | ||
"commits_url": "https://api.github.com/repos/Codertocat/Hello-World/commits{/sha}", | ||
"git_commits_url": "https://api.github.com/repos/Codertocat/Hello-World/git/commits{/sha}", | ||
"comments_url": "https://api.github.com/repos/Codertocat/Hello-World/comments{/number}", | ||
"issue_comment_url": "https://api.github.com/repos/Codertocat/Hello-World/issues/comments{/number}", | ||
"contents_url": "https://api.github.com/repos/Codertocat/Hello-World/contents/{+path}", | ||
"compare_url": "https://api.github.com/repos/Codertocat/Hello-World/compare/{base}...{head}", | ||
"merges_url": "https://api.github.com/repos/Codertocat/Hello-World/merges", | ||
"archive_url": "https://api.github.com/repos/Codertocat/Hello-World/{archive_format}{/ref}", | ||
"downloads_url": "https://api.github.com/repos/Codertocat/Hello-World/downloads", | ||
"issues_url": "https://api.github.com/repos/Codertocat/Hello-World/issues{/number}", | ||
"pulls_url": "https://api.github.com/repos/Codertocat/Hello-World/pulls{/number}", | ||
"milestones_url": "https://api.github.com/repos/Codertocat/Hello-World/milestones{/number}", | ||
"notifications_url": "https://api.github.com/repos/Codertocat/Hello-World/notifications{?since,all,participating}", | ||
"labels_url": "https://api.github.com/repos/Codertocat/Hello-World/labels{/name}", | ||
"releases_url": "https://api.github.com/repos/Codertocat/Hello-World/releases{/id}", | ||
"deployments_url": "https://api.github.com/repos/Codertocat/Hello-World/deployments", | ||
"created_at": 1527711484, | ||
"updated_at": "2018-05-30T20:18:35Z", | ||
"pushed_at": 1527711528, | ||
"git_url": "git://github.com/Codertocat/Hello-World.git", | ||
"ssh_url": "[email protected]:Codertocat/Hello-World.git", | ||
"clone_url": "https://github.com/Codertocat/Hello-World.git", | ||
"svn_url": "https://github.com/Codertocat/Hello-World", | ||
"homepage": None, | ||
"size": 0, | ||
"stargazers_count": 0, | ||
"watchers_count": 0, | ||
"language": None, | ||
"has_issues": True, | ||
"has_projects": True, | ||
"has_downloads": True, | ||
"has_wiki": True, | ||
"has_pages": True, | ||
"forks_count": 0, | ||
"mirror_url": None, | ||
"archived": False, | ||
"open_issues_count": 2, | ||
"license": None, | ||
"forks": 0, | ||
"open_issues": 2, | ||
"watchers": 0, | ||
"default_branch": "master", | ||
"stargazers": 0, | ||
"master_branch": "master", | ||
}, | ||
"pusher": {"name": "Codertocat", "email": "[email protected]"}, | ||
"sender": { | ||
"login": "Codertocat", | ||
"id": 21031067, | ||
"node_id": "MDQ6VXNlcjIxMDMxMDY3", | ||
"avatar_url": "https://avatars1.githubusercontent.com/u/21031067?v=4", | ||
"gravatar_id": "", | ||
"url": "https://api.github.com/users/Codertocat", | ||
"html_url": "https://github.com/Codertocat", | ||
"followers_url": "https://api.github.com/users/Codertocat/followers", | ||
"following_url": "https://api.github.com/users/Codertocat/following{/other_user}", | ||
"gists_url": "https://api.github.com/users/Codertocat/gists{/gist_id}", | ||
"starred_url": "https://api.github.com/users/Codertocat/starred{/owner}{/repo}", | ||
"subscriptions_url": "https://api.github.com/users/Codertocat/subscriptions", | ||
"organizations_url": "https://api.github.com/users/Codertocat/orgs", | ||
"repos_url": "https://api.github.com/users/Codertocat/repos", | ||
"events_url": "https://api.github.com/users/Codertocat/events{/privacy}", | ||
"received_events_url": "https://api.github.com/users/Codertocat/received_events", | ||
"type": "User", | ||
"site_admin": False, | ||
}, | ||
} | ||
|
||
|
||
def test_push_request(): | ||
""" Uses the example event defined in the GitHub documentation to ensure | ||
that our webhook app can receive the event. | ||
""" | ||
|
||
# GIVEN | ||
app = Flask(__name__) # Standard Flask app | ||
webhook = Webhook(app) # Defines '/postreceive' endpoint | ||
|
||
@webhook.hook() # Defines a handler for the 'push' event | ||
def on_push(data): | ||
flag = data["repository"]["full_name"] == "Codertocat/Hello-World" | ||
if not flag: | ||
return "Event data does not match expected data", 400 | ||
|
||
# WHEN | ||
resp = None | ||
with app.test_client() as client: | ||
resp = client.post( | ||
"/postreceive", json=example_push_event, headers={"X-Github-Event": "push", "X-Github-Delivery": 0} | ||
) | ||
|
||
# THEN | ||
assert resp.status_code == 204 | ||
|
||
|
||
# ----------------------------------------------------------------------------- | ||
# Copyright 2015 Bloomberg Finance L.P. | ||
# | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the use case is sending an error, would this be better represented with an exception?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case we're returning the http code that the wrapped function returns. This could be any http code such as a 301 which is not necessarily an error. I think the current approach is the best choice here, but I'm happy to be corrected.