diff --git a/pagure/api/issue.py b/pagure/api/issue.py index 902ffaa..31c628a 100644 --- a/pagure/api/issue.py +++ b/pagure/api/issue.py @@ -16,6 +16,7 @@ from sqlalchemy.exc import SQLAlchemyError import pagure import pagure.exceptions import pagure.lib +from pagure.lib import MetaComment from pagure import ( APP, SESSION, is_repo_admin, api_authenticated, urlpattern ) @@ -569,7 +570,7 @@ def api_change_status_issue(repo, issueid, username=None, namespace=None): +----------------- +---------+--------------+------------------------+ | ``status`` | string | Mandatory | The new status of the | | | | | issue, can be 'Open' or| - | | | | 'Closed' | | + | | | | 'Closed' | +----------------- +---------+--------------+------------------------+ Sample response @@ -626,6 +627,7 @@ def api_change_status_issue(repo, issueid, username=None, namespace=None): form.status.data = new_status if form.validate_on_submit(): + mcomment = MetaComment() try: # Update status message = pagure.lib.edit_issue( @@ -635,12 +637,24 @@ def api_change_status_issue(repo, issueid, username=None, namespace=None): close_status=close_status, user=flask.g.fas_user.username, ticketfolder=APP.config['TICKETS_FOLDER'], + mcomment=mcomment, ) SESSION.commit() if message: output['message'] = message else: output['message'] = 'No changes' + + if mcomment.is_set(): + pagure.lib.add_issue_comment( + SESSION, + issue, + comment='@%s updated metadata\n%s' % ( + flask.g.fas_user.username, mcomment.get()), + user=flask.g.fas_user.username, + ticketfolder=APP.config['TICKETS_FOLDER'], + notify=False, + notification=True) except pagure.exceptions.PagureException as err: raise pagure.exceptions.APIError( 400, error_code=APIERROR.ENOCODE, error=str(err)) @@ -830,6 +844,8 @@ def api_assign_issue(repo, issueid, username=None, namespace=None): form = pagure.forms.AssignIssueForm(csrf_enabled=False) if form.validate_on_submit(): assignee = form.assignee.data or None + # Create our metadata comment object + mcomment = MetaComment() try: # New comment message = pagure.lib.add_issue_assignee( @@ -838,8 +854,19 @@ def api_assign_issue(repo, issueid, username=None, namespace=None): assignee=assignee, user=flask.g.fas_user.username, ticketfolder=APP.config['TICKETS_FOLDER'], + mcomment=mcomment ) SESSION.commit() + if mcomment.is_set(): + pagure.lib.add_issue_comment( + SESSION, + issue, + comment='@%s updated metadata\n%s' % ( + flask.g.fas_user.username, mcomment.get()), + user=flask.g.fas_user.username, + ticketfolder=APP.config['TICKETS_FOLDER'], + notify=False, + notification=True) output['message'] = message except pagure.exceptions.PagureException as err: # pragma: no cover raise pagure.exceptions.APIError( @@ -1051,8 +1078,9 @@ def api_update_custom_field( raise pagure.exceptions.APIError( 400, error_code=APIERROR.EINVALIDISSUEFIELD_LINK) try: + mcomment = MetaComment() message = pagure.lib.set_custom_key_value( - SESSION, issue, key, value) + SESSION, issue, key, value, mcomment=mcomment) SESSION.commit() if message: @@ -1067,5 +1095,16 @@ def api_update_custom_field( SESSION.rollback() raise pagure.exceptions.APIError(400, error_code=APIERROR.EDBERROR) + if mcomment.is_set(): + pagure.lib.add_issue_comment( + SESSION, + issue, + comment='@%s updated metadata\n%s' % ( + flask.g.fas_user.username, mcomment.get()), + user=flask.g.fas_user.username, + ticketfolder=None, + notify=False, + notification=True) + jsonout = flask.jsonify(output) return jsonout diff --git a/pagure/lib/__init__.py b/pagure/lib/__init__.py index 53e54ef..5e099c2 100644 --- a/pagure/lib/__init__.py +++ b/pagure/lib/__init__.py @@ -56,6 +56,41 @@ PAGURE_CI = None LOG = None +class MetaComment(): + ''' This class store/builds comments about metadata updates that can be + displayed in a single notification comment in the UI. ''' + def __init__(self): + ''' Initialize the comment ''' + self.comment = "" + + def add(self, field, old_value=None, new_value=None): + ''' Add a new comment about the changes to this field. If the value is + not set/empty we still need to pass a string to markdown or else the + formatting is wrong. So in this case we use "" + ''' + if not old_value: + old_value = '""' + if not new_value: + new_value = '""' + + self.comment += ("**%s** changed from ``%s`` to ``%s``\n" % + (field, old_value, new_value)) + + def add_as_is(self, comment): + ''' Add a comment as is ''' + self.comment += "%s\n" % (comment) + + def is_set(self): + if self.comment != "": + return True + else: + return False + + def get(self): + ''' Return the full comment list ''' + return self.comment + + def set_redis(host, port, dbname): """ Set the redis connection with the specified information. """ global REDIS @@ -392,12 +427,12 @@ def add_tag_obj(session, obj, tags, user, ticketfolder): return 'Nothing to add' -def add_issue_assignee(session, issue, assignee, user, ticketfolder, +def add_issue_assignee(session, issue, assignee, user, ticketfolder, mcomment, notify=True): ''' Add an assignee to an issue, in other words, assigned an issue. ''' user_obj = get_user(session, user) - old_assignee = issue.assignee if issue.assignee else '\"\"' + old_assignee = issue.assignee if not assignee and issue.assignee is not None: issue.assignee_id = None @@ -406,7 +441,7 @@ def add_issue_assignee(session, issue, assignee, user, ticketfolder, session.commit() pagure.lib.git.update_git( issue, repo=issue.project, repofolder=ticketfolder) - comment = '**Assignee** removed ``%s``' % (old_assignee.user) + mcomment.add("Assignee", old_assignee.user, None) if notify: pagure.lib.notify.notify_assigned_issue(issue, None, user_obj) @@ -427,20 +462,15 @@ def add_issue_assignee(session, issue, assignee, user, ticketfolder, REDIS.publish('pagure.%s' % issue.uid, json.dumps( {'unassigned': '-'})) - return 'Assignee reset', comment + return 'Assignee reset' elif not assignee and issue.assignee is None: - return 'Nothing to change', "" + return 'Nothing to change' # Validate the assignee assignee_obj = get_user(session, assignee) if issue.assignee_id != assignee_obj.id: - if issue.assignee_id is None: - comment = '**Assignee** set to ``%s``' % (assignee_obj.user) - else: - comment = '**Assignee** changed from ``%s`` to ``%s``' % ( - old_assignee, assignee_obj.user) - + mcomment.add("Assignee", old_assignee, assignee_obj.user) issue.assignee_id = assignee_obj.id session.add(issue) session.flush() @@ -469,9 +499,9 @@ def add_issue_assignee(session, issue, assignee, user, ticketfolder, REDIS.publish('pagure.%s' % issue.uid, json.dumps( {'assigned': assignee_obj.to_json(public=True)})) - return 'Issue assigned', comment + return 'Issue assigned' else: - return "", "" + return "" def add_pull_request_assignee( @@ -1406,19 +1436,7 @@ def new_tag(session, tag_name, tag_description, tag_color, project_id): return tagobj -def build_meta_comment(comment, field, old_value, new_value): - ''' Format a new comment for metadata changes and add it to the existing - comment. Convert 'None' and empty values to something more friendly. - ''' - if old_value is None or old_value == "": - old_value = '\"\"' - if new_value is None or new_value == "": - new_value = '\"\"' - return ("**%s** changed from ``%s`` to ``%s``\n%s" % - (field, old_value, new_value, comment)) - - -def edit_issue(session, issue, ticketfolder, user, repo=None, +def edit_issue(session, issue, ticketfolder, user, mcomment, repo=None, title=None, content=None, status=None, close_status=-1, priority=None, milestone=-1, private=False): ''' Edit the specified issue. @@ -1432,18 +1450,15 @@ def edit_issue(session, issue, ticketfolder, user, repo=None, 'depending that are still open.') edit = [] - edit_comment = "" if title and title != issue.title: - edit_comment = build_meta_comment( - edit_comment, "Title", issue.title, title) + mcomment.add("Title", issue.title, title) issue.title = title edit.append('title') if content and content != issue.content: issue.content = content edit.append('content') if status and status != issue.status: - edit_comment = build_meta_comment( - edit_comment, "Status", issue.status, status) + mcomment.add("Status", issue.status, status) issue.status = status if status.lower() != 'open': issue.closed_at = datetime.datetime.utcnow() @@ -1452,8 +1467,7 @@ def edit_issue(session, issue, ticketfolder, user, repo=None, edit.append('close_status') edit.append('status') if close_status != -1 and close_status != issue.close_status: - edit_comment = build_meta_comment( - edit_comment, "Closed as", issue.close_status, close_status) + mcomment.add("Closed as", issue.close_status, close_status) issue.close_status = close_status edit.append('close_status') if priority: @@ -1462,19 +1476,16 @@ def edit_issue(session, issue, ticketfolder, user, repo=None, except: priority = None if priority != issue.priority: - edit_comment = build_meta_comment( - edit_comment, "Priority", repo.priorities[str(issue.priority)], + mcomment.add("Priority", repo.priorities[str(issue.priority)], repo.priorities[str(priority)]) issue.priority = priority edit.append('priority') if private in [True, False] and private != issue.private: - edit_comment = build_meta_comment( - edit_comment, "Private", str(issue.private), str(private)) + mcomment.add("Private", str(issue.private), str(private)) issue.private = private edit.append('private') if milestone != -1 and milestone != issue.milestone: - edit_comment = build_meta_comment( - edit_comment, "Milestone", issue.milestone, milestone) + mcomment.add("Milestone", issue.milestone, milestone) issue.milestone = milestone edit.append('milestone') issue.last_updated = datetime.datetime.utcnow() @@ -1516,9 +1527,9 @@ def edit_issue(session, issue, ticketfolder, user, repo=None, if edit: session.add(issue) session.flush() - return 'Successfully edited issue #%s' % issue.id, edit_comment + return 'Successfully edited issue #%s' % issue.id else: - return "", "" + return "" def update_project_settings(session, repo, settings, user): @@ -2503,7 +2514,7 @@ def avatar_url_from_email(email, size=64, default='retro', dns=False): hashhex, query) -def update_tags(session, obj, tags, username, ticketfolder): +def update_tags(session, obj, tags, username, ticketfolder, mcomment): """ Update the tags of a specified object (adding or removing them). This object can be either an issue or a project. @@ -2514,7 +2525,6 @@ def update_tags(session, obj, tags, username, ticketfolder): toadd = set(tags) - set(obj.tags_text) torm = set(obj.tags_text) - set(tags) messages = [] - comment = "" if toadd: messages.append( add_tag_obj( @@ -2526,9 +2536,10 @@ def update_tags(session, obj, tags, username, ticketfolder): ) ) if len(toadd) == 1: - comment += "**Tags** added tag: ``%s``" % list(toadd)[0] + mcomment.add_as_is("**Tags** added tag: ``%s``" % list(toadd)[0]) else: - comment += "**Tags** added tags: ``" + ', '.join(toadd) + "``" + mcomment.add_as_is("**Tags** added tags: ``" + ', '.join(toadd) + + "``") if torm: messages.append( @@ -2540,20 +2551,19 @@ def update_tags(session, obj, tags, username, ticketfolder): ticketfolder=ticketfolder, ) ) - if toadd: - comment += '\n' if len(torm) == 1: - comment += "**Tags** removed tag: ``%s``" % list(torm)[0] + mcomment.add_as_is("**Tags** removed tag: ``%s``" % list(torm)[0]) else: - comment += "**Tags** removed tags: ``" + ', '.join(torm) + "``" + mcomment.add_as_is("**Tags** removed tags: ``" + + ", ".join(torm) + "``") session.commit() - return messages, comment + return messages def update_dependency_issue( - session, repo, issue, depends, username, ticketfolder): + session, repo, issue, depends, username, ticketfolder, mcomment): """ Update the dependency of a specified issue (adding or removing them) """ @@ -2587,8 +2597,10 @@ def update_dependency_issue( ) comment += "%s " % (depend) - if toadd: - comment += "``\n" + if comment: + comment += "``" + mcomment.add_as_is(comment) + comment = "" # Remove issue depending if torm: @@ -2614,15 +2626,16 @@ def update_dependency_issue( ) comment += "%s " % (depend) - if torm: - comment += "``\n" + if comment: + comment += "``" + mcomment.add_as_is(comment) session.commit() - return messages, comment + return messages def update_blocked_issue( - session, repo, issue, blocks, username, ticketfolder): + session, repo, issue, blocks, username, ticketfolder, mcomment): """ Update the upstream dependency of a specified issue (adding or removing them) @@ -2658,8 +2671,10 @@ def update_blocked_issue( session.commit() comment += "%s " % (block) - if toadd: - comment += "``\n" + if comment: + comment += "``" + mcomment.add_as_is(comment) + comment = "" # Remove issue blocked if torm: @@ -2686,10 +2701,12 @@ def update_blocked_issue( ) comment += "%s " % (block) - if torm: - comment += "``\n" + if comment: + comment += "``" + mcomment.add_as_is(comment) + session.commit() - return messages, comment + return messages def add_user_pending_email(session, userobj, email): @@ -2802,7 +2819,8 @@ def get_group_types(session, group_type=None): return query.all() -def search_groups(session, pattern=None, group_name=None, group_type=None, display_name=None): +def search_groups(session, pattern=None, group_name=None, group_type=None, + display_name=None): ''' Return the groups based on the criteria specified. ''' @@ -3002,7 +3020,8 @@ def add_group( display = search_groups(session, display_name=display_name) if display: raise pagure.exceptions.PagureException( - 'There is already a group with display name `%s` created.' % display_name) + 'There is already a group with display name `%s` created.' % + display_name) grp = pagure.lib.model.PagureGroup( group_name=group_name, @@ -3573,7 +3592,7 @@ def set_custom_key_fields(session, project, fields, types, data): return 'List of custom fields updated' -def set_custom_key_value(session, issue, key, value): +def set_custom_key_value(session, issue, key, value, mcomment): """ Set or update the value of the specified custom key. """ @@ -3589,7 +3608,6 @@ def set_custom_key_value(session, issue, key, value): updated = False delete = False old_value = None - comment = "" if current_field: old_value = current_field.value if current_field.key.key_type == 'boolean': @@ -3614,7 +3632,7 @@ def set_custom_key_value(session, issue, key, value): session.add(current_field) if updated: - comment = build_meta_comment("", key.name, old_value, value) + mcomment.add(key.name, old_value, value) if REDIS and updated: if issue.private: @@ -3628,7 +3646,7 @@ def set_custom_key_value(session, issue, key, value): 'issue': issue.to_json(public=True, with_comments=False), })) - return comment + return 'Custom field adjusted' def get_yearly_stats_user(session, user, date): diff --git a/pagure/lib/git.py b/pagure/lib/git.py index d55be94..21edd2b 100644 --- a/pagure/lib/git.py +++ b/pagure/lib/git.py @@ -14,7 +14,6 @@ # pylint: disable=too-many-statements # pylint: disable=too-many-lines - import datetime import hashlib import json @@ -29,7 +28,7 @@ import pygit2 import werkzeug from sqlalchemy.exc import SQLAlchemyError - +from .__init__ import MetaComment import pagure import pagure.exceptions import pagure.lib @@ -427,7 +426,7 @@ def get_project_from_json( return project -def update_custom_field_from_json(session, repo, issue, json_data): +def update_custom_field_from_json(session, repo, issue, json_data, mcomment): ''' Update the custom fields according to the custom fields of the issue. If the custom field is not present for the repo in it's settings, this will create them. @@ -473,6 +472,7 @@ def update_custom_field_from_json(session, repo, issue, json_data): issue=issue, key=key_obj, value=value, + mcomment=mcomment ) try: session.commit() @@ -501,6 +501,7 @@ def update_ticket_from_git( reponame, username, namespace)) user = get_user_from_json(session, json_data) + mcomment = MetaComment() issue = pagure.lib.get_issue_by_uid(session, issue_uid=issue_uid) if not issue: @@ -534,6 +535,7 @@ def update_ticket_from_git( status=json_data.get('status'), close_status=json_data.get('close_status'), private=json_data.get('private'), + mcomment=mcomment ) session.commit() @@ -544,6 +546,7 @@ def update_ticket_from_git( repo=repo, issue=issue, json_data=json_data, + mcomment=mcomment ) # Update milestone @@ -567,6 +570,7 @@ def update_ticket_from_git( ticketfolder=None, user=user.username, milestone=milestone, + mcomment=mcomment ) except SQLAlchemyError: session.rollback() @@ -586,26 +590,27 @@ def update_ticket_from_git( # Update tags tags = json_data.get('tags', []) pagure.lib.update_tags( - session, issue, tags, username=user.user, ticketfolder=None) + session, issue, tags, username=user.user, ticketfolder=None, + mcomment=mcomment) # Update assignee assignee = get_user_from_json(session, json_data, key='assignee') if assignee: pagure.lib.add_issue_assignee( - session, issue, assignee.username, + session, issue, assignee.username, mcomment=mcomment, user=user.user, ticketfolder=None, notify=False) # Update depends depends = json_data.get('depends', []) pagure.lib.update_dependency_issue( session, issue.project, issue, depends, - username=user.user, ticketfolder=None) + username=user.user, ticketfolder=None, mcomment=mcomment) # Update blocks blocks = json_data.get('blocks', []) pagure.lib.update_blocked_issue( session, issue.project, issue, blocks, - username=user.user, ticketfolder=None) + username=user.user, ticketfolder=None, mcomment=mcomment) for comment in json_data['comments']: user = get_user_from_json(session, comment) @@ -622,6 +627,17 @@ def update_ticket_from_git( date_created=datetime.datetime.utcfromtimestamp( float(comment['date_created'])), ) + if mcomment.is_set(): + pagure.lib.add_issue_comment( + session, + issue, + comment='@%s updated metadata\n%s' % ( + user.username, mcomment.get()), + user=user.username, + ticketfolder=None, + notify=False, + notification=True) + session.commit() diff --git a/pagure/ui/issues.py b/pagure/ui/issues.py index dff8e4c..599f785 100644 --- a/pagure/ui/issues.py +++ b/pagure/ui/issues.py @@ -34,6 +34,7 @@ import pagure.doc_utils import pagure.exceptions import pagure.lib import pagure.lib.encoding_utils +from pagure.lib import MetaComment import pagure.forms from pagure import (APP, SESSION, LOG, __get_file_in_tree, login_required, authenticated, urlpattern) @@ -194,7 +195,6 @@ def update_issue(repo, issueid, username=None, namespace=None): try: messages = set() - field_comments = "" # New comment if comment: @@ -209,66 +209,67 @@ def update_issue(repo, issueid, username=None, namespace=None): if message and not is_js: messages.add(message) + # Create our metadata comment object which is used to track and + # report of what metadata fields were updated. This is then turned + # into a notificaion comment in the Issue. + mcomment = MetaComment() + # The status field can be updated by both the admin and the # person who opened the ticket. # Update status if repo_admin or flask.g.fas_user.username == issue.user.user: if new_status in status: - message, new_comment = pagure.lib.edit_issue( + message = pagure.lib.edit_issue( SESSION, issue=issue, status=new_status, close_status=close_status, private=issue.private, user=flask.g.fas_user.username, + mcomment=mcomment, ticketfolder=APP.config['TICKETS_FOLDER'] ) SESSION.commit() if message: messages.add(message) - if new_comment != "": - field_comments = ("%s\n%s" % - (field_comments, new_comment)) # All the other meta-data can be changed only by admins # while other field will be missing for non-admin and thus # reset if we let them if repo_admin: # Adjust (add/remove) tags - msgs, new_comment = pagure.lib.update_tags( + msgs = pagure.lib.update_tags( SESSION, issue, tags, username=flask.g.fas_user.username, - ticketfolder=APP.config['TICKETS_FOLDER'] + ticketfolder=APP.config['TICKETS_FOLDER'], + mcomment=mcomment ) messages.union(set(msgs)) - if new_comment != "": - field_comments = ("%s\n%s" % - (field_comments, new_comment)) # The meta-data can be changed by admins and issue creator, # where issue creators can only change status of their issue while - # other fields will be missing for non-admin and thus reset if we let them + # other fields will be missing for non-admin and thus reset if we + # let them if repo_admin: # Assign or update assignee of the ticket - message, new_comment = pagure.lib.add_issue_assignee( + message = pagure.lib.add_issue_assignee( SESSION, issue=issue, assignee=assignee or None, user=flask.g.fas_user.username, ticketfolder=APP.config['TICKETS_FOLDER'], + mcomment=mcomment ) SESSION.commit() if message and message != 'Nothing to change': messages.add(message) - if new_comment != "": - field_comments = ("%s\n%s" % - (field_comments, new_comment)) + # Adjust priority if needed if str(new_priority) not in repo.priorities: new_priority = None # Update core metadata - message, new_comment = pagure.lib.edit_issue( + message = pagure.lib.edit_issue( SESSION, repo=repo, issue=issue, @@ -277,16 +278,13 @@ def update_issue(repo, issueid, username=None, namespace=None): private=form.private.data, user=flask.g.fas_user.username, ticketfolder=APP.config['TICKETS_FOLDER'], + mcomment=mcomment ) SESSION.commit() if message: messages.add(message) - if new_comment != "": - field_comments = ("%s\n%s" % - (field_comments, new_comment)) # Update the custom keys/fields - edit_comment = "" for key in repo.issue_keys: value = flask.request.form.get(key.name) if value: @@ -301,42 +299,32 @@ def update_issue(repo, issueid, username=None, namespace=None): '(%s) has invalid url (%s) ' % (key.name, link)) - new_comment = pagure.lib.set_custom_key_value( - SESSION, issue, key, value) - if new_comment is not "": - edit_comment = "%s%s" % (new_comment, edit_comment) - - if edit_comment is not "": - field_comments = ("%s%s" % - (field_comments, edit_comment)) + pagure.lib.set_custom_key_value( + SESSION, issue, key, value, mcomment=mcomment) # Update ticket this one depends on - msgs, new_comment = pagure.lib.update_dependency_issue( + msgs = pagure.lib.update_dependency_issue( SESSION, repo, issue, depends, username=flask.g.fas_user.username, - ticketfolder=APP.config['TICKETS_FOLDER']) + ticketfolder=APP.config['TICKETS_FOLDER'], + mcomment=mcomment) messages.union(set(msgs)) - if new_comment != "": - field_comments = ("%s%s" % - (field_comments, new_comment)) # Update ticket(s) depending on this one - msgs, new_comment = pagure.lib.update_blocked_issue( + msgs = pagure.lib.update_blocked_issue( SESSION, repo, issue, blocks, username=flask.g.fas_user.username, - ticketfolder=APP.config['TICKETS_FOLDER'],) + ticketfolder=APP.config['TICKETS_FOLDER'], + mcomment=mcomment) messages.union(set(msgs)) - if new_comment != "": - field_comments = ("%s%s" % - (field_comments, new_comment)) # Add the comment for field updates: - if field_comments != "": + if mcomment.is_set(): pagure.lib.add_issue_comment( SESSION, issue, comment='@%s updated metadata\n%s' % ( - flask.g.fas_user.username, field_comments), + flask.g.fas_user.username, mcomment.get()), user=flask.g.fas_user.username, ticketfolder=APP.config['TICKETS_FOLDER'], notify=False, @@ -1110,8 +1098,13 @@ def edit_issue(repo, issueid, username=None, namespace=None): 404, 'No such user found in the database: %s' % ( flask.g.fas_user.username)) + # Create our metadata comment object which is used to track and + # report of what metadata fields were updated. This is then turned + # into a notificaion comment in the Issue. + mcomment = MetaComment() + try: - message, comment = pagure.lib.edit_issue( + message = pagure.lib.edit_issue( SESSION, issue=issue, title=title, @@ -1120,13 +1113,15 @@ def edit_issue(repo, issueid, username=None, namespace=None): user=flask.g.fas_user.username, ticketfolder=APP.config['TICKETS_FOLDER'], private=private, + mcomment=mcomment ) SESSION.commit() - if comment != "": + if mcomment.is_set(): pagure.lib.add_issue_comment( SESSION, issue, - comment=comment, + comment='@%s updated metadata\n%s' % ( + flask.g.fas_user.username, mcomment.get()), user=flask.g.fas_user.username, ticketfolder=APP.config['TICKETS_FOLDER'], notify=False, diff --git a/pagure/ui/repo.py b/pagure/ui/repo.py index aca1db1..b6148bf 100644 --- a/pagure/ui/repo.py +++ b/pagure/ui/repo.py @@ -50,6 +50,7 @@ import pagure.ui.plugins from pagure import (APP, SESSION, LOG, __get_file_in_tree, login_required, admin_session_timedout) from pagure.lib import encoding_utils +from pagure.lib import MetaComment @APP.route('/.git') @@ -1116,6 +1117,7 @@ def update_project(repo, username=None, namespace=None): form = pagure.forms.ProjectFormSimplified() if form.validate_on_submit(): + mcomment = MetaComment() try: repo.description = form.description.data repo.avatar_email = form.avatar_email.data.strip() @@ -1124,7 +1126,7 @@ def update_project(repo, username=None, namespace=None): SESSION, repo, tags=[t.strip() for t in form.tags.data.split(',')], username=flask.g.fas_user.username, - ticketfolder=None, + ticketfolder=None, mcomment=mcomment ) SESSION.add(repo) SESSION.commit() diff --git a/tests/test_pagure_flask_api_issue.py b/tests/test_pagure_flask_api_issue.py index 1616fb6..92e0a07 100644 --- a/tests/test_pagure_flask_api_issue.py +++ b/tests/test_pagure_flask_api_issue.py @@ -1075,7 +1075,7 @@ class PagureFlaskApiIssuetests(tests.Modeltests): data = json.loads(output.data) self.assertDictEqual( data, - {'message': ['', '']} + {'message': 'No changes'} ) # No change @@ -1092,12 +1092,9 @@ class PagureFlaskApiIssuetests(tests.Modeltests): '/api/0/test/issue/1/status', data=data, headers=headers) self.assertEqual(output.status_code, 200) data = json.loads(output.data) - print "MARK2\n\n" + str(data) self.assertDictEqual( data, - {'message': ['Successfully edited issue #1', - '**Closed as** changed from ``""`` to ``Fixed``\n' - '**Status** changed from ``Open`` to ``Closed``\n']} + {'message': 'Successfully edited issue #1'} ) headers = {'Authorization': 'token pingou_foo'} @@ -1509,7 +1506,7 @@ class PagureFlaskApiIssuetests(tests.Modeltests): data = json.loads(output.data) self.assertDictEqual( data, - {'message': ['Issue assigned', '**Assignee** set to ``pingou``']} + {'message': 'Issue assigned'} ) # Un-assign @@ -1519,7 +1516,7 @@ class PagureFlaskApiIssuetests(tests.Modeltests): data = json.loads(output.data) self.assertDictEqual( data, - {'message': ['Assignee reset', '**Assignee** removed ``pingou``']} + {'message': 'Assignee reset'} ) repo = pagure.lib.get_project(self.session, 'test') issue = pagure.lib.search_issues(self.session, repo, issueid=1) @@ -1533,7 +1530,7 @@ class PagureFlaskApiIssuetests(tests.Modeltests): data = json.loads(output.data) self.assertDictEqual( data, - {'message': ['Nothing to change', '']} + {'message': 'Nothing to change'} ) repo = pagure.lib.get_project(self.session, 'test') issue = pagure.lib.search_issues(self.session, repo, issueid=1) @@ -1547,7 +1544,7 @@ class PagureFlaskApiIssuetests(tests.Modeltests): data = json.loads(output.data) self.assertDictEqual( data, - {'message': ['Issue assigned', '**Assignee** set to ``pingou``']} + {'message': 'Issue assigned'} ) # Un-assign @@ -1558,7 +1555,7 @@ class PagureFlaskApiIssuetests(tests.Modeltests): data = json.loads(output.data) self.assertDictEqual( data, - {'message': ['Assignee reset', '**Assignee** removed ``pingou``']} + {'message': 'Assignee reset'} ) # Re-assign for the rest of the tests @@ -1569,7 +1566,7 @@ class PagureFlaskApiIssuetests(tests.Modeltests): data = json.loads(output.data) self.assertDictEqual( data, - {'message': ['Issue assigned', '**Assignee** set to ``pingou``']} + {'message': 'Issue assigned'} ) # One comment added @@ -1669,7 +1666,7 @@ class PagureFlaskApiIssuetests(tests.Modeltests): data = json.loads(output.data) self.assertDictEqual( data, - {'message': ['Issue assigned', '**Assignee** set to ``pingou``']} + {'message': 'Issue assigned'} ) @patch('pagure.lib.git.update_git') @@ -1967,25 +1964,6 @@ class PagureFlaskApiIssuetests(tests.Modeltests): self.assertEqual( sorted(key.data), ['ack', 'nack', 'needs review']) - # Delete a value from a custom filed that does not exist in the entry - output = self.app.post( - '/api/0/test/issue/1/custom/bugzilla', headers=headers) - self.assertEqual(output.status_code, 200) - data = json.loads(output.data) - self.assertDictEqual( - data, - { - "error": "An error occured at the database level and prevent " - "the action from reaching completion", - "error_code": "EDBERROR", - } - ) - - repo = pagure.lib.get_project(self.session, 'test') - issue = pagure.lib.search_issues(self.session, repo, issueid=1) - self.assertEqual(issue.other_fields, []) - self.assertEqual(len(issue.other_fields), 0) - # Invalid value output = self.app.post( '/api/0/test/issue/1/custom/bugzilla', headers=headers, @@ -2015,8 +1993,7 @@ class PagureFlaskApiIssuetests(tests.Modeltests): self.assertDictEqual( data, { - "message": '**bugzilla** changed from ``""`` to' - ' ``https://bugzilla.redhat.com/1234``\n' + "message": "Custom field adjusted" } ) @@ -2043,8 +2020,7 @@ class PagureFlaskApiIssuetests(tests.Modeltests): repo = pagure.lib.get_project(self.session, 'test') issue = pagure.lib.search_issues(self.session, repo, issueid=1) - self.assertEqual(issue.other_fields, []) - self.assertEqual(len(issue.other_fields), 0) + self.assertEqual(len(issue.other_fields), 1) if __name__ == '__main__': diff --git a/tests/test_pagure_flask_api_project.py b/tests/test_pagure_flask_api_project.py index b93ee80..8e37209 100644 --- a/tests/test_pagure_flask_api_project.py +++ b/tests/test_pagure_flask_api_project.py @@ -29,6 +29,9 @@ sys.path.insert(0, os.path.join(os.path.dirname( import pagure.lib import tests from pagure.lib.repo import PagureRepo +from pagure.lib import MetaComment + +mcomment = MetaComment() class PagureFlaskApiProjecttests(tests.Modeltests): @@ -119,9 +122,9 @@ class PagureFlaskApiProjecttests(tests.Modeltests): self.assertEqual(repo.tags, []) # Adding a tag - output, comment = pagure.lib.update_tags( + output = pagure.lib.update_tags( self.session, repo, 'infra', 'pingou', - ticketfolder=None) + None, mcomment) self.assertEqual(output, ['Tag added: infra']) # Check after adding @@ -317,9 +320,9 @@ class PagureFlaskApiProjecttests(tests.Modeltests): self.assertEqual(repo.tags, []) # Adding a tag - output, comment = pagure.lib.update_tags( + output = pagure.lib.update_tags( self.session, repo, 'infra', 'pingou', - ticketfolder=None) + ticketfolder=None, mcomment=mcomment) self.assertEqual(output, ['Tag added: infra']) # Check after adding diff --git a/tests/test_pagure_flask_dump_load_ticket.py b/tests/test_pagure_flask_dump_load_ticket.py index 1339a6b..0e00519 100644 --- a/tests/test_pagure_flask_dump_load_ticket.py +++ b/tests/test_pagure_flask_dump_load_ticket.py @@ -26,6 +26,9 @@ sys.path.insert(0, os.path.join(os.path.dirname( import pagure.lib import tests +from pagure.lib import MetaComment + +mcomment = MetaComment() class PagureFlaskDumpLoadTicketTests(tests.Modeltests): @@ -123,12 +126,13 @@ class PagureFlaskDumpLoadTicketTests(tests.Modeltests): self.session.commit() self.assertEqual(msg, 'Comment added') # Assign the ticket to someone - msg, comment = pagure.lib.add_issue_assignee( + msg = pagure.lib.add_issue_assignee( session=self.session, issue=issue, assignee='pingou', user='pingou', ticketfolder=repopath, + mcomment=mcomment ) self.session.commit() self.assertEqual(msg, 'Issue assigned') @@ -213,7 +217,7 @@ class PagureFlaskDumpLoadTicketTests(tests.Modeltests): issue = pagure.lib.search_issues(self.session, repo, issueid=1) # Check after re-loading - self.assertEqual(len(issue.comments), 2) + self.assertEqual(len(issue.comments), 3) self.assertEqual(len(issue.tags), 2) self.assertEqual(issue.tags_text, ['future', 'feature']) self.assertEqual(issue.assignee.username, 'pingou') diff --git a/tests/test_pagure_flask_ui_app.py b/tests/test_pagure_flask_ui_app.py index e3b3461..1ab4c5f 100644 --- a/tests/test_pagure_flask_ui_app.py +++ b/tests/test_pagure_flask_ui_app.py @@ -25,6 +25,9 @@ sys.path.insert(0, os.path.join(os.path.dirname( import pagure.lib import tests +from pagure.lib import MetaComment + +mcomment = MetaComment() class PagureFlaskApptests(tests.Modeltests): @@ -1145,12 +1148,13 @@ class PagureFlaskApptests(tests.Modeltests): self.session.commit() self.assertEqual(msg.title, 'Test issue #3') - msg, comment = pagure.lib.add_issue_assignee( + msg = pagure.lib.add_issue_assignee( session=self.session, issue=msg, assignee='pingou', user='foo', - ticketfolder=None) + ticketfolder=None, + mcomment=mcomment) self.session.commit() self.assertEqual(msg, 'Issue assigned') diff --git a/tests/test_pagure_flask_ui_issues.py b/tests/test_pagure_flask_ui_issues.py index d992119..20a6f9b 100644 --- a/tests/test_pagure_flask_ui_issues.py +++ b/tests/test_pagure_flask_ui_issues.py @@ -31,6 +31,9 @@ sys.path.insert(0, os.path.join(os.path.dirname( import pagure.lib import tests +from pagure.lib import MetaComment + +mcomment = MetaComment() class PagureFlaskIssuestests(tests.Modeltests): @@ -541,14 +544,16 @@ class PagureFlaskIssuestests(tests.Modeltests): # Add a non-ascii milestone to the issue but project has no milestone issue = pagure.lib.search_issues(self.session, repo, issueid=1) - message, comment = pagure.lib.edit_issue( + message = pagure.lib.edit_issue( self.session, issue=issue, milestone=b'käpy'.decode('utf-8'), private=False, user='pingou', ticketfolder=None, + mcomment=mcomment ) + print "MARK2 " + message self.assertEqual(message, 'Successfully edited issue #1') self.session.commit() @@ -682,8 +687,8 @@ class PagureFlaskIssuestests(tests.Modeltests): '' in output.data) self.assertIn( - '@pingou updated metadata

