integrations: organized templates a bit more.
This commit is contained in:
parent
4f3a80a688
commit
6ff0f9072b
2 changed files with 46 additions and 46 deletions
|
|
@ -36,6 +36,26 @@ from rhodecode.integrations.types.base import (
|
|||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
REPO_PUSH_TEMPLATE = Template('''
|
||||
<b>${data['actor']['username']}</b> pushed to repo <a href="${data['repo']['url']}">${data['repo']['repo_name']}</a>:
|
||||
<br>
|
||||
<ul>
|
||||
%for branch, branch_commits in branches_commits.items():
|
||||
<li>
|
||||
% if branch:
|
||||
<a href="${branch_commits['branch']['url']}">branch: ${branch_commits['branch']['name']}</a>
|
||||
% else:
|
||||
to trunk
|
||||
% endif
|
||||
<ul>
|
||||
% for commit in branch_commits['commits']:
|
||||
<li><a href="${commit['url']}">${commit['short_id']}</a> - ${commit['message_html']}</li>
|
||||
% endfor
|
||||
</ul>
|
||||
</li>
|
||||
%endfor
|
||||
''')
|
||||
|
||||
|
||||
class HipchatSettingsSchema(colander.Schema):
|
||||
color_choices = [
|
||||
|
|
@ -76,27 +96,6 @@ class HipchatSettingsSchema(colander.Schema):
|
|||
)
|
||||
|
||||
|
||||
repo_push_template = Template('''
|
||||
<b>${data['actor']['username']}</b> pushed to repo <a href="${data['repo']['url']}">${data['repo']['repo_name']}</a>:
|
||||
<br>
|
||||
<ul>
|
||||
%for branch, branch_commits in branches_commits.items():
|
||||
<li>
|
||||
% if branch:
|
||||
<a href="${branch_commits['branch']['url']}">branch: ${branch_commits['branch']['name']}</a>
|
||||
% else:
|
||||
to trunk
|
||||
% endif
|
||||
<ul>
|
||||
% for commit in branch_commits['commits']:
|
||||
<li><a href="${commit['url']}">${commit['short_id']}</a> - ${commit['message_html']}</li>
|
||||
% endfor
|
||||
</ul>
|
||||
</li>
|
||||
%endfor
|
||||
''')
|
||||
|
||||
|
||||
class HipchatIntegrationType(IntegrationTypeBase, CommitParsingDataHandler):
|
||||
key = 'hipchat'
|
||||
display_name = _('Hipchat')
|
||||
|
|
@ -226,7 +225,7 @@ class HipchatIntegrationType(IntegrationTypeBase, CommitParsingDataHandler):
|
|||
data['push']['branches'], data['push']['commits'])
|
||||
|
||||
result = render_with_traceback(
|
||||
repo_push_template,
|
||||
REPO_PUSH_TEMPLATE,
|
||||
data=data,
|
||||
branches_commits=branches_commits,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -41,6 +41,30 @@ from rhodecode.integrations.types.base import (
|
|||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def html_to_slack_links(message):
|
||||
return re.compile(r'<a .*?href=["\'](.+?)".*?>(.+?)</a>').sub(
|
||||
r'<\1|\2>', message)
|
||||
|
||||
|
||||
REPO_PUSH_TEMPLATE = Template('''
|
||||
<%
|
||||
def branch_text(branch):
|
||||
if branch:
|
||||
return 'on branch: <{}|{}>'.format(branch_commits['branch']['url'], branch_commits['branch']['name'])
|
||||
else:
|
||||
## case for SVN no branch push...
|
||||
return 'to trunk'
|
||||
%> \
|
||||
|
||||
% for branch, branch_commits in branches_commits.items():
|
||||
${len(branch_commits['commits'])} ${'commit' if len(branch_commits['commits']) == 1 else 'commits'} ${branch_text(branch)}
|
||||
% for commit in branch_commits['commits']:
|
||||
`<${commit['url']}|${commit['short_id']}>` - ${commit['message_html']|html_to_slack_links}
|
||||
% endfor
|
||||
% endfor
|
||||
''')
|
||||
|
||||
|
||||
class SlackSettingsSchema(colander.Schema):
|
||||
service = colander.SchemaNode(
|
||||
colander.String(),
|
||||
|
|
@ -258,7 +282,6 @@ class SlackIntegrationType(IntegrationTypeBase, CommitParsingDataHandler):
|
|||
return title, text
|
||||
|
||||
def format_repo_push_event(self, data):
|
||||
|
||||
branches_commits = self.aggregate_branch_data(
|
||||
data['push']['branches'], data['push']['commits'])
|
||||
|
||||
|
|
@ -267,25 +290,8 @@ class SlackIntegrationType(IntegrationTypeBase, CommitParsingDataHandler):
|
|||
''')
|
||||
title = render_with_traceback(template, data=data)
|
||||
|
||||
repo_push_template = Template(textwrap.dedent(r'''
|
||||
<%
|
||||
def branch_text(branch):
|
||||
if branch:
|
||||
return 'on branch: <{}|{}>'.format(branch_commits['branch']['url'], branch_commits['branch']['name'])
|
||||
else:
|
||||
## case for SVN no branch push...
|
||||
return 'to trunk'
|
||||
%> \
|
||||
% for branch, branch_commits in branches_commits.items():
|
||||
${len(branch_commits['commits'])} ${'commit' if len(branch_commits['commits']) == 1 else 'commits'} ${branch_text(branch)}
|
||||
% for commit in branch_commits['commits']:
|
||||
`<${commit['url']}|${commit['short_id']}>` - ${commit['message_html']|html_to_slack_links}
|
||||
% endfor
|
||||
% endfor
|
||||
'''))
|
||||
|
||||
text = render_with_traceback(
|
||||
repo_push_template,
|
||||
REPO_PUSH_TEMPLATE,
|
||||
data=data,
|
||||
branches_commits=branches_commits,
|
||||
html_to_slack_links=html_to_slack_links,
|
||||
|
|
@ -308,11 +314,6 @@ class SlackIntegrationType(IntegrationTypeBase, CommitParsingDataHandler):
|
|||
return title, text
|
||||
|
||||
|
||||
def html_to_slack_links(message):
|
||||
return re.compile(r'<a .*?href=["\'](.+?)".*?>(.+?)</a>').sub(
|
||||
r'<\1|\2>', message)
|
||||
|
||||
|
||||
@async_task(ignore_result=True, base=RequestContextTask)
|
||||
def post_text_to_slack(settings, title, text, fields=None, overrides=None):
|
||||
log.debug('sending %s (%s) to slack %s', title, text, settings['service'])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue