def _handle_webhook_installation(self, data): """Handles 'installation' event.""" installation = data['installation'] installation_obj = GitHubInstallation.from_data( installation, self._token, installation['id']) trigger_event = { 'created': InstallationActions.CREATED, 'deleted': InstallationActions.DELETED }[data['action']] # sender is the user who made this installation and has access to it sender = GitHubUser.from_data(data['sender'], self._token, data['sender']['login']) # When a new installation is created, it will be installed on at # least one repository which will be forwarded through # `repositories` key. if 'repositories' in data: repos = [ GitHubRepository.from_data(repo, self._token, repo['id']) for repo in data['repositories'] ] yield trigger_event, [installation_obj, sender, repos] else: yield trigger_event, [installation_obj, sender]
def author(self) -> GitHubUser: """ Retrieves the author of the merge request. :return: A GitHubUser object. """ return GitHubUser.from_data(self.data['user'], self._token, self.data['user']['login'])
def owners(self) -> Set[GitHubUser]: """ Returns the user handles of all admin users. """ try: return { GitHubUser.from_data(user, self._token, user['login']) for user in get(self._token, self._url + '/members', params={'role': 'admin'}) } except RuntimeError: return {GitHubUser(self._token, self.name)}
def author(self) -> GitHubUser: """ Retrieves the author of the comment. >>> from os import environ >>> issue = GitHubComment(GitHubToken(environ['GITHUB_TEST_TOKEN']), ... 'gitmate-test-user/test', 172962077) >>> issue.author.username 'sils' :return: A GitHubUser object. """ return GitHubUser.from_data(self.data['user'], self._token, self.data['user']['login'])
def assignees(self) -> Set[GitHubUser]: """ Retrieves the assignee of the issue: >>> from os import environ >>> issue = GitHubIssue(GitHubToken(environ['GITHUB_TEST_TOKEN']), ... 'gitmate-test-user/test', 1) >>> {a.username for a in issue.assignees} {'gitmate-test-user'} >>> issue = GitHubIssue(GitHubToken(environ['GITHUB_TEST_TOKEN']), ... 'gitmate-test-user/test', 2) >>> issue.assignees # Returns empty set, unassigned {} :return: A set containing the usernames of assignees. """ return set( GitHubUser.from_data(user, self._token, user['login']) for user in self.data['assignees'] )
def _handle_webhook_installation_repositories(self, data): """Handles 'installation_repositories' event.""" installation = data['installation'] installation_obj = GitHubInstallation.from_data( installation, self._token, installation['id']) # sender is the user who has access to this installation sender = GitHubUser.from_data(data['sender'], self._token, data['sender']['login']) if data['action'] == 'added': trigger_event = InstallationActions.REPOSITORIES_ADDED repos = [ GitHubRepository.from_data(repo, self._token, repo['id']) for repo in data['repositories_added'] ] elif data['action'] == 'removed': trigger_event = InstallationActions.REPOSITORIES_REMOVED repos = [ GitHubRepository.from_data(repo, self._token, repo['id']) for repo in data['repositories_removed'] ] yield trigger_event, [installation_obj, sender, repos]
def user(self) -> GitHubUser: """ Retrieves the user who reacted with this reaction. """ user = self.data['user'] return GitHubUser.from_data(user, self._token, user['login'])