def __call__(self, integration, organization, event): repo = self.get_repo(integration, organization, event) if repo is None: return # TODO(kmclb): turn this back on once tri-level repo problem has been solved # while we're here, make sure repo data is up to date # self.update_repo_data(repo, event) try: number = event["object_attributes"]["iid"] title = event["object_attributes"]["title"] body = event["object_attributes"]["description"] created_at = event["object_attributes"]["created_at"] merge_commit_sha = event["object_attributes"]["merge_commit_sha"] last_commit = event["object_attributes"]["last_commit"] author_email = None author_name = None if last_commit: author_email = last_commit["author"]["email"] author_name = last_commit["author"]["name"] except KeyError as e: logger.info( "gitlab.webhook.invalid-merge-data", extra={ "integration_id": integration.id, "error": six.string_type(e) }, ) if not author_email: raise Http404() author = CommitAuthor.objects.get_or_create( organization_id=organization.id, email=author_email, defaults={"name": author_name})[0] try: PullRequest.create_or_save( organization_id=organization.id, repository_id=repo.id, key=number, values={ "title": title, "author": author, "message": body, "merge_commit_sha": merge_commit_sha, "date_added": dateutil.parser.parse(created_at).astimezone(timezone.utc), }, ) except IntegrityError: pass
def __call__(self, integration, organization, event): repo = self.get_repo(integration, organization, event) if repo is None: return try: number = event['object_attributes']['iid'] title = event['object_attributes']['title'] body = event['object_attributes']['description'] created_at = event['object_attributes']['created_at'] merge_commit_sha = event['object_attributes']['merge_commit_sha'] last_commit = event['object_attributes']['last_commit'] author_email = None author_name = None if last_commit: author_email = last_commit['author']['email'] author_name = last_commit['author']['name'] except KeyError as e: logger.info('gitlab.webhook.invalid-merge-data', extra={ 'integration_id': integration.id, 'error': six.string_type(e) }) if not author_email: raise Http404() author = CommitAuthor.objects.get_or_create( organization_id=organization.id, email=author_email, defaults={'name': author_name})[0] try: PullRequest.create_or_save( organization_id=organization.id, repository_id=repo.id, key=number, values={ 'title': title, 'author': author, 'message': body, 'merge_commit_sha': merge_commit_sha, 'date_added': dateutil.parser.parse(created_at).astimezone(timezone.utc), }, ) except IntegrityError: pass
def __call__(self, integration, organization, event): repo = self.get_repo(integration, organization, event) if repo is None: return try: number = event['object_attributes']['iid'] title = event['object_attributes']['title'] body = event['object_attributes']['description'] created_at = event['object_attributes']['created_at'] merge_commit_sha = event['object_attributes']['merge_commit_sha'] author = event['object_attributes']['last_commit']['author'] author_email = author['email'] author_name = author['name'] except KeyError as e: logger.info( 'gitlab.webhook.invalid-merge-data', extra={ 'integration_id': integration.id, 'error': six.string_type(e) }) raise Http404() author = CommitAuthor.objects.get_or_create( organization_id=organization.id, email=author_email, defaults={'name': author_name} )[0] try: PullRequest.objects.create_or_update( organization_id=organization.id, repository_id=repo.id, key=number, values={ 'title': title, 'author': author, 'message': body, 'merge_commit_sha': merge_commit_sha, 'date_added': dateutil.parser.parse( created_at).astimezone(timezone.utc), }, ) except IntegrityError: pass