def user_subscribed(user_id, repository_url): user = UserRepository.get_user_by_github_username(action.reviewer['login']) if not user: log.warning('Couldn\'t find user in our database with this github email: %s', action.reviewer) return json_response({'ok': True}) dm_id = user.slack_dm_id repo = sa.select([Repository]).where(sa.and_(Repository.c.repo_url == action.repo_url, Repository.c.subscribed_user_id == user.id)).execute().fetchone() if not repo: log.warning('User %s is not subscribed for %s repository', action.reviewer, action.pr_url) return json_response({'ok': True})
def review_requested(self): """ Function which handles review_requested action from GitHub API. :return: dm_id, msg for SlackApi """ pull_request_url = self.payload['pull_request']['html_url'] repo_full_url = self.payload['repository']['html_url'] reviewers = self.payload['pull_request']['requested_reviewers'] messages = [] for reviewer in reviewers: github_username = reviewer['login'] user = UserRepository.get_user_by_github_username(github_username) if not user: log.warning( 'Couldn\'t find user in our database with this github email: %s', github_username) continue dm_id = user.slack_dm_id repo = sa.select([repository_t]).where( sa.and_(repository_t.c.repo_url == repo_full_url, repository_t.c.subscribed_user_id == user.id)).execute().fetchone() if not repo: log.warning('User %s is not subscribed for %s repository', github_username, repo_full_url) continue text = f'<@{user.slack_id}>, please check PR: {pull_request_url}' if not dm_id: dm_id = SlackBot.create_dm_id(user) user_t.update().where(user_t.c.id == user.id).values( slack_dm_id=dm_id).execute() log.info('Successfully set new dm id for user %s', user_t) msg = { 'channel': dm_id, 'text': text, 'as_user': False # todo Variable? } messages.append(msg) return messages
def is_user_subscribed(username, repository_url, chained=None): user = UserRepository.get_user_by_github_username(username)
def is_user_registered(username): return UserRepository.get_user_by_github_username(username) is not None