# HG changeset patch # User Steve Losh # Date 1598889236 14400 # Node ID 31e094924f7ef25e68813b606ad7c2f479eaa358 # Parent 324d9b638b9a5a307e1e4747befbc284121e14e9 Slack is a hellscape diff -r 324d9b638b9a -r 31e094924f7e weechat/python/autoload/sanitize_jira.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/weechat/python/autoload/sanitize_jira.py Mon Aug 31 11:53:56 2020 -0400 @@ -0,0 +1,30 @@ +import re, weechat, subprocess + +SCRIPT_NAME = 'sanitize_jira' +SCRIPT_AUTHOR = 'Steve Losh ' +SCRIPT_VERSION = '0.0.1' +SCRIPT_LICENSE = 'MIT' +SCRIPT_DESC = 'clean up the garbage jirabot sends to channels into something readable' + +weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE, SCRIPT_DESC, '', '') + +weechat.hook_line('*', '', 'nick_Jira_Cloud', 'sanitize_jira', '') + +first_line_re = re.compile( + r'(?Phttps://[^/]+/browse/[^?]+)[?]atlOrigin=[^ ]+ [(](?P.+)[)]' +) + +detail_line_re = re.compile( + r'''Status: \x1a\x01[*](?P<status>[^*]+)[*]\x1b\x01.*Type: \x1a\x01[*](?P<type>[^*]+)[*]\x1b\x01.*Assignee: \x1a\x01[*](?P<assignee>[^*]+)[*]\x1b\x01.*Priority: \x1a\x01[*](?P<priority>[^*]+)[*]\x1b\x01''' +) + +def sanitize_jira(data, line): + m = first_line_re.search(line['message']) + if m: + return {'message': '%s | %s' % (m.group('title'), m.group('link'))} + + m = detail_line_re.search(line['message']) + if m: + return {'message': '%s / %s / %s' % (m.group('type'), m.group('status'), m.group('assignee'))} + + return {}