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

GitCommitBear: Block invalid email addresses #6

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

Conversation

rhemon
Copy link
Owner

@rhemon rhemon commented Jul 23, 2017

Uses validate_email to check invalid email
addresses in git commit message.

Fixes coala#1791

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!

Uses validate_email to check invalid email
addresses in git commit message.

Fixes coala#1791
@rhemon
Copy link
Owner Author

rhemon commented Jul 24, 2017

Comment on f1548c1.

Shortlog of HEAD commit isn't in imperative mood! Bad words are 'trying'

GitCommitBear, severity NORMAL, section commit.

@rhemon
Copy link
Owner Author

rhemon commented Jul 24, 2017

Comment on f1548c1.

Shortlog of HEAD commit isn't in imperative mood! Bad words are 'trying'

GitCommitBear, severity NORMAL, section commit.

@rhemon rhemon added size/L and removed size/M labels Jul 24, 2017
@rhemon
Copy link
Owner Author

rhemon commented Jul 24, 2017

Comment on f1548c1.

Shortlog of HEAD commit isn't in imperative mood! Bad words are 'trying'

GitCommitBear, severity NORMAL, section commit.

@rhemon
Copy link
Owner Author

rhemon commented Jul 24, 2017

Comment on f1548c1.

Shortlog of HEAD commit isn't in imperative mood! Bad words are 'trying'

GitCommitBear, severity NORMAL, section commit.

@rhemon
Copy link
Owner Author

rhemon commented Jul 24, 2017

Comment on ec558ce.

Shortlog of HEAD commit isn't in imperative mood! Bad words are 'removing'

GitCommitBear, severity NORMAL, section commit.

@rhemon
Copy link
Owner Author

rhemon commented Jul 24, 2017

Comment on f1548c1.

Shortlog of HEAD commit isn't in imperative mood! Bad words are 'trying'

GitCommitBear, severity NORMAL, section commit.

@rhemon
Copy link
Owner Author

rhemon commented Jul 24, 2017

Comment on ec558ce.

Shortlog of HEAD commit isn't in imperative mood! Bad words are 'removing'

GitCommitBear, severity NORMAL, section commit.

for email in re.findall(r'\w+@+\w+\.+\w*', line):
if is_email(email, diagnose=True, check_dns=True).ERROR_CODES:
invalid_emails = True
result_message += ' ' + email + '\n'
Copy link
Owner Author

Choose a reason for hiding this comment

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

Line is longer than allowed. (82 > 79)

LineLengthBear, severity NORMAL, section linelength.

