Skip to content
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

Open
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

wparks
Copy link
Collaborator

@wparks wparks commented Mar 16, 2018

No description provided.

@@ -15,7 +15,7 @@ def __init__(self):
self.messages = {}

def add_message(self, path, line, message):
path = os.path.relpath(path).replace('\\', '/').strip()
Copy link
Collaborator Author

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

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):
Copy link
Owner

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:

def is_duplicate(comments, msg, body):
for comment in comments:
try:
if (comment["context"]["rightLine"] == msg.line_number):
Copy link
Owner

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

try:
if (comment["context"]["rightLine"] == msg.line_number):
if (comment["context"]["file"] == msg.path):
if (comment["body"].strip() == body.strip()):
Copy link
Owner

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

from inlineplz.interfaces.base import InterfaceBase

class SwarmInterface(InterfaceBase):
def __init__(self, username, password, host, topic, version='v8'):
Copy link
Owner

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?

# 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)
Copy link
Owner

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

Copy link
Owner

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)

@@ -0,0 +1,98 @@
# -*- coding: utf-8 -*-

import requests
Copy link
Owner

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

Copy link
Owner

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'
Copy link
Owner

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?

@guykisel
Copy link
Owner

guykisel commented Mar 16, 2018

Traceback (most recent call last):
  File "/home/travis/virtualenv/python3.6.3/bin/inline-plz", line 11, in <module>
    load_entry_point('inlineplz', 'console_scripts', 'inline-plz')()
  File "/home/travis/build/guykisel/inline-plz/inlineplz/main.py", line 61, in main
    result = inline(args)
  File "/home/travis/build/guykisel/inline-plz/inlineplz/main.py", line 148, in inline
    my_interface = interfaces.INTERFACES[args.interface](args)
  File "/home/travis/build/guykisel/inline-plz/inlineplz/interfaces/github.py", line 63, in __init__
    if branch and not pr:
NameError: name 'branch' is not defined

from the failed CI. i added args.branch earlier today

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)
Copy link
Owner

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?

Copy link
Collaborator Author

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?

parser.add_argument('--username', type=str)
parser.add_argument('--password', type=str)
parser.add_argument('--host', type=str)
parser.add_argument('--topic', type=str)
Copy link
Owner

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?

Copy link
Collaborator Author

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.

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)
Copy link
Owner

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?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and/or for swarm?

Copy link
Collaborator Author

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.

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)
Copy link
Owner

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?

Copy link
Collaborator Author

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)
Copy link
Owner

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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

continue
messages_to_post += 1
body = self.format_message(msg)
proc = subprocess.Popen(["p4", "fstat", "-T", "depotFile", msg.path], stdout=subprocess.PIPE)
Copy link
Owner

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.

proc = subprocess.Popen(["p4", "fstat", "-T", "depotFile", msg.path], stdout=subprocess.PIPE)
output = proc.stdout.read()
l = output.split()
if (len(l) != 3):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unnecessary parens

@guykisel
Copy link
Owner

the readme still references token:

You'll also need to provide the following either in the command line or via environment variables:

owner: the repo organization/owner
repo: the repo name
token: your auth token (encrypt this, don't put this in plaintext in any public configurations!)
url: the url of your scm host
interface: the type of scm host (such as github)

@guykisel
Copy link
Owner

looking at the console logs from the last run, although it passed, it doesnt look like it tried to run the github interface:

Parsing of stylint took 0 seconds
Running linter: jsonlint
b'+ [email protected]\nadded 124 packages in 5.157s\n\nnpm WARN deprecated [email protected]: Package no longer supported. Contact [email protected] for more info.\nnpm WARN saveError ENOENT: no such file or directory, open \'/home/travis/build/guykisel/inline-plz/package.json\'\nnpm WARN enoent ENOENT: no such file or directory, open \'/home/travis/build/guykisel/inline-plz/package.json\'\nnpm WARN inline-plz No description\nnpm WARN inline-plz No repository field.\nnpm WARN inline-plz No README data\nnpm WARN inline-plz No license field.\nnpm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/fsevents):\nnpm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})'
['node_modules/.bin/jsonlint', '-c', '-q']
Installation and running of jsonlint took 5 seconds
Parsing of jsonlint took 0 seconds
675 lint messages found
inline-plz version: 0.26.1
Python version: 3.6.3 (default, Nov 28 2017, 18:47:21) 
[GCC 4.8.4]
Last SHA: 1206f79c7a7ba0c9f5a70db6a857a9a164d6e61e
inline-plz version: 0.26.1
Python version: 3.6.3 (default, Nov 28 2017, 18:47:21) 
[GCC 4.8.4]
inline-plz ran for 40 seconds
inline-plz returned exit code 0

travis_time:end:03584e56:start=1521260769120624562,finish=1521260809879847019,duration=40759222457
�[0K
�[32;1mThe command "inline-plz --autorun" exited with 0.�[0m```

@guykisel
Copy link
Owner

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:
Copy link
Owner

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))
Copy link
Owner

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):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unnecessary parens

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants