weechat/python/autoload/sanitize_jira.py @ abb473227306
Merge
author |
Steve Losh <steve@stevelosh.com> |
date |
Mon, 29 Mar 2021 11:34:42 -0400 |
parents |
18cc4d4f4ac4 |
children |
(none) |
import re, weechat, subprocess
SCRIPT_NAME = 'sanitize_jira'
SCRIPT_AUTHOR = 'Steve Losh <steve@stevelosh.com>'
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'(?P<link>https://[^/]+/browse/[^?]+)[?]atlOrigin=[^ ]+ [(](?P<title>.+)[)]'
)
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):
if 'sign up for an Atlassian account to view this link' in line['message']:
return {'message': ' '}
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 {}