Convert over to notifications system. Note this is incomplete

This commit is contained in:
Joseph Schorr 2014-07-17 22:51:58 -04:00
parent de8e898ad0
commit 8d7493cb86
17 changed files with 432 additions and 166 deletions

View file

@ -382,18 +382,10 @@ class RepositoryNotification(BaseModel):
config_json = TextField()
# TODO: remove after migration.
class Webhook(BaseModel):
public_id = CharField(default=random_string_generator(length=64),
unique=True, index=True)
repository = ForeignKeyField(Repository)
parameters = TextField()
all_models = [User, Repository, Image, AccessToken, Role, RepositoryPermission, Visibility,
RepositoryTag, EmailConfirmation, FederatedLogin, LoginService, QueueItem,
RepositoryBuild, Team, TeamMember, TeamRole, LogEntryKind, LogEntry,
PermissionPrototype, ImageStorage, BuildTriggerService, RepositoryBuildTrigger,
OAuthApplication, OAuthAuthorizationCode, OAuthAccessToken, NotificationKind,
Notification, ImageStorageLocation, ImageStoragePlacement,
ExternalNotificationEvent, ExternalNotificationMethod, RepositoryNotification, Webhook]
ExternalNotificationEvent, ExternalNotificationMethod, RepositoryNotification]

View file

@ -840,6 +840,13 @@ def get_repository_for_resource(resource_key):
return None
def lookup_repository(repo_id):
try:
return Repository.get(Repository.id == repo_id)
except Repository.DoesNotExist:
return None
def get_repository(namespace_name, repository_name):
try:
return Repository.get(Repository.name == repository_name,
@ -1540,6 +1547,13 @@ def create_repo_notification(repo, event_name, method_name, config):
config_json=json.dumps(config))
def lookup_repo_notification(notification_id):
try:
return RepositoryNotification.get(RepositoryNotification.id == notification_id)
except RepositoryNotification.DoesNotExist:
return None
def get_repo_notification(namespace_name, repository_name, uuid):
joined = RepositoryNotification.select().join(Repository)
found = list(joined.where(Repository.namespace == namespace_name,
@ -1558,11 +1572,16 @@ def delete_repo_notification(namespace_name, repository_name, uuid):
return found
def list_repo_notifications(namespace_name, repository_name):
def list_repo_notifications(namespace_name, repository_name, event_name=None):
joined = RepositoryNotification.select().join(Repository)
return joined.where(Repository.namespace == namespace_name,
Repository.name == repository_name)
where = joined.where(Repository.namespace == namespace_name,
Repository.name == repository_name)
if event_name:
event = ExternalNotificationEvent.get(ExternalNotificationEvent.name == event_name)
where = where.where(Repostiory.event == event)
return where
# TODO: remove webhook methods when no longer used.
def create_webhook(repo, params_obj):