def _handle_webhook_note(self, data, repository): comment = data['object_attributes'] comment_type = { 'MergeRequest': CommentType.MERGE_REQUEST, 'Commit': CommentType.COMMIT, 'Issue': CommentType.ISSUE, 'Snippet': CommentType.SNIPPET }.get(comment['noteable_type']) if comment_type == CommentType.MERGE_REQUEST: iid = data['merge_request']['iid'] iss = GitLabMergeRequest.from_data(data['merge_request'], self._token, repository, iid) action = MergeRequestActions.COMMENTED elif comment_type == CommentType.ISSUE: iid = data['issue']['iid'] iss = GitLabIssue.from_data(data['issue'], self._token, repository, iid) action = IssueActions.COMMENTED else: raise NotImplementedError yield action, [ iss, GitLabComment.from_data(comment, self._token, repository, iid, comment_type, comment['id']) ]
def mentioned_issues(self) -> Set[GitLabIssue]: """ Returns a set of GitLabIssue objects which are related to the merge request. """ issues = self._get_mentioned_issues() return { GitLabIssue(self._token, repo_name, number) for number, repo_name in issues }
def closes_issues(self) -> Set[GitLabIssue]: """ Returns a set of GitLabIssue objects which would be closed upon merging this pull request. """ issues = self._get_closes_issues() return { GitLabIssue(self._token, repo_name, number) for number, repo_name in issues }
def filter_issues(self, state: str = 'opened') -> set: """ Filters the issues from the repository based on properties. :param state: 'opened' or 'closed' or 'all'. """ return { GitLabIssue.from_data(res, self._token, self.full_name, res['iid']) for res in get(self._token, self._url + '/issues', {'state': state}) }
def _handle_webhook_issue(self, data, repository): issue = data['object_attributes'] issue_obj = GitLabIssue.from_data(issue, self._token, repository, issue['iid']) trigger_event = { 'open': IssueActions.OPENED, 'close': IssueActions.CLOSED, 'reopen': IssueActions.REOPENED, }.get(issue['action'], IssueActions.ATTRIBUTES_CHANGED) if (trigger_event == IssueActions.ATTRIBUTES_CHANGED and 'labels' in data['changes']): # labels are changed yield from type(self)._handle_labels(IssueActions, issue_obj, data) else: yield trigger_event, [issue_obj]
def get_issue(self, issue_number: int) -> GitLabIssue: """ Retrieves an issue: >>> from os import environ >>> repo = GitLabRepository( ... GitLabOAuthToken(environ['GITLAB_TEST_TOKEN']), ... 'gitmate-test-user/test' ... ) >>> repo.get_issue(1).title 'Take it serious, son!' :param issue_number: The issue IID of the issue on GitLab. :return: An Issue object. :raises ElementDoesntExistError: If the issue doesn't exist. :raises RuntimeError: If something goes wrong (network, auth...). """ return GitLabIssue(self._token, self.full_name, issue_number)
def create_issue(self, title: str, body: str = '') -> GitLabIssue: """ Create a new issue in the repository. """ return GitLabIssue.create(self._token, self.full_name, title, body)
def setUp(self): self.token = GitLabOAuthToken(os.environ.get('GITLAB_TEST_TOKEN', '')) self.iss = GitLabIssue(self.token, 'gitmate-test-user/test', 23) self.reaction = GitLabReaction(self.token, self.iss, 490941)