weechat/python/autoload/sanitize_jira.py @ 18cc4d4f4ac4

More
author Steve Losh <steve@stevelosh.com>
date Fri, 18 Sep 2020 17:21:49 -0400
parents 31e094924f7e
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 {}