1
1
# -*- coding: utf-8 -*-
2
- """
3
- github3.repos.hook
4
- ==================
5
-
6
- This module contains only the Hook object for GitHub's Hook API.
7
-
8
- """
2
+ """This module contains only the Hook object for GitHub's Hook API."""
9
3
from __future__ import unicode_literals
10
4
11
5
from json import dumps
14
8
15
9
16
10
class Hook (GitHubCore ):
17
- """The :class:`Hook <Hook>` object. This handles the information returned
18
- by GitHub about hooks set on a repository.
11
+ """The representation of a hook on a repository.
19
12
20
- Two hook instances can be checked like so::
13
+ See also: http://developer.github.com/v3/repos/hooks/
21
14
22
- h1 == h2
23
- h1 != h2
15
+ This object has the following attributes:
24
16
25
- And is equivalent to::
17
+ .. attribute:: active
26
18
27
- h1.id == h2.id
28
- h1.id != h2.id
19
+ A boolean attribute describing whether the hook is active or not.
29
20
30
- See also: http://developer.github.com/v3/repos/hooks/
31
- """
32
- def _update_attributes (self , hook , session = None ):
33
- self ._api = self ._get_attribute (hook , 'url' )
21
+ .. attribute:: config
22
+
23
+ A dictionary containing the configuration for this hook.
34
24
35
- #: datetime object representing when this hook was last updated.
36
- self .updated_at = self ._strptime_attribute (hook , 'updated_at' )
25
+ .. attribute:: created_at
37
26
38
- #: datetime object representing the date the hook was created.
39
- self . created_at = self . _strptime_attribute ( hook , 'created_at' )
27
+ A :class:`~ datetime.datetime` object representing the date and time
28
+ when this hook was created.
40
29
41
- #: The name of the hook.
42
- self .name = self ._get_attribute (hook , 'name' )
30
+ .. attribute:: events
43
31
44
- #: Events which trigger the hook.
45
- self .events = self ._get_attribute (hook , 'events' )
32
+ The list of events which trigger this hook.
46
33
47
- #: Whether or not this Hook is marked as active on GitHub
48
- self .active = self ._get_attribute (hook , 'active' )
34
+ .. attribute:: id
49
35
50
- #: Dictionary containing the configuration for the Hook.
51
- self .config = self ._get_attribute (hook , 'config' )
36
+ The unique identifier for this hook.
52
37
53
- #: Unique id of the hook.
54
- self .id = self ._get_attribute (hook , 'id' )
38
+ .. attribute:: name
39
+
40
+ The name provided to this hook.
41
+
42
+ .. attribute:: updated_at
43
+
44
+ A :class:`~datetime.datetime` object representing the date and time
45
+ when this hook was updated.
46
+ """
47
+
48
+ def _update_attributes (self , hook , session = None ):
49
+ self ._api = hook ['url' ]
50
+ self .active = hook ['active' ]
51
+ self .config = hook ['config' ]
52
+ self .created_at = self ._strptime (hook ['created_at' ])
53
+ self .events = hook ['events' ]
54
+ self .id = hook ['id' ]
55
+ self .name = hook ['name' ]
56
+ self .updated_at = self ._strptime (hook ['updated_at' ])
55
57
56
58
def _repr (self ):
57
59
return '<Hook [{0}]>' .format (self .name )
@@ -60,7 +62,10 @@ def _repr(self):
60
62
def delete (self ):
61
63
"""Delete this hook.
62
64
63
- :returns: bool
65
+ :returns:
66
+ True if successful, False otherwise
67
+ :rtype:
68
+ bool
64
69
"""
65
70
return self ._boolean (self ._delete (self ._api ), 204 , 404 )
66
71
@@ -69,16 +74,22 @@ def edit(self, config={}, events=[], add_events=[], rm_events=[],
69
74
active = True ):
70
75
"""Edit this hook.
71
76
72
- :param dict config: (optional), key-value pairs of settings for this
73
- hook
74
- :param list events: (optional), which events should this be triggered
75
- for
76
- :param list add_events: (optional), events to be added to the list of
77
- events that this hook triggers for
78
- :param list rm_events: (optional), events to be removed from the list
79
- of events that this hook triggers for
80
- :param bool active: (optional), should this event be active
81
- :returns: bool
77
+ :param dict config:
78
+ (optional), key-value pairs of settings for this hook
79
+ :param list events:
80
+ (optional), which events should this be triggered for
81
+ :param list add_events:
82
+ (optional), events to be added to the list of events that this hook
83
+ triggers for
84
+ :param list rm_events:
85
+ (optional), events to be removed from the list of events that this
86
+ hook triggers for
87
+ :param bool active:
88
+ (optional), should this event be active
89
+ :returns:
90
+ True if successful, False otherwise
91
+ :rtype:
92
+ bool
82
93
"""
83
94
data = {'config' : config , 'active' : active }
84
95
if events :
@@ -102,16 +113,22 @@ def edit(self, config={}, events=[], add_events=[], rm_events=[],
102
113
def ping (self ):
103
114
"""Ping this hook.
104
115
105
- :returns: bool
116
+ :returns:
117
+ True if successful, False otherwise
118
+ :rtype:
119
+ bool
106
120
"""
107
121
url = self ._build_url ('pings' , base_url = self ._api )
108
122
return self ._boolean (self ._post (url ), 204 , 404 )
109
123
110
124
@requires_auth
111
125
def test (self ):
112
- """Test this hook
126
+ """Test this hook.
113
127
114
- :returns: bool
128
+ :returns:
129
+ True if successful, False otherwise
130
+ :rtype:
131
+ bool
115
132
"""
116
133
url = self ._build_url ('tests' , base_url = self ._api )
117
134
return self ._boolean (self ._post (url ), 204 , 404 )
0 commit comments