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

HTTPSBear.py: New Bear Added #2063

Merged
merged 1 commit into from
Apr 22, 2018
Merged

HTTPSBear.py: New Bear Added #2063

merged 1 commit into from
Apr 22, 2018

Conversation

stellargo
Copy link
Member

@stellargo stellargo commented Oct 3, 2017

HTTPS bear can detect URL links which can be changed to https
from http and allows to change them automatically.

Closes #1900

For short term contributors: we understand that getting your commits well
defined like we require is a hard task and takes some learning. If you
look to help without wanting to contribute long term there's no need
for you to learn this. Just drop us a message and we'll take care of brushing
up your stuff for merge!

Checklist

  • I read the commit guidelines and I've followed
    them.
  • I ran coala over my code locally. (All commits have to pass
    individually.
    It is not sufficient to have "fixup commits" on your PR,
    our bot will still report the issues for the previous commit.) You will
    likely receive a lot of bot comments and build failures if coala does not
    pass on every single commit!

After you submit your pull request, DO NOT click the 'Update Branch' button.
When asked for a rebase, consult coala.io/rebase
instead.

Please consider helping us by reviewing other peoples pull requests as well:

The more you review, the more your score will grow at coala.io and we will
review your PRs faster!

"""
for result in dependency_results.get(URLBear.name, []):
line_number, link, code, context = result.contents
if (link[0:5]!='https'):
Copy link
Collaborator

Choose a reason for hiding this comment

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

The code does not comply to PEP8.

Origin: PEP8Bear, Section: autopep8.

The issue can be fixed by applying the following patch:

--- a/tmp/tmps3czyfyb/bears/general/HTTPSBear.py
+++ b/tmp/tmps3czyfyb/bears/general/HTTPSBear.py
@@ -61,7 +61,7 @@
         """
         for result in dependency_results.get(URLBear.name, []):
             line_number, link, code, context = result.contents
-            if (link[0:5]!='https'):
+            if (link[0:5] != 'https'):
                 httpslink = 'https' + link[4:]
                 host = urlparse(httpslink).netloc
                 network_timeout = {urlparse(url).netloc

"""
for result in dependency_results.get(URLBear.name, []):
line_number, link, code, context = result.contents
if (link[0:5]!='https'):
Copy link
Collaborator

Choose a reason for hiding this comment

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

E225 missing whitespace around operator

Origin: PycodestyleBear (E225), Section: autopep8.

# def __init__(self, origin, affected_code,
# link: str,
# http_status_code: (int, None),
# link_context: LINK_CONTEXT):
Copy link
Member

Choose a reason for hiding this comment

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

commented code ;)

Copy link
Member Author

@stellargo stellargo Oct 3, 2017

Choose a reason for hiding this comment

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

@Makman2 Yeah still working on it :P I still have to write tests and get it to solve the problem on its own , also remove unnecessary imports :P


from coalib.bears.LocalBear import LocalBear
from dependency_management.requirements.PipRequirement import PipRequirement
from coalib.bearlib import deprecate_settings
Copy link
Member

Choose a reason for hiding this comment

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

unused import


from coalib.bears.LocalBear import LocalBear
from dependency_management.requirements.PipRequirement import PipRequirement
from coalib.bearlib import deprecate_settings
Copy link
Member

Choose a reason for hiding this comment

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

Generally many unused imports...

'{url}').format(url=link),
file=filename,
line=line_number,
severity=RESULT_SEVERITY.NORMAL)
Copy link
Member

Choose a reason for hiding this comment

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

we definitely want a patch ;)

yield Result.from_values(
origin=self,
message=('You could use https instead of http at - '
'{url}').format(url=link),
Copy link
Member

Choose a reason for hiding this comment

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

with a patch you don't have to include the link in the message ;)

all your data.

:param dependency_results: Results given by URLBear.
:param follow_redirects: Set to true to autocorrect redirects.
Copy link
Member

Choose a reason for hiding this comment

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

-->

:param a:
    ABC
:param b:
    DEF

BEAR_DEPS = {URLBear}

def run(self, filename, file, dependency_results=dict(),
follow_redirects: bool=False,
Copy link
Member

Choose a reason for hiding this comment

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

unused parameter

else network_timeout.get('*')
if '*' in network_timeout
else URLBear.DEFAULT_TIMEOUT
)
Copy link
Member

Choose a reason for hiding this comment

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

bad indent ;)

end = start + len(link)
replacement = 'https' + link[4:]
replacement = current_line[:start] +
'https' + link[4:] + current_line[end:]
Copy link
Collaborator

Choose a reason for hiding this comment

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

E113 unexpected indentation

Origin: PycodestyleBear (E113), Section: autopep8.

end = start + len(link)
replacement = 'https' + link[4:]
replacement = current_line[:start] +
'https' + link[4:] + current_line[end:]
Copy link
Collaborator

Choose a reason for hiding this comment

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

E113 unexpected indentation

Origin: PycodestyleBear (E113), Section: autopep8.

HTTP_PREFIX = 'http'

def run(self, filename, file, dependency_results=dict(),
network_timeout: typed_dict(str, int, DEFAULT_TIMEOUT)=dict()):
Copy link
Member

Choose a reason for hiding this comment

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

style change requires spaces around =

@stellargo
Copy link
Member Author

stellargo commented Apr 22, 2018

@jayvdb So basically this bear needs to use URLHeadBear to get a response for the new https link obtained from http. Problem is that when there is no such link it returns a ConnectTimeout Exception. This obviously does not have a status_code attribute. Hence i have used the try except block. But this is making testing extremely problematic because the custom_matcher first checks prerequisites and the LocalBearTestHelper immediately raises AssertionError. This was not the problem earlier when the URLBear hadn't been split into the two bears as then it would just return None for the attribute status_code. So either we could re change the URLHeadBear's get_head_response method to the way it was, or use the pragma no cover which I have added right now.
Other bears like InvalidLinkBear are not having this problem because they are just dependent on the URLHeadBear's result and don't want to make any more head response for status codes.

Copy link
Member

@jayvdb jayvdb left a comment

Choose a reason for hiding this comment

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

Im happy to let this pragma in. we can worry about that later.

A few style issues.

network_timeout = {
urlparse(url).netloc if not url == '*' else '*': timeout
for url, timeout in network_timeout.items()}
httpsresponse = URLHeadBear.get_head_response(
Copy link
Member

Choose a reason for hiding this comment

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

snake_case (everywhere)

current_line = file[line_number - 1]
start = current_line.find(link)
end = start + len(link)
replacement = current_line[:start] + 'https' + \
Copy link
Member

Choose a reason for hiding this comment

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

dont use \


yield Result.from_values(
origin=self,
message=('https can be used instead of http'),
Copy link
Member

Choose a reason for hiding this comment

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

why ()?

HTTPS bear can detect URL links which can be changed to https
from http and changes them if the user wants.

Closes coala#1900
@jayvdb
Copy link
Member

jayvdb commented Apr 22, 2018

ack bbfb116

@jayvdb
Copy link
Member

jayvdb commented Apr 22, 2018

@gitmate-bot ff

@gitmate-bot
Copy link
Collaborator

Hey! I'm GitMate.io! This pull request is being fastforwarded automatically. Please DO NOT push while fastforward is in progress or your changes would be lost permanently ⚠️

@gitmate-bot
Copy link
Collaborator

Automated fastforward with GitMate.io was successful! 🎉

@gitmate-bot gitmate-bot merged commit bbfb116 into coala:master Apr 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

Bear Proposal HTTPS bear
7 participants