Include commit message in SVN activity
This commit is contained in:
@@ -172,13 +172,14 @@ class TaskManager(object):
|
||||
# to the current user (the SVNer service account) if there is no mapping.
|
||||
usermap = proj['extension_props'].get('attract', {}).get('svn_usermap', {})
|
||||
user_id = usermap.get(log_entry.author, None)
|
||||
msg = 'committed SVN revision %s' % log_entry.revision
|
||||
if not user_id:
|
||||
if 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.',
|
||||
log_entry.author)
|
||||
user_id = authentication.current_user_id()
|
||||
msg = 'committed SVN revision %s authored by SVN user %s' % (
|
||||
log_entry.revision, log_entry.author)
|
||||
msg = 'committed SVN revision %s authored by SVN user %s: %s' % (
|
||||
log_entry.revision, log_entry.author, log_entry.msg)
|
||||
|
||||
register_activity(
|
||||
user_id, msg,
|
||||
|
@@ -9,10 +9,16 @@ import datetime
|
||||
import logging.config
|
||||
import unittest
|
||||
|
||||
from bson import ObjectId
|
||||
from dateutil.tz import tzutc
|
||||
import mock
|
||||
import responses
|
||||
import svn.common
|
||||
|
||||
import pillarsdk
|
||||
import pillar
|
||||
import pillar.tests.common_test_data as ctd
|
||||
|
||||
import logging_config
|
||||
from abstract_attract_test import AbstractAttractTest
|
||||
|
||||
@@ -236,3 +242,61 @@ class PushCommitTest(AbstractAttractTest):
|
||||
blinks[0]['log_entry'].msg)
|
||||
self.assertEqual(datetime.datetime(2016, 10, 21, 15, 40, 17, 0, tzinfo=tzutc()),
|
||||
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'])
|
||||
|
Reference in New Issue
Block a user