##// END OF EJS Templates
tests: Add missing argument to assert_called_with statements....
tests: Add missing argument to assert_called_with statements. Added the `'use_rebase' argument to assert statements which was recently added to the merge method.

File last commit:

r389:06163eeb default
r398:e672ff04 default
Show More
repo.py
149 lines | 4.0 KiB | text/x-python | PythonLexer
dan
events: add event system for RepoEvents
r375 # Copyright (C) 2016-2016 RhodeCode GmbH
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License, version 3
# (only), as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# This program is dual-licensed. If you wish to learn more about the
# RhodeCode Enterprise Edition, including its added features, Support services,
# and proprietary license terms, please see https://rhodecode.com/licenses/
dan
events: add serialization .to_dict() to events based on marshmallow
r379 from marshmallow import Schema, fields
dan
events: fix bugs with serialization of repo/pr events and add tests for those cases
r389 from rhodecode.model.db import User, Repository, Session
dan
events: add serialization .to_dict() to events based on marshmallow
r379 from rhodecode.events.base import RhodecodeEvent
dan
events: fix bugs with serialization of repo/pr events and add tests for those cases
r389 def get_repo_url(repo):
dan
events: add serialization .to_dict() to events based on marshmallow
r379 from rhodecode.model.repo import RepoModel
return RepoModel().get_url(repo)
class RepositorySchema(Schema):
"""
Marshmallow schema for a repository
"""
repo_id = fields.Integer()
repo_name = fields.Str()
dan
events: fix bugs with serialization of repo/pr events and add tests for those cases
r389 url = fields.Function(get_repo_url)
dan
events: add serialization .to_dict() to events based on marshmallow
r379
class RepoEventSchema(RhodecodeEvent.MarshmallowSchema):
"""
Marshmallow schema for a repository event
"""
dan
events: fix bugs with serialization of repo/pr events and add tests for those cases
r389 repo = fields.Nested(RepositorySchema)
dan
events: add event system for RepoEvents
r375
class RepoEvent(RhodecodeEvent):
"""
Base class for events acting on a repository.
:param repo: a :class:`Repository` instance
"""
dan
events: add serialization .to_dict() to events based on marshmallow
r379 MarshmallowSchema = RepoEventSchema
dan
events: add event system for RepoEvents
r375 def __init__(self, repo):
dan
events: add serialization .to_dict() to events based on marshmallow
r379 super(RepoEvent, self).__init__()
dan
events: add event system for RepoEvents
r375 self.repo = repo
class RepoPreCreateEvent(RepoEvent):
"""
An instance of this class is emitted as an :term:`event` before a repo is
created.
"""
name = 'repo-pre-create'
class RepoCreatedEvent(RepoEvent):
"""
An instance of this class is emitted as an :term:`event` whenever a repo is
created.
"""
name = 'repo-created'
class RepoPreDeleteEvent(RepoEvent):
"""
An instance of this class is emitted as an :term:`event` whenever a repo is
created.
"""
name = 'repo-pre-delete'
class RepoDeletedEvent(RepoEvent):
"""
An instance of this class is emitted as an :term:`event` whenever a repo is
created.
"""
name = 'repo-deleted'
class RepoVCSEvent(RepoEvent):
"""
Base class for events triggered by the VCS
"""
def __init__(self, repo_name, extras):
self.repo = Repository.get_by_repo_name(repo_name)
if not self.repo:
raise Exception('repo by this name %s does not exist' % repo_name)
self.extras = extras
super(RepoVCSEvent, self).__init__(self.repo)
dan
events: add serialization .to_dict() to events based on marshmallow
r379 @property
dan
events: fix bugs with serialization of repo/pr events and add tests for those cases
r389 def actor(self):
dan
events: add serialization .to_dict() to events based on marshmallow
r379 if self.extras.get('username'):
dan
events: fix bugs with serialization of repo/pr events and add tests for those cases
r389 return User.get_by_username(self.extras['username'])
dan
events: add serialization .to_dict() to events based on marshmallow
r379
@property
dan
events: fix bugs with serialization of repo/pr events and add tests for those cases
r389 def actor_ip(self):
dan
events: add serialization .to_dict() to events based on marshmallow
r379 if self.extras.get('ip'):
dan
events: fix bugs with serialization of repo/pr events and add tests for those cases
r389 return self.extras['ip']
dan
events: add serialization .to_dict() to events based on marshmallow
r379
dan
events: add event system for RepoEvents
r375
class RepoPrePullEvent(RepoVCSEvent):
"""
An instance of this class is emitted as an :term:`event` before commits
are pulled from a repo.
"""
name = 'repo-pre-pull'
class RepoPullEvent(RepoVCSEvent):
"""
An instance of this class is emitted as an :term:`event` after commits
are pulled from a repo.
"""
name = 'repo-pull'
class RepoPrePushEvent(RepoVCSEvent):
"""
An instance of this class is emitted as an :term:`event` before commits
are pushed to a repo.
"""
name = 'repo-pre-push'
class RepoPushEvent(RepoVCSEvent):
"""
An instance of this class is emitted as an :term:`event` after commits
are pushed to a repo.
:param extras: (optional) dict of data from proxied VCS actions
"""
name = 'repo-push'
def __init__(self, repo_name, pushed_commit_ids, extras):
super(RepoPushEvent, self).__init__(repo_name, extras)
self.pushed_commit_ids = pushed_commit_ids