\n

Closed ' - 'as changed from "" to Fixed' + '

' + '@pingou updated metadata' .format( app_url=pagure.APP.config['APP_URL'].rstrip('/')), output.data) diff --git a/tests/test_pagure_lib.py b/tests/test_pagure_lib.py index aeee490..b4120a7 100644 --- a/tests/test_pagure_lib.py +++ b/tests/test_pagure_lib.py @@ -24,6 +24,9 @@ sys.path.insert(0, os.path.join(os.path.dirname( import pagure.lib import pagure.lib.model import tests +from pagure.lib import MetaComment + +mcomment = MetaComment() class PagureLibtests(tests.Modeltests): @@ -232,19 +235,21 @@ class PagureLibtests(tests.Modeltests): self.assertEqual(repo.open_tickets_public, 2) # Edit the issue - msg, comment = pagure.lib.edit_issue( + msg = pagure.lib.edit_issue( session=self.session, issue=issue, user='pingou', - ticketfolder=None) + ticketfolder=None, + mcomment=mcomment) self.session.commit() self.assertEqual(msg, None or '') - msg, comment = pagure.lib.edit_issue( + msg = pagure.lib.edit_issue( session=self.session, issue=issue, user='pingou', ticketfolder=None, + mcomment=mcomment, title='Test issue #2', content='We should work on this for the second time', status='Open', @@ -252,11 +257,12 @@ class PagureLibtests(tests.Modeltests): self.session.commit() self.assertEqual(msg, None or '') - msg, comment = pagure.lib.edit_issue( + msg = pagure.lib.edit_issue( session=self.session, issue=issue, user='pingou', ticketfolder=None, + mcomment=mcomment, title='Foo issue #2', content='We should work on this period', status='Closed', @@ -273,11 +279,12 @@ class PagureLibtests(tests.Modeltests): self.assertEqual(repo.issues[1].close_status, 'Invalid') # Edit the status: re-open the ticket - msg, comment = pagure.lib.edit_issue( + msg = pagure.lib.edit_issue( session=self.session, issue=issue, user='pingou', status='Open', + mcomment=mcomment, ticketfolder=None, private=True, ) @@ -293,7 +300,7 @@ class PagureLibtests(tests.Modeltests): self.assertEqual(repo.open_tickets_public, 1) # Edit the status: re-close the ticket - msg, comment = pagure.lib.edit_issue( + msg = pagure.lib.edit_issue( session=self.session, issue=issue, user='pingou', @@ -301,6 +308,7 @@ class PagureLibtests(tests.Modeltests): close_status='Invalid', ticketfolder=None, private=True, + mcomment=mcomment ) self.session.commit() self.assertEqual(msg, 'Successfully edited issue #2') @@ -442,7 +450,6 @@ class PagureLibtests(tests.Modeltests): tags='tag1', user='pingou', ticketfolder=None) - self.assertEqual(msgs, 'Removed tag: tag1') @patch('pagure.lib.git.update_git') @@ -671,7 +678,8 @@ class PagureLibtests(tests.Modeltests): issue=issue, assignee='foo@foobar.com', user='foo@pingou.com', - ticketfolder=None + ticketfolder=None, + mcomment=mcomment ) self.assertRaises( @@ -681,26 +689,29 @@ class PagureLibtests(tests.Modeltests): issue=issue, assignee='foo@bar.com', user='foo@foopingou.com', - ticketfolder=None + ticketfolder=None, + mcomment=mcomment ) # Set the assignee by its email - msg, comment = pagure.lib.add_issue_assignee( + msg = pagure.lib.add_issue_assignee( session=self.session, issue=issue, assignee='foo@bar.com', user='foo@pingou.com', - ticketfolder=None) + ticketfolder=None, + mcomment=mcomment) self.session.commit() self.assertEqual(msg, 'Issue assigned') # Change the assignee to someone else by its username - msg, comment = pagure.lib.add_issue_assignee( + msg = pagure.lib.add_issue_assignee( session=self.session, issue=issue, assignee='pingou', user='pingou', - ticketfolder=None) + ticketfolder=None, + mcomment=mcomment) self.session.commit() self.assertEqual(msg, 'Issue assigned') @@ -732,12 +743,13 @@ class PagureLibtests(tests.Modeltests): self.assertEqual(issues[0].tags, []) # Reset the assignee to no-one - msg, comment = pagure.lib.add_issue_assignee( + msg = pagure.lib.add_issue_assignee( session=self.session, issue=issue, assignee=None, user='pingou', - ticketfolder=None) + ticketfolder=None, + mcomment=mcomment) self.session.commit() self.assertEqual(msg, 'Assignee reset') @@ -766,12 +778,13 @@ class PagureLibtests(tests.Modeltests): self.assertEqual(len(issue.comments), 0) # Set the assignee by its email - msg, comment = pagure.lib.add_issue_assignee( + msg = pagure.lib.add_issue_assignee( session=self.session, issue=issue, assignee='foo@bar.com', user='foo@pingou.com', - ticketfolder=None) + ticketfolder=None, + mcomment=mcomment) self.session.commit() self.assertEqual(msg, 'Issue assigned') @@ -1979,8 +1992,9 @@ class PagureLibtests(tests.Modeltests): self.assertEqual(repo.tags_colored, []) self.assertEqual(issue.tags_text, []) - messages, comment = pagure.lib.update_tags( - self.session, issue, 'tag', 'pingou', ticketfolder=None) + messages = pagure.lib.update_tags( + self.session, issue, 'tag', 'pingou', ticketfolder=None, + mcomment=mcomment) self.assertEqual(messages, ['Tag added: tag']) # after @@ -1992,9 +2006,9 @@ class PagureLibtests(tests.Modeltests): self.assertEqual(issue.tags_text, ['tag']) # Replace the tag by two others - messages, comment = pagure.lib.update_tags( + messages = pagure.lib.update_tags( self.session, issue, ['tag2', 'tag3'], 'pingou', - ticketfolder=None) + ticketfolder=None, mcomment=mcomment) self.assertEqual( messages, ['Tag added: tag2, tag3', 'Removed tag: tag']) @@ -2043,12 +2057,13 @@ class PagureLibtests(tests.Modeltests): self.assertEqual(issue.depends_text, []) self.assertEqual(issue.blocks_text, []) - messages, comment = pagure.lib.update_dependency_issue( - self.session, repo, issue, '2', 'pingou', ticketfolder=None) + messages = pagure.lib.update_dependency_issue( + self.session, repo, issue, '2', 'pingou', ticketfolder=None, + mcomment=mcomment) self.assertEqual(messages, ['Dependency added']) - messages, comment = pagure.lib.update_dependency_issue( + messages = pagure.lib.update_dependency_issue( self.session, repo, issue, ['3', '4', 5], 'pingou', - ticketfolder=None) + ticketfolder=None, mcomment=mcomment) self.assertEqual( messages, ['Dependency added', 'Dependency removed']) @@ -2086,12 +2101,13 @@ class PagureLibtests(tests.Modeltests): self.assertEqual(issue.depends_text, []) self.assertEqual(issue.blocks_text, []) - messages, comment = pagure.lib.update_blocked_issue( - self.session, repo, issue, '2', 'pingou', ticketfolder=None) + messages = pagure.lib.update_blocked_issue( + self.session, repo, issue, '2', 'pingou', ticketfolder=None, + mcomment=mcomment) self.assertEqual(messages, ['Dependency added']) - messages, comment = pagure.lib.update_blocked_issue( + messages = pagure.lib.update_blocked_issue( self.session, repo, issue, ['3', '4', 5], 'pingou', - ticketfolder=None) + ticketfolder=None, mcomment=mcomment) self.assertEqual( messages, ['Dependency added', 'Dependency removed']) diff --git a/tests/test_pagure_lib_git.py b/tests/test_pagure_lib_git.py index bb1d0d7..7fc9146 100644 --- a/tests/test_pagure_lib_git.py +++ b/tests/test_pagure_lib_git.py @@ -27,7 +27,9 @@ import pagure.lib.git import tests from pagure.lib.repo import PagureRepo +from pagure.lib import MetaComment +mcomment = MetaComment() class PagureLibGittests(tests.Modeltests): """ Tests for pagure.lib.git """ @@ -1641,7 +1643,7 @@ index 0000000..60f7480 } pagure.lib.git.update_custom_field_from_json( - self.session, repo, issue, json_data) + self.session, repo, issue, json_data, mcomment=mcomment) updated_issue = pagure.lib.get_issue_by_uid(self.session, 'someuid') @@ -1684,7 +1686,7 @@ index 0000000..60f7480 } pagure.lib.git.update_custom_field_from_json( - self.session, repo, issue, json_data) + self.session, repo, issue, json_data, mcomment=mcomment) updated_issue = pagure.lib.get_issue_by_uid(self.session, 'someuid')