From 5ff7d2061e9458ac84d07676bffaffe3d49b009c Mon Sep 17 00:00:00 2001 From: "James E. Blair" Date: Thu, 20 Feb 2020 10:27:12 -0800 Subject: [PATCH] Support robot comments Change-Id: I8623bb2de9a9d7b6f162cd99ae0ea13a320c5a6b --- .../versions/6f6183367a8f_robot_comments.py | 30 +++++++++++++++++++ gertty/db.py | 9 +++++- gertty/sync.py | 15 ++++++++-- 3 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 gertty/alembic/versions/6f6183367a8f_robot_comments.py diff --git a/gertty/alembic/versions/6f6183367a8f_robot_comments.py b/gertty/alembic/versions/6f6183367a8f_robot_comments.py new file mode 100644 index 0000000..ed1464c --- /dev/null +++ b/gertty/alembic/versions/6f6183367a8f_robot_comments.py @@ -0,0 +1,30 @@ +"""robot-comments + +Revision ID: 6f6183367a8f +Revises: a18731009699 +Create Date: 2020-02-20 10:11:56.409361 + +""" + +# revision identifiers, used by Alembic. +revision = '6f6183367a8f' +down_revision = 'a18731009699' + +import warnings + +from alembic import op +import sqlalchemy as sa + +from gertty.dbsupport import sqlite_alter_columns + + +def upgrade(): + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + op.add_column('comment', sa.Column('robot_id', sa.String(255))) + op.add_column('comment', sa.Column('robot_run_id', sa.String(255))) + op.add_column('comment', sa.Column('url', sa.Text())) + + +def downgrade(): + pass diff --git a/gertty/db.py b/gertty/db.py index e39a050..fe40748 100644 --- a/gertty/db.py +++ b/gertty/db.py @@ -134,6 +134,9 @@ comment_table = Table( Column('line', Integer), Column('message', Text, nullable=False), Column('draft', Boolean, index=True, nullable=False), + Column('robot_id', String(255)), + Column('robot_run_id', String(255)), + Column('url', Text()), ) label_table = Table( 'label', metadata, @@ -543,7 +546,8 @@ class Message(object): return author_name class Comment(object): - def __init__(self, file, id, author, in_reply_to, created, parent, line, message, draft=False): + def __init__(self, file, id, author, in_reply_to, created, parent, line, message, draft=False, + robot_id=None, robot_run_id=None, url=None): self.file_key = file.key self.account_key = author.key self.id = id @@ -553,6 +557,9 @@ class Comment(object): self.line = line self.message = message self.draft = draft + self.robot_id = robot_id + self.robot_run_id = robot_run_id + self.url = url class Label(object): def __init__(self, change, category, value, description): diff --git a/gertty/sync.py b/gertty/sync.py index 8f54723..f7e22fc 100644 --- a/gertty/sync.py +++ b/gertty/sync.py @@ -24,6 +24,7 @@ import json import time import datetime import warnings +import itertools import dateutil.parser try: @@ -591,6 +592,10 @@ class SyncChangeTask(Task): for remote_commit, remote_revision in remote_change.get('revisions', {}).items(): remote_comments_data = sync.get('changes/%s/revisions/%s/comments' % (self.change_id, remote_commit)) remote_revision['_gertty_remote_comments_data'] = remote_comments_data + if sync.version >= (2,14,0): + remote_robot_comments_data = sync.get('changes/%s/revisions/%s/robotcomments' % ( + self.change_id, remote_commit)) + remote_revision['_gertty_remote_robot_comments_data'] = remote_robot_comments_data try: remote_conflicts = sync.query(['q=status:open+is:mergeable+conflicts:%s' % remote_change['_number']]) @@ -739,8 +744,9 @@ class SyncChangeTask(Task): remote_file.get('old_path'), inserted, deleted) - remote_comments_data = remote_revision['_gertty_remote_comments_data'] - for remote_file, remote_comments in remote_comments_data.items(): + remote_comments_items = list(remote_revision['_gertty_remote_comments_data'].items()) + remote_robot_comments_items = list(remote_revision.get('_gertty_remote_robot_comments_data', {}).items()) + for remote_file, remote_comments in itertools.chain(remote_comments_items, remote_robot_comments_items): for remote_comment in remote_comments: account = session.getAccountByID(remote_comment['author']['_account_id'], name=remote_comment['author'].get('name'), @@ -760,7 +766,10 @@ class SyncChangeTask(Task): remote_comment.get('in_reply_to'), created, parent, remote_comment.get('line'), - remote_comment['message']) + remote_comment['message'], + robot_id = remote_comment.get('robot_id'), + robot_run_id = remote_comment.get('robot_run_id'), + url = remote_comment.get('url')) self.log.info("Created new comment %s for revision %s in local DB.", comment.key, revision.key) else: