weechat/python/autoload/sanitize_jira.py @ dfb5e299d678

More
author Steve Losh <steve@stevelosh.com>
date Tue, 08 Sep 2020 14:03:40 -0400
parents 31e094924f7e
children 18cc4d4f4ac4
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):
    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 {}