weechat-old/python/sanitize_jira.py @ 5dd4e6c93b90

More
author Steve Losh <steve@stevelosh.com>
date Tue, 23 Jan 2024 10:17:59 -0500
parents a9f1df02501f
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 {}