@@ -236,6 +239,8 @@ def check_body(self, body,
expressions in this list will be ignored.
:param body_regex: If provided, checks the presence of regex
in the commit body.
:param verify_email: Checks validity of emails in commit body if
present.
Copy link
Owner Author

Choose a reason for hiding this comment

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

Line is longer than allowed. (80 > 79)

LineLengthBear, severity NORMAL, section linelength.

# Testing if check recognises invalid emails
self.git_commit('Shortlog\n\n'
'A valid email [email protected]\n'
'An invalid email [email protected]\n'
Copy link
Owner Author

Choose a reason for hiding this comment

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

Line is longer than allowed. (87 > 79)

LineLengthBear, severity NORMAL, section linelength.

# Testing if check recognises invalid emails
self.git_commit('Shortlog\n\n'
'A valid email [email protected]\n'
'An invalid email [email protected]\n'
Copy link
Owner Author

Choose a reason for hiding this comment

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

E501 line too long (87 > 79 characters)'

PycodestyleBear (E501), severity NORMAL, section autopep8.

for email in re.findall(r'\w+@+\w+\.+\w*', line):
if is_email(email, diagnose=True, check_dns=True).ERROR_CODES:
invalid_emails = True
result_message += ' ' + email + '\n'
Copy link
Owner Author

Choose a reason for hiding this comment

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

E501 line too long (82 > 79 characters)'

PycodestyleBear (E501), severity NORMAL, section autopep8.

@@ -236,6 +239,8 @@ def check_body(self, body,
expressions in this list will be ignored.
:param body_regex: If provided, checks the presence of regex
in the commit body.
:param verify_email: Checks validity of emails in commit body if
present.
Copy link
Owner Author

Choose a reason for hiding this comment

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

E501 line too long (80 > 79 characters)'

PycodestyleBear (E501), severity NORMAL, section autopep8.

@rhemon rhemon added size/XL and removed size/L labels Jul 26, 2017
@rhemon
Copy link
Owner Author

rhemon commented Jul 26, 2017

Comment on f1548c1.

Shortlog of HEAD commit isn't in imperative mood! Bad words are 'trying'

GitCommitBear, severity NORMAL, section commit.

@rhemon
Copy link
Owner Author

rhemon commented Jul 26, 2017

Comment on ec558ce.

Shortlog of HEAD commit isn't in imperative mood! Bad words are 'removing'

GitCommitBear, severity NORMAL, section commit.

# Testing if check recognises invalid emails
self.git_commit('Shortlog\n\n'
'A valid email [email protected]\n'
'An invalid email [email protected]\n'
Copy link
Owner Author

Choose a reason for hiding this comment

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

E501 line too long (87 > 79 characters)'

PycodestyleBear (E501), severity NORMAL, section autopep8.

for email in re.findall(r'\w+@+\w+\.+\w*', line):
if is_email(email, diagnose=True, check_dns=True).ERROR_CODES:
invalid_emails = True
result_message += ' ' + email + '\n'
Copy link
Owner Author

Choose a reason for hiding this comment

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

E501 line too long (82 > 79 characters)'

PycodestyleBear (E501), severity NORMAL, section autopep8.

@@ -236,6 +239,8 @@ def check_body(self, body,
expressions in this list will be ignored.
:param body_regex: If provided, checks the presence of regex
in the commit body.
:param verify_email: Checks validity of emails in commit body if
present.
Copy link
Owner Author

Choose a reason for hiding this comment

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

E501 line too long (80 > 79 characters)'

PycodestyleBear (E501), severity NORMAL, section autopep8.

# Testing if check recognises invalid emails
self.git_commit('Shortlog\n\n'
'A valid email [email protected]\n'
'An invalid email [email protected]\n'
Copy link
Owner Author

Choose a reason for hiding this comment

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

Line is longer than allowed. (87 > 79)

LineLengthBear, severity NORMAL, section linelength.

for email in re.findall(r'\w+@+\w+\.+\w*', line):
if is_email(email, diagnose=True, check_dns=True).ERROR_CODES:
invalid_emails = True
result_message += ' ' + email + '\n'
Copy link
Owner Author

Choose a reason for hiding this comment

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

Line is longer than allowed. (82 > 79)

LineLengthBear, severity NORMAL, section linelength.

@@ -236,6 +239,8 @@ def check_body(self, body,
expressions in this list will be ignored.
:param body_regex: If provided, checks the presence of regex
in the commit body.
:param verify_email: Checks validity of emails in commit body if
present.
Copy link
Owner Author

Choose a reason for hiding this comment

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

Line is longer than allowed. (80 > 79)

LineLengthBear, severity NORMAL, section linelength.

@@ -260,6 +268,25 @@ def check_body(self, body,
'Commit body lines should not exceed {} '
'characters.'.format(body_line_length))

Copy link
Owner Author

Choose a reason for hiding this comment

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

E128 continuation line under-indented for visual indent'

PycodestyleBear (E128), severity NORMAL, section autopep8.

:param valid_email_check: If True, it checks if emails are in valid
format or not
:param email_dns_check: If True, it checks if domains in the emails
are valid or not
"""
if len(body) == 0:
Copy link
Owner Author

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'

PycodestyleBear (E225), severity NORMAL, section autopep8.

:param valid_email_check: If True, it checks if emails are in valid
format or not
:param email_dns_check: If True, it checks if domains in the emails
are valid or not
"""
Copy link
Owner Author

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'

PycodestyleBear (E225), severity NORMAL, section autopep8.

@@ -260,6 +268,25 @@ def check_body(self, body,
'Commit body lines should not exceed {} '
'characters.'.format(body_line_length))

Copy link
Owner Author

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.

PEP8Bear, severity NORMAL, section autopep8.

The issue can be fixed by applying the following patch:

--- a/bears/vcs/git/GitCommitBear.py
+++ b/bears/vcs/git/GitCommitBear.py
@@ -280,7 +280,7 @@
                     # look up dns
                     if email_dns_check and email_check:
                         email_check = not is_email(email, diagnose=True,
-                                               check_dns=True).ERROR_CODES
+                                                   check_dns=True).ERROR_CODES
                     if not email_check:
                         invalid_emails = True
                         result_message += ' ' + email + '\n'

:param valid_email_check: If True, it checks if emails are in valid
format or not
:param email_dns_check: If True, it checks if domains in the emails
are valid or not
"""
Copy link
Owner Author

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.

PEP8Bear, severity NORMAL, section autopep8.

The issue can be fixed by applying the following patch:

--- a/bears/vcs/git/GitCommitBear.py
+++ b/bears/vcs/git/GitCommitBear.py
@@ -274,8 +274,8 @@
             for line in body:
                 for email in re.findall(r'\S*@\S*', line):
                     email_check = re.match(r"(^[a-zA-Z0-9_.+-]"
-                                           +r"+@[a-zA-Z0-9-]+\."
-                                           +r"[a-zA-Z0-9-.]+$)", email)
+                                           + r"+@[a-zA-Z0-9-]+\."
+                                           + r"[a-zA-Z0-9-.]+$)", email)
                     # if eamil do not match regex there is no need to
                     # look up dns
                     if email_dns_check and email_check:

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

Successfully merging this pull request may close these issues.

GitCommitBear: Block invalid email addresses
1 participant