Exemplo n.º 1
0
    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'])
        ]
Exemplo n.º 2
0
    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})
        }
Exemplo n.º 3
0
    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]