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