Skip to content
This repository has been archived by the owner on Jul 6, 2020. It is now read-only.

Commit

Permalink
Added verbosity flag to hide files outside of diff.
Browse files Browse the repository at this point in the history
  • Loading branch information
freakboy3742 committed Sep 16, 2018
1 parent b0fdb17 commit d94b9ad
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 17 deletions.
3 changes: 3 additions & 0 deletions src/beefore/__main__.py
Expand Up @@ -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(
Expand Down Expand Up @@ -85,6 +86,7 @@ def main():
directory=options.directory,
repository=repository,
branch=options.branch,
verbosity=options.verbosity,
)

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

print()
Expand Down
2 changes: 1 addition & 1 deletion src/beefore/checks/dco.py
Expand Up @@ -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']:
Expand Down
19 changes: 15 additions & 4 deletions src/beefore/checks/eslint.py
Expand Up @@ -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
19 changes: 15 additions & 4 deletions src/beefore/checks/javacheckstyle.py
Expand Up @@ -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
19 changes: 15 additions & 4 deletions src/beefore/checks/pycodestyle.py
Expand Up @@ -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
5 changes: 3 additions & 2 deletions src/beefore/github.py
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
5 changes: 3 additions & 2 deletions src/beefore/local.py
Expand Up @@ -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)

Expand Down

0 comments on commit d94b9ad

Please sign in to comment.