aboutsummaryrefslogtreecommitdiffstats
path: root/pygithub3/services/orgs/teams.py
blob: 2e47803236ba048055b310995767e075d7bcd610 (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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# -*- encoding: utf-8 -*-

from . import Service


class Teams(Service):
    """ Consume `Teams API <http://developer.github.com/v3/orgs/teams/>`_

    .. warning ::
        You must be authenticated as an owner of the org
    """

    def list(self, org):
        """ Get org's teams

        :param str org: Organisation name
        :returns: A :doc:`result`
        """
        request = self.request_builder('orgs.teams.list', org=org)
        return self._get_result(request)

    def get(self, id):
        """ Get a team

        :param int id: The team id
        :returns: A :doc:`result`
        """
        request = self.request_builder('orgs.teams.get', id=id)
        return self._get(request)

    def create(self, org, name, repo_names=None, permission=None):
        """ Create a new team

        :param str org: Organisation name
        :param str name: Team name
        :param list repo_names: List of repo names to belong to the team
        :param str permission: Permissions to be granted to members
        """
        data = {'name': name}
        if repo_names:
            data['repo_names'] = repo_names
        if permission:
            data['permission'] = permission
        request = self.request_builder('orgs.teams.create', org=org, body=data)
        return self._post(request)

    def update(self, id, name, permission=None):
        """ Update a team

        :param int id: The team id
        :param str name: Team name
        :param str permission: Permissions to be granted to members
        """
        data = {'name': name}
        if permission:
            data['permission'] = permission
        request = self.request_builder('orgs.teams.update', id=id, body=data)
        return self._patch(request)

    def delete(self, id):
        """ Delete a team

        :param int id: The team id
        """
        request = self.request_builder('orgs.teams.delete', id=id)
        return self._delete(request)

    def list_members(self, id):
        """ List the members of a team

        :param int id: The team id
        :returns: A :doc:`result`
        """
        request = self.request_builder('orgs.teams.list_members', id=id)
        return self._get_result(request)

    def is_member(self, id, user):
        """ Determine if user is a member of a team

        :param int id: The team id
        :param str user: User name
        """
        request = self.request_builder('orgs.teams.is_member',
                                       id=id, user=user)
        return self._bool(request)

    def add_member(self, id, user):
        """ Add a user to a team

        :param int id: The team id
        :param str user: User name
        """
        request = self.request_builder('orgs.teams.add_member',
                                       id=id, user=user)
        return self._put(request)

    def remove_member(self, id, user):
        """ Remove a member from a team

        :param int id: The team id
        :param str user: User name
        """
        request = self.request_builder('orgs.teams.remove_member',
                                       id=id, user=user)
        return self._delete(request)

    def list_repos(self, id):
        """ List the repos that a team's members get access to

        :param int id: The team id
        :returns: A :doc:`result`
        """
        request = self.request_builder('orgs.teams.list_repos', id=id)
        return self._get_result(request)

    def contains_repo(self, id, user, repo):
        """ Determine if user is a member of a team

        :param int id: The team id
        :param str user: User name
        :param str repo: Repo name
        """
        request = self.request_builder('orgs.teams.contains_repo',
                                       id=id, user=user, repo=repo)
        return self._bool(request)

    def add_repo(self, id, user, repo):
        """ Give team members access to a repo

        :param int id: The team id
        :param str user: User name
        :param str repo: Repo name
        """
        request = self.request_builder('orgs.teams.add_repo',
                                       id=id, user=user, repo=repo)
        return self._put(request)

    def remove_repo(self, id, user, repo):
        """ Remove a repo from the a team

        :param int id: The team id
        :param str user: User name
        :param str repo: Repo name
        """
        request = self.request_builder('orgs.teams.remove_repo',
                                       id=id, user=user, repo=repo)
        return self._delete(request)