Commits

Lukasz Balcerzak committed 44fc775

Added post push activity handler

  • Participants
  • Parent commits 518c6e0

Comments (0)

Files changed (4)

example_project/manage.py

 #!/usr/bin/env python
+import os
+import sys
 from django.core.management import execute_manager
+
+PROJECT_ROOT = '/Users/lukaszb/develop/workspace/projector/example_project'
+sys.path.insert(0, PROJECT_ROOT)
+os.environ['DJANGO_SETTINGS_MODULE'] = 'example_project.settings'
+
 try:
     import settings # Assumed to be in the same directory.
 except ImportError:

example_project/settings.py

     'richtemplates',
     'projector',
     'vcs.web.simplevcs',
+    'sss',
 
     'example_project',
 )
+ADMINBROWSE_MEDIA_URL = '/media/adminbrowse/'
 
 MIDDLEWARE_CLASSES = (
     'django.middleware.common.CommonMiddleware',

projector/actions.py

+from django.contrib.auth.models import User
 from django.db.models.signals import post_save
+
 from projector.models import Project
 from projector.models import Task
 
+from vcs.web.simplevcs.models import Repository
+
 
 def action_project_created(sender, instance, created, **kwargs):
 
     if created and instance.parent:
         instance.parent.create_action("forked", author=instance.author)
     elif created:
-        instance.create_action("created")
+        instance.create_action("created", author=instance.author)
 
 
 def action_task_saved(sender, instance, created, **kwargs):
     logging.critical("Pushing!")
     logging.debug("Sender: %s" % sender)
     logging.debug("kwargs: %s" % kwargs)
+    try:
+        project = Project.objects\
+            .select_related('repository')\
+            .get(repository__path=kwargs.get('repo_path'))
+        author = User.objects.get(username=kwargs.get('username'))
+        verb = "pushed"
+        project.create_action(verb, author=author)
+    except Project.DoesNotExist:
+        pass
+    except User.DoesNotExist:
+        pass
 
 def actions_start_listening():
     """

projector/models.py

 from projector.actions import actions_start_listening
 actions_start_listening()
 
+
+class Commit(models.Model):
+    id = models.CharField(max_length=255)
+    project = models.ForeignKey(Project)
+    repo = models.ForeignKey(Repository)
+
+    class Meta:
+        abstract = True
+
+    @models.permalink
+    def get_absolute_url(self):
+        return {
+            'username': self.project.author.username,
+            'project_slug': self.project.slug,
+            'revision': self.id,
+        }
+