Include commit message in SVN activity

This commit is contained in:
2016-11-10 15:33:55 +01:00
parent 72e903d192
commit 268d1f28e3
2 changed files with 69 additions and 4 deletions

View File

@@ -172,13 +172,14 @@ class TaskManager(object):
# to the current user (the SVNer service account) if there is no mapping. # to the current user (the SVNer service account) if there is no mapping.
usermap = proj['extension_props'].get('attract', {}).get('svn_usermap', {}) usermap = proj['extension_props'].get('attract', {}).get('svn_usermap', {})
user_id = usermap.get(log_entry.author, None) user_id = usermap.get(log_entry.author, None)
msg = 'committed SVN revision %s' % log_entry.revision if user_id:
if not user_id: msg = 'committed SVN revision %s: %s' % (log_entry.revision, log_entry.msg)
else:
self._log.warning(u'No Pillar user mapped for SVN user %s, using SVNer account.', self._log.warning(u'No Pillar user mapped for SVN user %s, using SVNer account.',
log_entry.author) log_entry.author)
user_id = authentication.current_user_id() user_id = authentication.current_user_id()
msg = 'committed SVN revision %s authored by SVN user %s' % ( msg = 'committed SVN revision %s authored by SVN user %s: %s' % (
log_entry.revision, log_entry.author) log_entry.revision, log_entry.author, log_entry.msg)
register_activity( register_activity(
user_id, msg, user_id, msg,

View File

@@ -9,10 +9,16 @@ import datetime
import logging.config import logging.config
import unittest import unittest
from bson import ObjectId
from dateutil.tz import tzutc from dateutil.tz import tzutc
import mock import mock
import responses
import svn.common import svn.common
import pillarsdk
import pillar
import pillar.tests.common_test_data as ctd
import logging_config import logging_config
from abstract_attract_test import AbstractAttractTest from abstract_attract_test import AbstractAttractTest
@@ -236,3 +242,61 @@ class PushCommitTest(AbstractAttractTest):
blinks[0]['log_entry'].msg) blinks[0]['log_entry'].msg)
self.assertEqual(datetime.datetime(2016, 10, 21, 15, 40, 17, 0, tzinfo=tzutc()), self.assertEqual(datetime.datetime(2016, 10, 21, 15, 40, 17, 0, tzinfo=tzutc()),
blinks[0]['log_entry'].date) blinks[0]['log_entry'].date)
class SvnTaskLoggedTest(AbstractAttractTest):
def setUp(self, **kwargs):
AbstractAttractTest.setUp(self, **kwargs)
self.mngr = self.attract.task_manager
self.proj_id, self.project = self.ensure_project_exists()
self.sdk_project = pillarsdk.Project(pillar.tests.mongo_to_sdk(self.project))
def create_task(self, task_type=None):
with self.app.test_request_context():
# Log in as project admin user
pillar.auth.login_user(ctd.EXAMPLE_PROJECT_OWNER_ID)
self.mock_blenderid_validate_happy()
sdk_task = self.mngr.create_task(self.sdk_project, task_type=task_type)
with self.app.test_request_context():
# Fetch the task again, so that we receive the shortcode.
# Also, this is an API test, so we have to use MongoDB
db = self.app.db()
task = db['nodes'].find_one({'_id': ObjectId(sdk_task['_id'])})
self.assertIsNotNone(task)
return task
@responses.activate
def test_svn_commit_to_activity(self):
from attract import cli
# Create a task to push to
task = self.create_task('Lighting')
shortcode = task['properties']['shortcode']
self.assertTrue(shortcode)
# We need a SVNer account to push stuff from SVN to Attract
with self.app.test_request_context():
_, token = cli.create_svner_account('svner@example.com', self.project['url'])
# Do the push
msg = u'¡is a tie! commit to task [%s]' % shortcode
self.post('/attract/api/%s/subversion/log' % self.project['url'],
json={
'revision': 6,
'msg': msg,
'author': 'jemoeder',
'date': datetime.datetime.now(tz=tzutc()).isoformat(' '),
},
auth_token=token['token'])
# Check that the commit message was included in the activity
with self.app.test_request_context():
acts = self.attract.activities_for_node(str(task['_id']))
self.assertEqual(2, acts['_meta']['total']) # create + commit
svn_act = acts['_items'][1]
self.assertIn(msg, svn_act['verb'])