From de3033abb392141c563e0921d84eca2295f5e097 Mon Sep 17 00:00:00 2001 From: Leo Franchi Date: Mon, 14 Oct 2013 08:05:11 -0400 Subject: [PATCH] Add support for discussion comments in Codebase mirror (imported from commit 9b37cbf4209ad607966053af9c1ef9979c2d6205) --- integrations/codebase/zulip_codebase_mirror | 24 +++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/integrations/codebase/zulip_codebase_mirror b/integrations/codebase/zulip_codebase_mirror index 8ce3823..15bc77a 100755 --- a/integrations/codebase/zulip_codebase_mirror +++ b/integrations/codebase/zulip_codebase_mirror @@ -180,12 +180,28 @@ def handle_event(event): comment = raw_props.get('content') commit = raw_props.get('commit_ref') - repo_link = raw_props.get('repository_permalink') - url = make_url('projects/%s/repositories/%s/commit/%s' % (project_link, repo_link, commit)) + # If there's a commit id, it's a comment to a commit + if commit: + repo_link = raw_props.get('repository_permalink') + + url = make_url('projects/%s/repositories/%s/commit/%s' % (project_link, repo_link, commit)) + + subject = "%s commented on %s" % (actor_name, commit) + content = "%s commented on [%s](%s):\n\n~~~ quote\n%s" % (actor_name, commit, url, comment) + else: + # Otherwise, this is a Discussion item, and handle it + subj = raw_props.get("subject") + category = raw_props.get("category") + comment_content = raw_props.get("content") + + subject = "Discussion: %s" % (subj,) + + if category: + content = "%s started a new discussion in %s:\n\n~~~ quote\n%s\n~~~" % (actor_name, category, comment_content) + else: + content = "%s posted:\n\n~~~ quote\n%s\n~~~" % (actor_name, comment_content) - subject = "%s commented on %s" % (actor_name, commit) - content = "%s commented on [%s](%s):\n\n~~~ quote\n%s" % (actor_name, commit, url, comment) elif event_type == 'deployment': stream = config.ZULIP_COMMITS_STREAM_NAME