Skip to content
This repository has been archived by the owner on Oct 13, 2023. It is now read-only.

find-bugs:qe - Use local logger instead of click.echo #561

Merged
merged 2 commits into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions elliottlib/bzutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,13 +482,13 @@ def update_bug_status(self, bug: Bug, target_status: str,
current_status = bug.status
action = f'changed {bug.id} from {current_status} to {target_status}'
if current_status == target_status:
click.echo(f'{bug.id} is already on {target_status}')
logger.info(f'{bug.id} is already on {target_status}')
return False
elif noop:
click.echo(f"Would have {action}")
logger.info(f"Would have {action}")
else:
self._update_bug_status(bug.id, target_status)
click.echo(action)
logger.info(action)

comment_lines = []
if log_comment:
Expand Down Expand Up @@ -676,7 +676,7 @@ def _update_bug_status(self, bugid, target_status):

def add_comment(self, bugid: str, comment: str, private: bool, noop=False):
if noop:
click.echo(f"Would have added a private={private} comment to {bugid}")
logger.info(f"Would have added a private={private} comment to {bugid}")
return
if private:
self._client.add_comment(bugid, comment, visibility={'type': 'group', 'value': 'Red Hat Employee'})
Expand Down Expand Up @@ -724,7 +724,7 @@ def _query(self, bugids: Optional[List] = None,

def _search(self, query, verbose=False) -> List[JIRABug]:
if verbose:
click.echo(query)
logger.info(query)
results = self._client.search_issues(query, maxResults=0)
return [JIRABug(j) for j in results]

Expand Down Expand Up @@ -832,7 +832,7 @@ def get_bugs(self, bugids, permissive=False, **kwargs):
return []
if 'verbose' in kwargs:
if kwargs.pop('verbose'):
click.echo(f'get_bugs called with bugids: {bugids}, permissive: {permissive} and kwargs: {kwargs}')
logger.info(f'get_bugs called with bugids: {bugids}, permissive: {permissive} and kwargs: {kwargs}')
bugs = [BugzillaBug(b) for b in self._client.getbugs(bugids, permissive=permissive, **kwargs)]
if len(bugs) < len(bugids):
bugids_not_found = set(bugids) - {b.id for b in bugs}
Expand All @@ -859,7 +859,7 @@ def cve_tracker_search(self, status, search_filter='default', verbose=False):

def _search(self, query, verbose=False):
if verbose:
click.echo(query)
logger.info(query)
return [BugzillaBug(b) for b in _perform_query(self._client, query)]

def remove_bugs(self, advisory_obj, bugids: List, noop=False):
Expand Down
10 changes: 5 additions & 5 deletions elliottlib/cli/find_bugs_qe_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from elliottlib import (Runtime, logutil)
from elliottlib.cli.common import cli
from elliottlib.cli.find_bugs_sweep_cli import FindBugsMode
from elliottlib.util import green_prefix


LOGGER = logutil.getLogger(__name__)

Expand Down Expand Up @@ -39,8 +39,8 @@ def find_bugs_qe_cli(runtime: Runtime, noop):
try:
find_bugs_qe(runtime, find_bugs_obj, noop, b)
except Exception as e:
runtime.logger.error(traceback.format_exc())
runtime.logger.error(f'exception with {b.type} bug tracker: {e}')
LOGGER.error(traceback.format_exc())
LOGGER.error(f'exception with {b.type} bug tracker: {e}')
exit_code = 1
sys.exit(exit_code)

Expand All @@ -49,10 +49,10 @@ def find_bugs_qe(runtime, find_bugs_obj, noop, bug_tracker):
major_version, minor_version = runtime.get_major_minor()
statuses = sorted(find_bugs_obj.status)
tr = bug_tracker.target_release()
green_prefix(f"Searching {bug_tracker.type} for bugs with status {statuses} and target releases: {tr}\n")
LOGGER.info(f"Searching {bug_tracker.type} for bugs with status {statuses} and target releases: {tr}")

bugs = find_bugs_obj.search(bug_tracker_obj=bug_tracker, verbose=runtime.debug)
click.echo(f"Found {len(bugs)} bugs: {', '.join(sorted(str(b.id) for b in bugs))}")
LOGGER.info(f"Found {len(bugs)} bugs: {', '.join(sorted(str(b.id) for b in bugs))}")

release_comment = (
"An ART build cycle completed after this fix was made, which usually means it can be"
Expand Down
6 changes: 0 additions & 6 deletions tests/test_find_bugs_qe_cli.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import unittest
import os
from unittest.mock import patch
from click.testing import CliRunner
from elliottlib.cli.common import cli, Runtime
from elliottlib.cli.find_bugs_qe_cli import FindBugsQE
Expand Down Expand Up @@ -37,10 +35,6 @@ def test_find_bugs_qe(self):
bz_bug, 'ON_QA', comment=expected_comment, noop=True
)
result = runner.invoke(cli, ['-g', 'openshift-4.6', 'find-bugs:qe', '--noop'])
search_string1 = 'Found 1 bugs: OCPBUGS-123'
search_string2 = 'Found 1 bugs: BZ-123'
self.assertIn(search_string1, result.output)
self.assertIn(search_string2, result.output)
self.assertEqual(result.exit_code, 0)


Expand Down