Show More
@@ -25,12 +25,13 b' def _push_hook(*args, **kwargs):' | |||
|
25 | 25 | repo_extra_fields = extra_fields.run(**kwargs) |
|
26 | 26 | |
|
27 | 27 | if repo_extra_fields.get('endpoint_url'): |
|
28 |
|
|
|
28 | field_metadata = repo_extra_fields['endpoint_url'] | |
|
29 | endpoint = field_metadata['field_value'] | |
|
29 | 30 | if endpoint: |
|
30 | 31 | data = { |
|
31 | 'some_key': 'val' | |
|
32 | 'project': kwargs['repository'], | |
|
32 | 33 | } |
|
33 |
response = http_call.run(url=endpoint, |
|
|
34 | return HookResponse(0, 'Called endpoint {}, with response {}'.format(endpoint, response)) | |
|
34 | response = http_call.run(url=endpoint, params=data) | |
|
35 | return HookResponse(0, 'Called endpoint {}, with response {}\n'.format(endpoint, response)) | |
|
35 | 36 | |
|
36 | 37 | return HookResponse(0, '') |
@@ -25,7 +25,8 b' def _push_hook(*args, **kwargs):' | |||
|
25 | 25 | repo_extra_fields = extra_fields.run(**kwargs) |
|
26 | 26 | |
|
27 | 27 | if repo_extra_fields.get('endpoint_url'): |
|
28 |
|
|
|
28 | field_metadata = repo_extra_fields['endpoint_url'] | |
|
29 | endpoint = field_metadata['field_value'] | |
|
29 | 30 | if endpoint: |
|
30 | 31 | data = { |
|
31 | 32 | 'some_key': 'val' |
@@ -54,10 +54,11 b' def _pre_push_hook(*args, **kwargs):' | |||
|
54 | 54 | repo_extra_fields = extra_fields.run(**kwargs) |
|
55 | 55 | |
|
56 | 56 | # optionally use 'extra fields' to control the logic per repo |
|
57 |
|
|
|
57 | validate_author = repo_extra_fields.get('validate_author', {}).get('field_value') | |
|
58 | should_validate = str2bool(validate_author) | |
|
58 | 59 | |
|
59 | 60 | # optionally store validation regex into extra fields |
|
60 | validation_regex = repo_extra_fields.get('validation_regex', '') | |
|
61 | validation_regex = repo_extra_fields.get('validation_regex', {}).get('field_value') | |
|
61 | 62 | |
|
62 | 63 | def validate_commit_message(commit_message, message_regex=None): |
|
63 | 64 | """ |
@@ -18,11 +18,26 b'' | |||
|
18 | 18 | # and proprietary license terms, please see https://rhodecode.com/licenses/ |
|
19 | 19 | |
|
20 | 20 | """ |
|
21 | us in hooks:: | |
|
21 | example usage in hooks:: | |
|
22 | 22 | |
|
23 | 23 | from .helpers import extra_fields |
|
24 | 24 | # returns list of dicts with key-val fetched from extra fields |
|
25 | 25 | repo_extra_fields = extra_fields.run(**kwargs) |
|
26 | repo_extra_fields.get('endpoint_url') | |
|
27 | ||
|
28 | # the field stored the following example values | |
|
29 | {u'created_on': datetime.datetime(), | |
|
30 | u'field_key': u'endpoint_url', | |
|
31 | u'field_label': u'Endpoint URL', | |
|
32 | u'field_desc': u'Full HTTP endpoint to call if given', | |
|
33 | u'field_type': u'str', | |
|
34 | u'field_value': u'http://server.com/post', | |
|
35 | u'repo_field_id': 1, | |
|
36 | u'repository_id': 1} | |
|
37 | # for example to obtain the value: | |
|
38 | endpoint_field = repo_extra_fields.get('endpoint_url') | |
|
39 | if endpoint_field: | |
|
40 | url = endpoint_field['field_value'] | |
|
26 | 41 | |
|
27 | 42 | """ |
|
28 | 43 |
@@ -22,15 +22,28 b' us in hooks::' | |||
|
22 | 22 | |
|
23 | 23 | from .helpers import http_call |
|
24 | 24 | # returns response after making a POST call |
|
25 |
response = http_call.run(url=url, json_data= |
|
|
25 | response = http_call.run(url=url, json_data={"key": "val"}) | |
|
26 | ||
|
27 | # returns response after making a GET call | |
|
28 | response = http_call.run(url=url, params={"key": "val"}, method='get') | |
|
26 | 29 | |
|
27 | 30 | """ |
|
28 | 31 | |
|
29 | 32 | from rhodecode.integrations.types.base import requests_retry_call |
|
30 | 33 | |
|
31 | 34 | |
|
32 | def run(url, json_data, method='post'): | |
|
35 | def run(url, json_data=None, params=None, method='post'): | |
|
33 | 36 | requests_session = requests_retry_call() |
|
34 | 37 | requests_session.verify = True # Verify SSL |
|
35 | resp = requests_session.post(url, json=json_data, timeout=60) | |
|
36 | return resp.raise_for_status() # raise exception on a failed request | |
|
38 | method_caller = getattr(requests_session, method, 'post') | |
|
39 | ||
|
40 | timeout = 60 | |
|
41 | if json_data: | |
|
42 | resp = method_caller(url, json=json_data, timeout=timeout) | |
|
43 | elif params: | |
|
44 | resp = method_caller(url, params=json_data, timeout=timeout) | |
|
45 | else: | |
|
46 | raise AttributeError('Provide json_data= or params= in function call') | |
|
47 | resp.raise_for_status() # raise exception on a failed request | |
|
48 | return resp | |
|
49 |
General Comments 0
You need to be logged in to leave comments.
Login now