aboutsummaryrefslogtreecommitdiffstats
path: root/pygithub3/services/repos/hooks.py
blob: 59cf6e147bba4241cf921522b2a5825f0f0855d4 (plain) (blame)
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
#!/usr/bin/env python
# -*- encoding: utf-8 -*-

from . import Service


class Hooks(Service):
    """ Consume `Hooks API
    <http://developer.github.com/v3/repos/hooks>`_

    .. warning::
        You must be authenticated and have repository's admin-permission
    """

    def list(self, user=None, repo=None):
        """ Get repository's hooks

        :param str user: Username
        :param str repo: Repository
        :returns: A :doc:`result`

        .. note::
            Remember :ref:`config precedence`
        """
        request = self.make_request('repos.hooks.list', user=user, repo=repo)
        return self._get_result(request)

    def get(self, hook_id, user=None, repo=None):
        """ Get a single hook

        :param int hook_id: Hook id
        :param str user: Username
        :param str repo: Repository

        .. note::
            Remember :ref:`config precedence`
        """
        request = self.make_request('repos.hooks.get',
            id=hook_id, user=user, repo=repo)
        return self._get(request)

    def create(self, data, user=None, repo=None):
        """ Create a hook

        :param dict data: Input. See `github hooks doc`_
        :param str user: Username
        :param str repo: Repository

        .. note::
            Remember :ref:`config precedence`

        ::

            data = {
                "name": "acunote",
                "active": True,
                "config": {
                    'token': 'AAA...',
                },
                "events": ['push', 'issues'],
            }
            hooks_service.create(data, user='octocat', repo='oct_repo')
        """
        request = self.make_request('repos.hooks.create',
            user=user, repo=repo, body=data)
        return self._post(request)

    def update(self, hook_id, data, user=None, repo=None):
        """ Update a single hook

        :param int hook_id: Hook id
        :param dict data: Input. See `github hooks doc`_
        :param str user: Username
        :param str repo: Repository

        .. note::
            Remember :ref:`config precedence`

        ::

            hooks_service.update(42, dict(active=False), user='octocat',
                repo='oct_repo')
        """
        request = self.make_request('repos.hooks.update',
            id=hook_id, user=user, repo=repo, body=data)
        return self._patch(request)

    def test(self, hook_id, user=None, repo=None):
        """ Test a hook

        :param str user: Username
        :param str repo: Repository

        .. note::
            Remember :ref:`config precedence`

        This will trigger the hook with the latest push to the current
        repository.
        """
        request = self.make_request('repos.hooks.test',
            id=hook_id, user=user, repo=repo)
        self._request('post', request)

    def delete(self, hook_id, user=None, repo=None):
        """ Delete a single hook

        :param int hook_id: Hook id
        :param str user: Username
        :param str repo: Repository

        .. note::
            Remember :ref:`config precedence`
        """
        request = self.make_request('repos.hooks.delete',
            id=hook_id, user=user, repo=repo)
        self._delete(request)