Permalink
Browse files

Added verbosity flag to hide files outside of diff.

  • Loading branch information...
freakboy3742 committed Sep 16, 2018
1 parent b0fdb17 commit d94b9ada5a84d7e45a567c4fb0f9b3f02fe48967
@@ -15,6 +15,7 @@ def main():
parser = ArgumentParser()

parser.add_argument('--version', action='version', version=__version__)
parser.add_argument('--verbosity', '-v', dest='verbosity', action='count')

# GitHub required arguments...
username_arg = parser.add_argument(
@@ -85,6 +86,7 @@ def main():
directory=options.directory,
repository=repository,
branch=options.branch,
verbosity=options.verbosity,
)

except git.InvalidGitRepositoryError:
@@ -115,6 +117,7 @@ def main():
repo_path=options.repo_path,
pull_request=options.pull_request,
sha=options.sha,
verbosity=options.verbosity,
)

print()
@@ -23,7 +23,7 @@ def prepare(directory):
pass


def check(directory, diff_content, commit):
def check(directory, diff_content, commit, verbosity):
expected_signoff = '\nSigned-off-by: '

if expected_signoff in commit['message']:
@@ -116,25 +116,36 @@ def prepare(directory):
install_eslint_config(directory)


def check(directory, diff_content, commit):
def check(directory, diff_content, commit, verbosity):
results = []

lint_results = Lint.find(directory=directory)
diff_mappings = diff.positions(directory, diff_content)

for filename, problems in lint_results.items():
print(" * %s" % filename)
file_seen = False
if filename in diff_mappings:
for problem in sorted(problems, key=lambda p: p.line):
try:
position = diff_mappings[filename][problem.line]
if not file_seen:
print(" * %s" % filename)
file_seen = True
print(' - %s' % problem)
results.append((problem, position))
except KeyError:
# Line doesn't exist in the diff; so we can ignore this problem
print(' - Line %s not in diff' % problem.line)
if verbosity:
if not file_seen:
print(" * %s" % filename)
file_seen = True
print(' - Line %s not in diff' % problem.line)
else:
# File has been changed, but wasn't in the diff
print(' - file not in diff')
if verbosity:
if not file_seen:
print(" * %s" % filename)
file_seen = True
print(' - file not in diff')

return results
@@ -62,25 +62,36 @@ def prepare(directory):
pass


def check(directory, diff_content, commit):
def check(directory, diff_content, commit, verbosity):
results = []

lint_results = Lint.find(directory=directory)
diff_mappings = diff.positions(directory, diff_content)

for filename, problems in lint_results.items():
print(" * %s" % filename)
file_seen = False
if filename in diff_mappings:
for problem in sorted(problems, key=lambda p: p.line):
try:
position = diff_mappings[filename][problem.line]
if not file_seen:
print(" * %s" % filename)
file_seen = True
print(' - %s' % problem)
results.append((problem, position))
except KeyError:
# Line doesn't exist in the diff; so we can ignore this problem
print(' - Line %s not in diff' % problem.line)
if verbosity:
if not file_seen:
print(" * %s" % filename)
file_seen = True
print(' - Line %s not in diff' % problem.line)
else:
# File has been changed, but wasn't in the diff
print(' - file not in diff')
if verbosity:
if not file_seen:
print(" * %s" % filename)
file_seen = True
print(' - file not in diff')

return results
@@ -68,25 +68,36 @@ def prepare(directory):
pass


def check(directory, diff_content, commit):
def check(directory, diff_content, commit, verbosity):
results = []

lint_results = Lint.find(directory=directory)
diff_mappings = diff.positions(directory, diff_content)

for filename, problems in lint_results.items():
print(" * %s" % filename)
file_seen = False
if filename in diff_mappings:
for problem in sorted(problems, key=lambda p: p.line):
try:
position = diff_mappings[filename][problem.line]
if not file_seen:
print(" * %s" % filename)
file_seen = True
print(' - %s' % problem)
results.append((problem, position))
except KeyError:
# Line doesn't exist in the diff; so we can ignore this problem
print(' - Line %s not in diff' % problem.line)
if verbosity:
if not file_seen:
print(" * %s" % filename)
file_seen = True
print(' - Line %s not in diff' % problem.line)
else:
# File has been changed, but wasn't in the diff
print(' - file not in diff')
if verbosity:
if not file_seen:
print(" * %s" % filename)
file_seen = True
print(' - file not in diff')

return results
@@ -4,7 +4,7 @@
from github3.exceptions import GitHubError


def check(check_module, directory, username, password, repo_path, pull_request, sha):
def check(check_module, directory, username, password, repo_path, pull_request, sha, verbosity):
try:
github = github3.login(username, password=password)
except GitHubError as ghe:
@@ -56,7 +56,8 @@ def check(check_module, directory, username, password, repo_path, pull_request,
problems = check_module.check(
directory=directory,
diff_content=diff_content,
commit=commit.commit
commit=commit.commit,
verbosity=verbosity,
)

for problem, position in problems:
@@ -44,15 +44,16 @@ def full_diff(repository, branch='master'):
return content


def check(check_module, directory, repository, branch):
def check(check_module, directory, repository, branch, verbosity):
print("Running %s check..." % check_module.__name__)
print('==========' * 8)
problems = check_module.check(
directory=directory,
diff_content=full_diff(repository, branch=branch),
commit={
'message': repository.commit().message
}
},
verbosity=verbosity,
)
print('==========' * 8)

0 comments on commit d94b9ad

Please sign in to comment.