def _get_task_move(self, id, desc, body): ret = None username = util.get_regex_match(body, ">([^>]+) moved this task") movement = util.get_regex_match(body, "moved this task ([^\.]+)") if not util.should_ignore_username(username): short_message = "{} moved {} {}.".format(username, id, movement) long_message = "@{} moved *{}: {}* {}.".format( username, id, desc, movement) ret = Notification(id, desc, short_message, long_message) return ret
def _get_inline_comments(self, id, desc, body): ret = None username = util.get_regex_match(body, ">([^>]+) added inline comments") # found inline comments if not util.should_ignore_username(username): short_message = "{} added inline comments to {}.".format( username, id) long_message = "@{} added inline comments to *{}: {}*.".format( username, id, desc) soup = BeautifulSoup(body, 'html.parser') comment_divs = soup.select("div > strong + div > div > div > div") files = {} comments = [] # try to find any actual comments for div in comment_divs: # filter out those with color - those are old comments comments = [ comment.text for comment in div.select("p") if 'color' not in comment.parent['style'] ] for comment in comments: long_message = "{}\n```{}```".format(long_message, comment) ret = Notification(id, desc, short_message, long_message) return ret
def _handle_request_changes(self, id, desc, body): username = util.get_regex_match(body, ">([^>]+) requested changes to this revision.") if username is not None: self.handler.on_diff_request_changes(id, desc, username) elif 'This revision now requires changes to proceed' in body: self.handler.on_diff_request_changes(id, desc, None)
def _get_new_revision(self, id, desc, body): ret = None username = util.get_regex_match(body, ">([^>]+) created this revision") if not util.should_ignore_username(username): short_message = "{} created a new revision - {}: {}.".format( username, id, desc) long_message = "@" + short_message ret = Notification(id, desc, short_message, long_message) return ret
def _handle_comments(self, id, desc, body): username = util.get_regex_match(body, ">([^>]+) added a comment.") if username is not None: soup = BeautifulSoup(body, 'html.parser') paragraphs = soup.select("div > div > p") comment = None if len(paragraphs) > 0 and len(paragraphs[0].parent.text) > 0: comment = paragraphs[0].parent.text self.handler.on_task_comment(id, desc, username, comment)
def _handle_inline_comments(self, id, desc, body): username = util.get_regex_match(body, ">([^>]+) added inline comments") if username is not None: soup = BeautifulSoup(body, 'html.parser') comment_divs = soup.select("div > strong + div > div > div > div") comments = [] # try to find any actual comments for div in comment_divs: # filter out those with color - those are old comments new_comments = [comment.text for comment in div.select("p") if 'color' not in comment.parent['style']] comments += new_comments self.handler.on_diff_inline_comments(id, desc, username, comments)
def _get_comments(self, id, desc, body): ret = None username = util.get_regex_match(body, ">([^>]+) added a comment.") if not util.should_ignore_username(username): short_message = "{} added a comment to {}.".format(username, id) long_message = "@{} added a comment to *{}: {}*.".format( username, id, desc) soup = BeautifulSoup(body, 'html.parser') paragraphs = soup.select("div > div > p") if len(paragraphs) > 0 and len(paragraphs[0].parent.text) > 0: long_message = "{}\n```{}```".format(long_message, paragraphs[0].parent.text) ret = Notification(id, desc, short_message, long_message) return ret
def _get_request_changes(self, id, desc, body): ret = None username = util.get_regex_match( body, ">([^>]+) requested changes to this revision.") if not util.should_ignore_username(username): short_message = "{} requested changes to {}.".format(username, id) long_message = "@{} requested changes to {}: {}.".format( username, id, desc) ret = Notification(id, desc, short_message, long_message) elif 'This revision now requires changes to proceed' in body: short_message = "{} requires changes to proceed.".format(id) long_message = "*{}: {}* requires changes to proceed.".format( id, desc) ret = Notification(id, desc, short_message, long_message) return ret
def _get_notifications(self, open_ids, label, last_id, parser): self.connection.select(label) new_mail, last_id = self._get_new_email(last_id, open) notifications = [] for mail in new_mail: phab_id = util.regex_phab_id(mail['subject']) phab_desc = util.get_regex_match(mail['subject'], "[DT][0-9]+: (.*)") if phab_id in open_ids: body = mail.get_payload(decode=True) if mail.is_multipart(): body = ''.join( [str(p) for p in body.get_payload(decode=True)]) parsed = parser.parse(phab_id, phab_desc, body.decode()) notifications = notifications + parsed return notifications, last_id
def __init__(self, diff_str): self.id = util.get_regex_match(diff_str, "(D[0-9]+):") self.description = util.get_regex_match(diff_str, "D[0-9]+: (.*)").strip() self.status = util.get_regex_match(diff_str, "^\* ([a-zA-Z ]+) D").strip()
def __init__(self, task_str): self.id = util.get_regex_match(task_str, "(T[0-9]+)") self.description = util.get_regex_match(task_str, "T[0-9]+ (.+)\s\s+({})".format(conf.PRIORITIES)).strip() self.priority = util.get_regex_match(task_str, "T[0-9]+ .+\s\s+({})\s\s+".format(conf.PRIORITIES)).strip() self.status = util.get_regex_match(task_str, "T[0-9]+ .+\s\s+({})\s\s+(.*)".format(conf.PRIORITIES), match_num=2).strip()
def _handle_new_revision(self, id, desc, body): username = util.get_regex_match(body, ">([^>]+) created this revision") if username is not None: self.handler.on_diff_new(id, desc, username)
def _handle_task_move(self, id, desc, body): username = util.get_regex_match(body, ">([^>]+) moved this task") movement = util.get_regex_match(body, "moved this task ([^\.]+)") if username is not None: self.handler.on_task_move(id, desc, username)