-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
First pass at Swarm interface integration for inline comments #193
base: master
Are you sure you want to change the base?
Conversation
@@ -15,7 +15,7 @@ def __init__(self): | |||
self.messages = {} | |||
|
|||
def add_message(self, path, line, message): | |||
path = os.path.relpath(path).replace('\\', '/').strip() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moving the path updating to the interface-specific code
inlineplz/interfaces/swarm.py
Outdated
parameters = "topic={}&max={}".format(self.topic, max_comments) | ||
url = "https://{}/api/{}/comments".format(self.host, self.version) | ||
r = requests.get(url, auth=(self.username, self.password)) | ||
if (r.status_code != 200): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if r.status_code != requests.codes.ok:
inlineplz/interfaces/swarm.py
Outdated
def is_duplicate(comments, msg, body): | ||
for comment in comments: | ||
try: | ||
if (comment["context"]["rightLine"] == msg.line_number): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the parens here are unnecessary
inlineplz/interfaces/swarm.py
Outdated
try: | ||
if (comment["context"]["rightLine"] == msg.line_number): | ||
if (comment["context"]["file"] == msg.path): | ||
if (comment["body"].strip() == body.strip()): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you could just chain these into one if
inlineplz/interfaces/swarm.py
Outdated
from inlineplz.interfaces.base import InterfaceBase | ||
|
||
class SwarmInterface(InterfaceBase): | ||
def __init__(self, username, password, host, topic, version='v8'): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok so this is where you wanted to change this to taking some sort of config object that would be created in main.py
right?
updates from PR comments
and added comments to SwarmInterface
# giturlparse won't parse URLs that don't end in .git | ||
if not url_to_parse.endswith('.git'): | ||
url_to_parse += '.git' | ||
parsed = giturlparse.parse(url_to_parse) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think you need to add an import for giturlparse in this file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(and delete the giturlparse import from main.py)
inlineplz/interfaces/swarm.py
Outdated
@@ -0,0 +1,98 @@ | |||
# -*- coding: utf-8 -*- | |||
|
|||
import requests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
requests isnt a builtin module so it should be in a 2nd import group https://www.python.org/dev/peps/pep-0008/#imports
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Imports should be grouped in the following order:
standard library imports
related third party imports
local application/library specific imports
You should put a blank line between each group of imports.
self.password = args.password | ||
self.host = args.host | ||
self.topic = args.topic | ||
self.version = 'v8' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where does this version come from? can we document that?
from the failed CI. i added args.branch earlier today |
inlineplz/main.py
Outdated
parser.add_argument('--url', type=str, default=None) | ||
parser.add_argument('--username', type=str) | ||
parser.add_argument('--password', type=str) | ||
parser.add_argument('--host', type=str) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is host different from url? could we use the same arg for both?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a url, it's just the hostname (plus extra directories if needed). We could use a url as a base?
inlineplz/main.py
Outdated
parser.add_argument('--username', type=str) | ||
parser.add_argument('--password', type=str) | ||
parser.add_argument('--host', type=str) | ||
parser.add_argument('--topic', type=str) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we rename this to something like review-id
? and deprecate pull-request
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we could do review-id, I like that.
inlineplz/main.py
Outdated
parser.add_argument('--branch', type=str) | ||
parser.add_argument('--token', type=str) | ||
parser.add_argument('--branch', type=str, default=None) | ||
parser.add_argument('--token', type=str, default=None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need some sort of auth for p4?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and/or for swarm?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, it's in the username and password.
inlineplz/main.py
Outdated
parser.add_argument('--url', type=str) | ||
parser.add_argument('--url', type=str, default=None) | ||
parser.add_argument('--username', type=str) | ||
parser.add_argument('--password', type=str) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we somehow combine password / token into a single auth arg?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, we can do that.
""" | ||
review_id = args.review_id | ||
try: | ||
review_id = int(review_id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are swarm review IDs always integers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes
inlineplz/interfaces/swarm.py
Outdated
continue | ||
messages_to_post += 1 | ||
body = self.format_message(msg) | ||
proc = subprocess.Popen(["p4", "fstat", "-T", "depotFile", msg.path], stdout=subprocess.PIPE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i would prefer if we used subprocess.check_output
unless theres a good reason to do it this way.
inlineplz/interfaces/swarm.py
Outdated
proc = subprocess.Popen(["p4", "fstat", "-T", "depotFile", msg.path], stdout=subprocess.PIPE) | ||
output = proc.stdout.read() | ||
l = output.split() | ||
if (len(l) != 3): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unnecessary parens
the readme still references token:
|
looking at the console logs from the last run, although it passed, it doesnt look like it tried to run the github interface:
|
so i think something might be wrong with the github integration |
output = proc.stdout.read() | ||
try: | ||
output = subprocess.check_output(["p4", "fstat", "-T", "depotFile", msg.path]) | ||
except subprocess.CalledProcessError as procError: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
proc_error
would be the pythonic way to name a variable
@@ -70,8 +73,10 @@ def post_comment(self, body, path, line_number): | |||
'context[file]': path, | |||
'context[rightLine]': line_number | |||
} | |||
print("".format(payload)) | |||
requests.post(url, auth=(self.username, self.password), data=payload) | |||
#print("{}".format(payload)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
delete this?
requests.post(url, auth=(self.username, self.password), data=payload) | ||
#print("{}".format(payload)) | ||
response = requests.post(url, auth=(self.username, self.password), data=payload) | ||
if (response.status_code != requests.codes.ok): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unnecessary parens
No description provided.