|
1 | 1 | # -*- coding: utf-8 -*-
|
2 | 2 | #
|
3 |
| -# Copyright (C) 2014 Carlos Jenkins <[email protected]> |
| 3 | +# Copyright (C) 2014, 2015 Carlos Jenkins <[email protected]> |
4 | 4 | #
|
5 | 5 | # Licensed under the Apache License, Version 2.0 (the "License");
|
6 | 6 | # you may not use this file except in compliance with the License.
|
@@ -86,36 +86,46 @@ def index():
|
86 | 86 | # Gather data
|
87 | 87 | try:
|
88 | 88 | payload = loads(request.data)
|
89 |
| - |
90 |
| - # Determining the branch is tricky, as it only appears for certain event types an at different levels |
91 |
| - branch = None |
92 |
| - try: |
93 |
| - # Case 1: a ref_type indicates the type of ref. This is create and delete events. |
94 |
| - if 'ref_type' in payload: |
95 |
| - if payload['ref_type'] == 'branch': |
96 |
| - branch = payload['ref'] |
97 |
| - # Case 2: a pull_request object is involved. This is pull_request and pull_request_review_comment events. |
98 |
| - elif 'pull_request' in payload: |
99 |
| - # This is the TARGET branch for the pull-request, not the source branch |
100 |
| - branch = payload['pull_request']['base']['ref'] |
101 |
| - elif event in ['push']: |
102 |
| - # Push events provide a full Git ref in 'ref' and not a 'ref_type'. Isn't that great? |
103 |
| - branch = payload['ref'].split('/')[2] |
104 |
| - except KeyError: |
105 |
| - # If the payload structure isn't what we expect, we'll live without the branch name |
106 |
| - pass |
107 |
| - |
108 |
| - # All current events have a repository, but some legacy events do not, so let's be safe |
109 |
| - name = payload['repository']['name'] if 'repository' in payload else None |
110 |
| - |
111 |
| - meta = { |
112 |
| - 'name': name, |
113 |
| - 'branch': branch, |
114 |
| - 'event': event |
115 |
| - } |
116 | 89 | except:
|
117 | 90 | abort(400)
|
118 | 91 |
|
| 92 | + # Determining the branch is tricky, as it only appears for certain event |
| 93 | + # types an at different levels |
| 94 | + branch = None |
| 95 | + try: |
| 96 | + # Case 1: a ref_type indicates the type of ref. |
| 97 | + # This true for create and delete events. |
| 98 | + if 'ref_type' in payload: |
| 99 | + if payload['ref_type'] == 'branch': |
| 100 | + branch = payload['ref'] |
| 101 | + |
| 102 | + # Case 2: a pull_request object is involved. This is pull_request and |
| 103 | + # pull_request_review_comment events. |
| 104 | + elif 'pull_request' in payload: |
| 105 | + # This is the TARGET branch for the pull-request, not the source |
| 106 | + # branch |
| 107 | + branch = payload['pull_request']['base']['ref'] |
| 108 | + |
| 109 | + elif event in ['push']: |
| 110 | + # Push events provide a full Git ref in 'ref' and not a 'ref_type'. |
| 111 | + branch = payload['ref'].split('/')[2] |
| 112 | + |
| 113 | + except KeyError: |
| 114 | + # If the payload structure isn't what we expect, we'll live without |
| 115 | + # the branch name |
| 116 | + pass |
| 117 | + |
| 118 | + # All current events have a repository, but some legacy events do not, |
| 119 | + # so let's be safe |
| 120 | + name = payload['repository']['name'] if 'repository' in payload else None |
| 121 | + |
| 122 | + meta = { |
| 123 | + 'name': name, |
| 124 | + 'branch': branch, |
| 125 | + 'event': event |
| 126 | + } |
| 127 | + logging.info('Metadata:\n{}'.format(dumps(meta))) |
| 128 | + |
119 | 129 | # Possible hooks
|
120 | 130 | scripts = []
|
121 | 131 | if branch and name:
|
|
0 commit comments