Show More
@@ -36,6 +36,26 b' from rhodecode.integrations.types.base i' | |||||
36 |
|
36 | |||
37 | log = logging.getLogger(__name__) |
|
37 | log = logging.getLogger(__name__) | |
38 |
|
38 | |||
|
39 | REPO_PUSH_TEMPLATE = Template(''' | |||
|
40 | <b>${data['actor']['username']}</b> pushed to repo <a href="${data['repo']['url']}">${data['repo']['repo_name']}</a>: | |||
|
41 | <br> | |||
|
42 | <ul> | |||
|
43 | %for branch, branch_commits in branches_commits.items(): | |||
|
44 | <li> | |||
|
45 | % if branch: | |||
|
46 | <a href="${branch_commits['branch']['url']}">branch: ${branch_commits['branch']['name']}</a> | |||
|
47 | % else: | |||
|
48 | to trunk | |||
|
49 | % endif | |||
|
50 | <ul> | |||
|
51 | % for commit in branch_commits['commits']: | |||
|
52 | <li><a href="${commit['url']}">${commit['short_id']}</a> - ${commit['message_html']}</li> | |||
|
53 | % endfor | |||
|
54 | </ul> | |||
|
55 | </li> | |||
|
56 | %endfor | |||
|
57 | ''') | |||
|
58 | ||||
39 |
|
59 | |||
40 | class HipchatSettingsSchema(colander.Schema): |
|
60 | class HipchatSettingsSchema(colander.Schema): | |
41 | color_choices = [ |
|
61 | color_choices = [ | |
@@ -76,27 +96,6 b' class HipchatSettingsSchema(colander.Sch' | |||||
76 | ) |
|
96 | ) | |
77 |
|
97 | |||
78 |
|
98 | |||
79 | repo_push_template = Template(''' |
|
|||
80 | <b>${data['actor']['username']}</b> pushed to repo <a href="${data['repo']['url']}">${data['repo']['repo_name']}</a>: |
|
|||
81 | <br> |
|
|||
82 | <ul> |
|
|||
83 | %for branch, branch_commits in branches_commits.items(): |
|
|||
84 | <li> |
|
|||
85 | % if branch: |
|
|||
86 | <a href="${branch_commits['branch']['url']}">branch: ${branch_commits['branch']['name']}</a> |
|
|||
87 | % else: |
|
|||
88 | to trunk |
|
|||
89 | % endif |
|
|||
90 | <ul> |
|
|||
91 | % for commit in branch_commits['commits']: |
|
|||
92 | <li><a href="${commit['url']}">${commit['short_id']}</a> - ${commit['message_html']}</li> |
|
|||
93 | % endfor |
|
|||
94 | </ul> |
|
|||
95 | </li> |
|
|||
96 | %endfor |
|
|||
97 | ''') |
|
|||
98 |
|
||||
99 |
|
||||
100 | class HipchatIntegrationType(IntegrationTypeBase, CommitParsingDataHandler): |
|
99 | class HipchatIntegrationType(IntegrationTypeBase, CommitParsingDataHandler): | |
101 | key = 'hipchat' |
|
100 | key = 'hipchat' | |
102 | display_name = _('Hipchat') |
|
101 | display_name = _('Hipchat') | |
@@ -226,7 +225,7 b' class HipchatIntegrationType(Integration' | |||||
226 | data['push']['branches'], data['push']['commits']) |
|
225 | data['push']['branches'], data['push']['commits']) | |
227 |
|
226 | |||
228 | result = render_with_traceback( |
|
227 | result = render_with_traceback( | |
229 | repo_push_template, |
|
228 | REPO_PUSH_TEMPLATE, | |
230 | data=data, |
|
229 | data=data, | |
231 | branches_commits=branches_commits, |
|
230 | branches_commits=branches_commits, | |
232 | ) |
|
231 | ) |
@@ -41,6 +41,30 b' from rhodecode.integrations.types.base i' | |||||
41 | log = logging.getLogger(__name__) |
|
41 | log = logging.getLogger(__name__) | |
42 |
|
42 | |||
43 |
|
43 | |||
|
44 | def html_to_slack_links(message): | |||
|
45 | return re.compile(r'<a .*?href=["\'](.+?)".*?>(.+?)</a>').sub( | |||
|
46 | r'<\1|\2>', message) | |||
|
47 | ||||
|
48 | ||||
|
49 | REPO_PUSH_TEMPLATE = Template(''' | |||
|
50 | <% | |||
|
51 | def branch_text(branch): | |||
|
52 | if branch: | |||
|
53 | return 'on branch: <{}|{}>'.format(branch_commits['branch']['url'], branch_commits['branch']['name']) | |||
|
54 | else: | |||
|
55 | ## case for SVN no branch push... | |||
|
56 | return 'to trunk' | |||
|
57 | %> \ | |||
|
58 | ||||
|
59 | % for branch, branch_commits in branches_commits.items(): | |||
|
60 | ${len(branch_commits['commits'])} ${'commit' if len(branch_commits['commits']) == 1 else 'commits'} ${branch_text(branch)} | |||
|
61 | % for commit in branch_commits['commits']: | |||
|
62 | `<${commit['url']}|${commit['short_id']}>` - ${commit['message_html']|html_to_slack_links} | |||
|
63 | % endfor | |||
|
64 | % endfor | |||
|
65 | ''') | |||
|
66 | ||||
|
67 | ||||
44 | class SlackSettingsSchema(colander.Schema): |
|
68 | class SlackSettingsSchema(colander.Schema): | |
45 | service = colander.SchemaNode( |
|
69 | service = colander.SchemaNode( | |
46 | colander.String(), |
|
70 | colander.String(), | |
@@ -258,7 +282,6 b' class SlackIntegrationType(IntegrationTy' | |||||
258 | return title, text |
|
282 | return title, text | |
259 |
|
283 | |||
260 | def format_repo_push_event(self, data): |
|
284 | def format_repo_push_event(self, data): | |
261 |
|
||||
262 | branches_commits = self.aggregate_branch_data( |
|
285 | branches_commits = self.aggregate_branch_data( | |
263 | data['push']['branches'], data['push']['commits']) |
|
286 | data['push']['branches'], data['push']['commits']) | |
264 |
|
287 | |||
@@ -267,25 +290,8 b' class SlackIntegrationType(IntegrationTy' | |||||
267 | ''') |
|
290 | ''') | |
268 | title = render_with_traceback(template, data=data) |
|
291 | title = render_with_traceback(template, data=data) | |
269 |
|
292 | |||
270 | repo_push_template = Template(textwrap.dedent(r''' |
|
|||
271 | <% |
|
|||
272 | def branch_text(branch): |
|
|||
273 | if branch: |
|
|||
274 | return 'on branch: <{}|{}>'.format(branch_commits['branch']['url'], branch_commits['branch']['name']) |
|
|||
275 | else: |
|
|||
276 | ## case for SVN no branch push... |
|
|||
277 | return 'to trunk' |
|
|||
278 | %> \ |
|
|||
279 | % for branch, branch_commits in branches_commits.items(): |
|
|||
280 | ${len(branch_commits['commits'])} ${'commit' if len(branch_commits['commits']) == 1 else 'commits'} ${branch_text(branch)} |
|
|||
281 | % for commit in branch_commits['commits']: |
|
|||
282 | `<${commit['url']}|${commit['short_id']}>` - ${commit['message_html']|html_to_slack_links} |
|
|||
283 | % endfor |
|
|||
284 | % endfor |
|
|||
285 | ''')) |
|
|||
286 |
|
||||
287 | text = render_with_traceback( |
|
293 | text = render_with_traceback( | |
288 | repo_push_template, |
|
294 | REPO_PUSH_TEMPLATE, | |
289 | data=data, |
|
295 | data=data, | |
290 | branches_commits=branches_commits, |
|
296 | branches_commits=branches_commits, | |
291 | html_to_slack_links=html_to_slack_links, |
|
297 | html_to_slack_links=html_to_slack_links, | |
@@ -308,11 +314,6 b' class SlackIntegrationType(IntegrationTy' | |||||
308 | return title, text |
|
314 | return title, text | |
309 |
|
315 | |||
310 |
|
316 | |||
311 | def html_to_slack_links(message): |
|
|||
312 | return re.compile(r'<a .*?href=["\'](.+?)".*?>(.+?)</a>').sub( |
|
|||
313 | r'<\1|\2>', message) |
|
|||
314 |
|
||||
315 |
|
||||
316 | @async_task(ignore_result=True, base=RequestContextTask) |
|
317 | @async_task(ignore_result=True, base=RequestContextTask) | |
317 | def post_text_to_slack(settings, title, text, fields=None, overrides=None): |
|
318 | def post_text_to_slack(settings, title, text, fields=None, overrides=None): | |
318 | log.debug('sending %s (%s) to slack %s', title, text, settings['service']) |
|
319 | log.debug('sending %s (%s) to slack %s', title, text, settings['service']) |
General Comments 0
You need to be logged in to leave comments.
Login now