| |
@@ -22,6 +22,7 @@
|
| |
import uuid
|
| |
|
| |
import bleach
|
| |
+ import redis
|
| |
import sqlalchemy
|
| |
import sqlalchemy.schema
|
| |
from datetime import timedelta
|
| |
@@ -44,6 +45,16 @@
|
| |
# pylint: disable=R0913
|
| |
|
| |
|
| |
+ REDIS = None
|
| |
+
|
| |
+
|
| |
+ def set_redis(host, port, db):
|
| |
+ """ Set the redis connection with the specified information. """
|
| |
+ global REDIS
|
| |
+ pool = redis.ConnectionPool(host=host, port=port, db=db)
|
| |
+ REDIS = redis.StrictRedis(connection_pool=pool)
|
| |
+
|
| |
+
|
| |
def __get_user(session, key):
|
| |
""" Searches for a user in the database for a given username or email.
|
| |
"""
|
| |
@@ -188,7 +199,7 @@
|
| |
|
| |
|
| |
def add_issue_comment(session, issue, comment, user, ticketfolder,
|
| |
- notify=True, redis=None):
|
| |
+ notify=True):
|
| |
''' Add a comment to an issue. '''
|
| |
user_obj = __get_user(session, user)
|
| |
|
| |
@@ -215,17 +226,18 @@
|
| |
issue=issue.to_json(public=True),
|
| |
project=issue.project.to_json(public=True),
|
| |
agent=user_obj.username,
|
| |
- )
|
| |
+ ),
|
| |
+ redis=REDIS,
|
| |
)
|
| |
|
| |
- if redis:
|
| |
+ if REDIS:
|
| |
if issue.private:
|
| |
- redis.publish(issue.uid, json.dumps({
|
| |
+ REDIS.publish('pagure.%s' % issue.uid, json.dumps({
|
| |
'issue': 'private',
|
| |
'comment_id': issue_comment.id,
|
| |
}))
|
| |
else:
|
| |
- redis.publish(issue.uid, json.dumps({
|
| |
+ REDIS.publish('pagure.%s' % issue.uid, json.dumps({
|
| |
'comment_id': issue_comment.id,
|
| |
'comment_added': text2markdown(issue_comment.comment),
|
| |
'comment_user': issue_comment.user.user,
|
| |
@@ -237,7 +249,7 @@
|
| |
return 'Comment added'
|
| |
|
| |
|
| |
- def add_tag_obj(session, obj, tags, user, ticketfolder, redis=None):
|
| |
+ def add_tag_obj(session, obj, tags, user, ticketfolder):
|
| |
''' Add a tag to an object (either an issue or a project). '''
|
| |
user_obj = __get_user(session, user)
|
| |
|
| |
@@ -290,11 +302,14 @@
|
| |
project=obj.project.to_json(public=True),
|
| |
tags=added_tags,
|
| |
agent=user_obj.username,
|
| |
- )
|
| |
+ ),
|
| |
+ redis=REDIS,
|
| |
)
|
| |
|
| |
- if redis:
|
| |
- redis.publish(obj.uid, json.dumps({'added_tags': added_tags}))
|
| |
+ # Send notification for the event-source server
|
| |
+ if REDIS:
|
| |
+ REDIS.publish('pagure.%s' % obj.uid, json.dumps(
|
| |
+ {'added_tags': added_tags}))
|
| |
|
| |
if added_tags:
|
| |
return 'Tag added: %s' % ', '.join(added_tags)
|
| |
@@ -302,8 +317,7 @@
|
| |
return 'Nothing to add'
|
| |
|
| |
|
| |
- def add_issue_assignee(session, issue, assignee, user, ticketfolder,
|
| |
- redis=None):
|
| |
+ def add_issue_assignee(session, issue, assignee, user, ticketfolder):
|
| |
''' Add an assignee to an issue, in other words, assigned an issue. '''
|
| |
user_obj = __get_user(session, user)
|
| |
|
| |
@@ -323,11 +337,14 @@
|
| |
issue=issue.to_json(public=True),
|
| |
project=issue.project.to_json(public=True),
|
| |
agent=user_obj.username,
|
| |
- )
|
| |
+ ),
|
| |
+ redis=REDIS,
|
| |
)
|
| |
|
| |
- if redis:
|
| |
- redis.publish(issue.uid, json.dumps({'unassigned': '-'}))
|
| |
+ # Send notification for the event-source server
|
| |
+ if REDIS:
|
| |
+ REDIS.publish('pagure.%s' % issue.uid, json.dumps(
|
| |
+ {'unassigned': '-'}))
|
| |
|
| |
return 'Assignee reset'
|
| |
elif assignee is None and issue.assignee is None:
|
| |
@@ -354,11 +371,13 @@
|
| |
issue=issue.to_json(public=True),
|
| |
project=issue.project.to_json(public=True),
|
| |
agent=user_obj.username,
|
| |
- )
|
| |
+ ),
|
| |
+ redis=REDIS,
|
| |
)
|
| |
|
| |
- if redis:
|
| |
- redis.publish(issue.uid, json.dumps(
|
| |
+ # Send notification for the event-source server
|
| |
+ if REDIS:
|
| |
+ REDIS.publish('pagure.%s' % issue.uid, json.dumps(
|
| |
{'assigned': assignee_obj.to_json(public=True)}))
|
| |
|
| |
return 'Issue assigned'
|
| |
@@ -385,7 +404,8 @@
|
| |
request=request.to_json(public=True),
|
| |
project=request.project.to_json(public=True),
|
| |
agent=user_obj.username,
|
| |
- )
|
| |
+ ),
|
| |
+ redis=REDIS,
|
| |
)
|
| |
|
| |
return 'Request reset'
|
| |
@@ -412,14 +432,15 @@
|
| |
request=request.to_json(public=True),
|
| |
project=request.project.to_json(public=True),
|
| |
agent=user_obj.username,
|
| |
- )
|
| |
+ ),
|
| |
+ redis=REDIS,
|
| |
)
|
| |
|
| |
return 'Request assigned'
|
| |
|
| |
|
| |
def add_issue_dependency(
|
| |
- session, issue, issue_blocked, user, ticketfolder, redis=None):
|
| |
+ session, issue, issue_blocked, user, ticketfolder):
|
| |
''' Add a dependency between two issues. '''
|
| |
user_obj = __get_user(session, user)
|
| |
|
| |
@@ -457,16 +478,18 @@
|
| |
project=issue.project.to_json(public=True),
|
| |
added_dependency=issue_blocked.id,
|
| |
agent=user_obj.username,
|
| |
- )
|
| |
+ ),
|
| |
+ redis=REDIS,
|
| |
)
|
| |
|
| |
- if redis:
|
| |
- redis.publish(issue.uid, json.dumps({
|
| |
+ # Send notification for the event-source server
|
| |
+ if REDIS:
|
| |
+ REDIS.publish('pagure.%s' % issue.uid, json.dumps({
|
| |
'added_dependency': issue_blocked.id,
|
| |
'issue_uid': issue.uid,
|
| |
'type': 'children',
|
| |
}))
|
| |
- redis.publish(issue_blocked.uid, json.dumps({
|
| |
+ REDIS.publish('pagure.%s' % issue_blocked.uid, json.dumps({
|
| |
'added_dependency': issue.id,
|
| |
'issue_uid': issue_blocked.uid,
|
| |
'type': 'parent',
|
| |
@@ -476,7 +499,7 @@
|
| |
|
| |
|
| |
def remove_issue_dependency(
|
| |
- session, issue, issue_blocked, user, ticketfolder, redis=None):
|
| |
+ session, issue, issue_blocked, user, ticketfolder):
|
| |
''' Remove a dependency between two issues. '''
|
| |
user_obj = __get_user(session, user)
|
| |
|
| |
@@ -515,16 +538,18 @@
|
| |
project=issue.project.to_json(public=True),
|
| |
removed_dependency=child_del,
|
| |
agent=user_obj.username,
|
| |
- )
|
| |
+ ),
|
| |
+ redis=REDIS,
|
| |
)
|
| |
|
| |
- if redis:
|
| |
- redis.publish(issue.uid, json.dumps({
|
| |
+ # Send notification for the event-source server
|
| |
+ if REDIS:
|
| |
+ REDIS.publish('pagure.%s' % issue.uid, json.dumps({
|
| |
'removed_dependency': child_del,
|
| |
'issue_uid': issue.uid,
|
| |
'type': 'children',
|
| |
}))
|
| |
- redis.publish(issue_blocked.uid, json.dumps({
|
| |
+ REDIS.publish('pagure.%s' % issue_blocked.uid, json.dumps({
|
| |
'removed_dependency': issue.id,
|
| |
'issue_uid': issue_blocked.uid,
|
| |
'type': 'parent',
|
| |
@@ -566,14 +591,15 @@
|
| |
project=project.to_json(public=True),
|
| |
tags=removed_tags,
|
| |
agent=user_obj.username,
|
| |
- )
|
| |
+ ),
|
| |
+ redis=REDIS,
|
| |
)
|
| |
|
| |
return msgs
|
| |
|
| |
|
| |
def remove_tags_obj(
|
| |
- session, obj, tags, ticketfolder, user, redis=None):
|
| |
+ session, obj, tags, ticketfolder, user):
|
| |
''' Removes the specified tag(s) of a given object. '''
|
| |
user_obj = __get_user(session, user)
|
| |
|
| |
@@ -599,11 +625,13 @@
|
| |
project=obj.project.to_json(public=True),
|
| |
tags=removed_tags,
|
| |
agent=user_obj.username,
|
| |
- )
|
| |
+ ),
|
| |
+ redis=REDIS,
|
| |
)
|
| |
|
| |
- if redis:
|
| |
- redis.publish(obj.uid, json.dumps(
|
| |
+ # Send notification for the event-source server
|
| |
+ if REDIS:
|
| |
+ REDIS.publish('pagure.%s' % obj.uid, json.dumps(
|
| |
{'removed_tags': removed_tags}))
|
| |
|
| |
return 'Removed tag: %s' % ', '.join(removed_tags)
|
| |
@@ -668,7 +696,8 @@
|
| |
old_tag=old_tag,
|
| |
new_tag=new_tag,
|
| |
agent=user_obj.username,
|
| |
- )
|
| |
+ ),
|
| |
+ redis=REDIS,
|
| |
)
|
| |
|
| |
return msgs
|
| |
@@ -701,7 +730,8 @@
|
| |
project=project.to_json(public=True),
|
| |
new_user=new_user_obj.username,
|
| |
agent=user_obj.username,
|
| |
- )
|
| |
+ ),
|
| |
+ redis=REDIS,
|
| |
)
|
| |
|
| |
return 'User added'
|
| |
@@ -748,15 +778,15 @@
|
| |
project=project.to_json(public=True),
|
| |
new_group=group_obj.group_name,
|
| |
agent=user,
|
| |
- )
|
| |
+ ),
|
| |
+ redis=REDIS,
|
| |
)
|
| |
|
| |
return 'Group added'
|
| |
|
| |
|
| |
def add_pull_request_comment(session, request, commit, filename, row,
|
| |
- comment, user, requestfolder, notify=True,
|
| |
- redis=None):
|
| |
+ comment, user, requestfolder, notify=True):
|
| |
''' Add a comment to a pull-request. '''
|
| |
user_obj = __get_user(session, user)
|
| |
|
| |
@@ -778,8 +808,9 @@
|
| |
if notify:
|
| |
pagure.lib.notify.notify_pull_request_comment(pr_comment, user_obj)
|
| |
|
| |
- if redis:
|
| |
- redis.publish(request.uid, json.dumps({
|
| |
+ # Send notification for the event-source server
|
| |
+ if REDIS:
|
| |
+ REDIS.publish('pagure.%s' % request.uid, json.dumps({
|
| |
'request_id': len(request.comments),
|
| |
'comment_added': text2markdown(pr_comment.comment),
|
| |
'comment_user': pr_comment.user.user,
|
| |
@@ -796,7 +827,8 @@
|
| |
msg=dict(
|
| |
pullrequest=request.to_json(public=True),
|
| |
agent=user_obj.username,
|
| |
- )
|
| |
+ ),
|
| |
+ redis=REDIS,
|
| |
)
|
| |
|
| |
return 'Comment added'
|
| |
@@ -838,7 +870,8 @@
|
| |
pullrequest=request.to_json(public=True),
|
| |
flag=pr_flag.to_json(public=True),
|
| |
agent=user_obj.username,
|
| |
- )
|
| |
+ ),
|
| |
+ redis=REDIS,
|
| |
)
|
| |
|
| |
return 'Flag %s' % action
|
| |
@@ -916,7 +949,7 @@
|
| |
msg=dict(
|
| |
project=project.to_json(public=True),
|
| |
agent=user_obj.username,
|
| |
- )
|
| |
+ ),
|
| |
)
|
| |
|
| |
return 'Project "%s" created' % name
|
| |
@@ -959,7 +992,8 @@
|
| |
issue=issue.to_json(public=True),
|
| |
project=issue.project.to_json(public=True),
|
| |
agent=user_obj.username,
|
| |
- )
|
| |
+ ),
|
| |
+ redis=REDIS,
|
| |
)
|
| |
|
| |
return issue
|
| |
@@ -986,7 +1020,8 @@
|
| |
issue=issue.to_json(public=True),
|
| |
project=issue.project.to_json(public=True),
|
| |
agent=user_obj.username,
|
| |
- )
|
| |
+ ),
|
| |
+ redis=REDIS,
|
| |
)
|
| |
|
| |
return issue
|
| |
@@ -1033,15 +1068,15 @@
|
| |
msg=dict(
|
| |
pullrequest=request.to_json(public=True),
|
| |
agent=user_obj.username,
|
| |
- )
|
| |
+ ),
|
| |
+ redis=REDIS,
|
| |
)
|
| |
|
| |
return request
|
| |
|
| |
|
| |
def edit_issue(session, issue, ticketfolder, user,
|
| |
- title=None, content=None, status=None, private=False,
|
| |
- redis=None):
|
| |
+ title=None, content=None, status=None, private=False):
|
| |
''' Edit the specified issue.
|
| |
'''
|
| |
user_obj = __get_user(session, user)
|
| |
@@ -1079,17 +1114,18 @@
|
| |
project=issue.project.to_json(public=True),
|
| |
fields=edit,
|
| |
agent=user_obj.username,
|
| |
- )
|
| |
+ ),
|
| |
+ redis=REDIS,
|
| |
)
|
| |
|
| |
- if redis and edit:
|
| |
+ if REDIS and edit:
|
| |
if issue.private:
|
| |
- redis.publish(issue.uid, json.dumps({
|
| |
+ REDIS.publish('pagure.%s' % issue.uid, json.dumps({
|
| |
'issue': 'private',
|
| |
'fields': edit,
|
| |
}))
|
| |
else:
|
| |
- redis.publish(issue.uid, json.dumps({
|
| |
+ REDIS.publish('pagure.%s' % issue.uid, json.dumps({
|
| |
'fields': edit,
|
| |
'issue': issue.to_json(public=True, with_comments=False),
|
| |
}))
|
| |
@@ -1137,7 +1173,8 @@
|
| |
project=repo.to_json(public=True),
|
| |
fields=update,
|
| |
agent=user_obj.username,
|
| |
- )
|
| |
+ ),
|
| |
+ redis=REDIS,
|
| |
)
|
| |
|
| |
return 'Edited successfully settings of repo: %s' % repo.fullname
|
| |
@@ -1221,7 +1258,7 @@
|
| |
msg=dict(
|
| |
project=project.to_json(public=True),
|
| |
agent=user_obj.username,
|
| |
- )
|
| |
+ ),
|
| |
)
|
| |
|
| |
return 'Repo "%s" cloned to "%s/%s"' % (repo.name, user, repo.name)
|
| |
@@ -1700,7 +1737,8 @@
|
| |
pullrequest=request.to_json(public=True),
|
| |
merged=merged,
|
| |
agent=user_obj.username,
|
| |
- )
|
| |
+ ),
|
| |
+ redis=REDIS,
|
| |
)
|
| |
|
| |
|
| |
@@ -1908,7 +1946,7 @@
|
| |
hashhex, query)
|
| |
|
| |
|
| |
- def update_tags(session, obj, tags, username, ticketfolder, redis=None):
|
| |
+ def update_tags(session, obj, tags, username, ticketfolder):
|
| |
""" Update the tags of a specified object (adding or removing them).
|
| |
This object can be either an issue or a project.
|
| |
|
| |
@@ -1927,7 +1965,6 @@
|
| |
tags=toadd,
|
| |
user=username,
|
| |
ticketfolder=ticketfolder,
|
| |
- redis=redis,
|
| |
)
|
| |
)
|
| |
|
| |
@@ -1939,7 +1976,6 @@
|
| |
tags=torm,
|
| |
user=username,
|
| |
ticketfolder=ticketfolder,
|
| |
- redis=redis,
|
| |
)
|
| |
)
|
| |
session.commit()
|
| |
@@ -1948,7 +1984,7 @@
|
| |
|
| |
|
| |
def update_dependency_issue(
|
| |
- session, repo, issue, depends, username, ticketfolder, redis=None):
|
| |
+ session, repo, issue, depends, username, ticketfolder):
|
| |
""" Update the dependency of a specified issue (adding or removing them)
|
| |
|
| |
"""
|
| |
@@ -1975,7 +2011,6 @@
|
| |
issue_blocked=issue,
|
| |
user=username,
|
| |
ticketfolder=ticketfolder,
|
| |
- redis=redis,
|
| |
)
|
| |
)
|
| |
|
| |
@@ -1997,7 +2032,6 @@
|
| |
issue_blocked=issue_depend,
|
| |
user=username,
|
| |
ticketfolder=ticketfolder,
|
| |
- redis=redis,
|
| |
)
|
| |
)
|
| |
|
| |
@@ -2006,7 +2040,7 @@
|
| |
|
| |
|
| |
def update_blocked_issue(
|
| |
- session, repo, issue, blocks, username, ticketfolder, redis=None):
|
| |
+ session, repo, issue, blocks, username, ticketfolder):
|
| |
""" Update the upstream dependency of a specified issue (adding or
|
| |
removing them)
|
| |
|
| |
@@ -2034,7 +2068,6 @@
|
| |
issue_blocked=issue_block,
|
| |
user=username,
|
| |
ticketfolder=ticketfolder,
|
| |
- redis=redis,
|
| |
)
|
| |
)
|
| |
session.commit()
|
| |
@@ -2058,7 +2091,6 @@
|
| |
issue_blocked=issue,
|
| |
user=username,
|
| |
ticketfolder=ticketfolder,
|
| |
- redis=redis,
|
| |
)
|
| |
)
|
| |
|
| |
I think it would be good to have a REDIS_WEBHOOK_DB and REDIS_ESS_DB, so people can use a different one per service?
Maybe even make the _HOST and _PORT per service to allow for more redundancy/flexibility.