Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add the beginnings of a CIA extension.

This will post to CIA when a review request is created.

This is from quite a while back and will not work just yet without updating.
  • Loading branch information...
commit 9bab666bbcf1bdd9ea42c848754166c8b60673a6 0 parents
@chipx86 chipx86 authored
0  rbcia/rbcia/__init__.py
No changes.
12 rbcia/rbcia/admin_urls.py
@@ -0,0 +1,12 @@
+from django.conf.urls.defaults import patterns
+
+from rbcia.extension import CIAExtension
+from rbcia.forms import CIASettingsForm
+
+
+urlpatterns = patterns('',
+ (r'^$', 'reviewboard.extensions.views.configure_extension',
+ {'ext_class': CIAExtension,
+ 'form_class': CIASettingsForm,
+ })
+)
68 rbcia/rbcia/client.py
@@ -0,0 +1,68 @@
+from django.conf import settings
+from django.contrib.sites.models import Site
+from django.dispatch import dispatcher
+import xmlrpclib
+
+from reviewboard.reviews.models import ReviewRequest, Review
+from reviewboard.reviews import signals
+
+
+class CIAClient(object):
+ """
+ A client for the CIA servers. Reports information to the server.
+ """
+ NAME = "Review Board CIA Notifier"
+ VERSION = 0.1
+
+ def __init__(self, extension):
+ self.extension = extension
+
+ print "Listening"
+ signals.published.connect(self._review_request_published,
+ sender=ReviewRequest)
+ signals.published.connect(self._review_published,
+ sender=Review)
+ print "Done setting up"
+
+ def send_message(self, review_request, author, log_message):
+ project = self.extension.settings['project']
+ module = self.extension.settings['module']
+ cia_server = self.extension.settings['server']
+
+ site = Site.objects.get(pk=settings.SITE_ID)
+ url = "%s://%s%s" % (settings.DOMAIN_METHOD, site.domain,
+ review_request.get_absolute_url())
+
+ msg = "<message>"
+ msg += " <generator>"
+ msg += " <name>%s</name>" % self.NAME
+ msg += " <version>%s</version>" % self.VERSION
+ msg += " </generator>"
+ msg += " <source>"
+ msg += " <project>%s</project>" % project
+ msg += " <module>%s</module>" % module
+ msg += " </source>"
+ msg += " <body>"
+ msg += " <commit>"
+ msg += " <revision>%s</revision>" % review_request.id
+ msg += " <author>%s</author>" % author
+ msg += " <log>%s</log>" % log_message
+ msg += " <url>%s</url>" % url
+ # TODO: Files?
+ msg += " </commit>"
+ msg += " </body>"
+ msg += "</message>"
+
+ print msg
+ xmlrpclib.ServerProxy(cia_server).hub.deliver(msg)
+
+ def _review_request_published(self, instance, **kwargs):
+ print "_review_request_published: %s" % instance
+ if instance:
+ self.send_message(instance, instance.submitter, instance.summary)
+
+ def _review_published(self, instance, **kwargs):
+ print "_review_published: %s" % instance
+ if instance:
+ self.send_message(instance.review_request, instance.user,
+ instance.body_top)
12 rbcia/rbcia/extension.py
@@ -0,0 +1,12 @@
+# CIA extension for Review Board.
+from reviewboard.extensions.base import Extension
+
+from rbcia.client import CIAClient
+
+
+class CIAExtension(Extension):
+ is_configurable = True
+
+ def __init__(self):
+ Extension.__init__(self)
+ self.client = CIAClient(self)
22 rbcia/rbcia/forms.py
@@ -0,0 +1,22 @@
+from django import forms
+from django.utils.translation import ugettext as _
+from djblets.extensions.forms import SettingsForm
+
+
+class CIASettingsForm(SettingsForm):
+ server = forms.URLField(initial="http://www.cia.vc",
+ help_text=_("The CIA server to send updates to."))
+ project = forms.CharField(max_length=64,
+ help_text=_("The project name to use."))
+ module = forms.CharField(max_length=64, initial="reviews",
+ help_text=_('The module name to use. '
+ 'Defaults to "reviews".'))
+ notify_on_review_requests = forms.BooleanField(
+ initial=True, required=False,
+ help_text=_("Indicates if CIA should be notified when new review "
+ "requests are published."))
+
+ notify_on_reviews = forms.BooleanField(
+ initial=True, required=False,
+ help_text=_("Indicates if CIA should be notified when new reviews "
+ "are published."))
11 rbcia/rbcia/templates/rbcia/configure.html
@@ -0,0 +1,11 @@
+{% extends "admin/base_site.html" %}
+{% load djblets_deco %}
+{% load i18n %}
+{% block title %}{% trans "Configure CIA" %}{% endblock %}
+
+{% block content %}
+<h1>Configure CIA</h1>
+
+<p>To do...</p>
+{% endblock %}
+
7 rbcia/rbcia/views.py
@@ -0,0 +1,7 @@
+from django.shortcuts import render_to_response
+from django.template.context import RequestContext
+
+
+def configure(request, template_name="rbcia/configure.html"):
+ return render_to_response(template_name, RequestContext(request, {
+ }))
21 rbcia/setup.py
@@ -0,0 +1,21 @@
+from setuptools import setup, find_packages
+
+PACKAGE="RB-CIA"
+VERSION="0.1"
+
+setup(
+ name=PACKAGE,
+ version=VERSION,
+ description="""CIA extension for Review Board""",
+ author="Christian Hammond",
+ packages=["rbcia"],
+ entry_points={
+ 'reviewboard.extensions':
+ '%s = rbcia.extension:CIAExtension' % PACKAGE,
+ },
+ package_data={
+ 'rbreports': [
+ 'templates/rbcia/*.html',
+ ],
+ }
+)
Please sign in to comment.
Something went wrong with that request. Please try again.