Support robot comments

Change-Id: I8623bb2de9a9d7b6f162cd99ae0ea13a320c5a6b
This commit is contained in:
James E. Blair 2020-02-20 10:27:12 -08:00
parent b6ba991215
commit 5ff7d2061e
3 changed files with 50 additions and 4 deletions

View File

@ -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

View File

@ -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):

View File

@ -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: