Skip to content

Commit

Permalink
Chore: Change "print" to "log" in github_cli
Browse files Browse the repository at this point in the history
print statements should not be used for logging. These have been
replaced with log.info and log.error, where appropriate.

Change-Id: I919e5972dd887a0ed647b00250cbbe7a020f7d7e
Signed-off-by: Eric Ball <[email protected]>
  • Loading branch information
eb-oss committed Sep 28, 2023
1 parent dc2972b commit 885a4fa
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 22 deletions.
47 changes: 25 additions & 22 deletions lftools/cli/github_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from __future__ import print_function

import logging
import sys

import click
Expand All @@ -19,6 +20,8 @@
from lftools import config
from lftools.github_helper import helper_list, helper_user_github, prvotes

log = logging.getLogger(__name__)


@click.group()
@click.pass_context
Expand All @@ -44,16 +47,16 @@ def submit_pr(ctx, organization, repo, pr):
try:
org = g.get_organization(orgName)
except GithubException as ghe:
print(ghe)
log.error(ghe)

repo = org.get_repo(repo)
pr_mergable = repo.get_pull(pr).mergeable

if pr_mergable:
print(pr_mergable)
log.info(pr_mergable)
repo.get_pull(pr).merge(commit_message="Vote Completed, merging INFO file")
else:
print("PR NOT MERGABLE {}".format(pr_mergable))
log.error("PR NOT MERGABLE {}".format(pr_mergable))
sys.exit(1)


Expand All @@ -65,7 +68,7 @@ def submit_pr(ctx, organization, repo, pr):
def votes(ctx, organization, repo, pr):
"""Helper for votes."""
approval_list = prvotes(organization, repo, pr)
print("Approvals:", approval_list)
log.info("Approvals:", approval_list)


@click.command(name="list")
Expand Down Expand Up @@ -106,15 +109,15 @@ def createrepo(ctx, organization, repository, description, has_issues, has_proje
has_issues = has_issues or False
has_wiki = has_wiki or False
has_projects = has_projects or False
print("Creating repo under organization: ", orgName)
log.info("Creating repo under organization: ", orgName)
try:
org = g.get_organization(orgName)
except GithubException as ghe:
print(ghe)
log.error(ghe)
repos = org.get_repos()
for repo in repos:
if repo.name == repository:
print("repo already exists")
log.error("repo already exists")
sys.exit(1)
try:
org.create_repo(
Expand All @@ -128,7 +131,7 @@ def createrepo(ctx, organization, repository, description, has_issues, has_proje
private=False,
)
except GithubException as ghe:
print(ghe)
log.error(ghe)


@click.command(name="update-repo")
Expand Down Expand Up @@ -160,7 +163,7 @@ def updaterepo(ctx, organization, repository, has_issues, has_projects, has_wiki
try:
org = g.get_organization(orgName)
except GithubException as ghe:
print(ghe)
log.error(ghe)

repos = org.get_repos()

Expand All @@ -181,16 +184,16 @@ def updaterepo(ctx, organization, repository, has_issues, has_projects, has_wiki
try:
repo_actual
except NameError:
print("repo not found")
log.error("repo not found")
exit(1)

for team in teams():
if team.name == add_team:
print(team.id)
log.info(team.id)
team.add_to_repos(repo_actual)
team.set_repo_permission(repo_actual, "write")
if team.name == remove_team:
print(team.id)
log.info(team.id)
team.remove_from_repos(repo_actual)


Expand All @@ -213,49 +216,49 @@ def createteam(ctx, organization, name, repo, privacy):

g = Github(token)
orgName = organization
print("Creating team {} for repo {} under organization {} ".format(name, repo, orgName))
log.info("Creating team {} for repo {} under organization {} ".format(name, repo, orgName))
try:
org = g.get_organization(orgName)
except GithubException as ghe:
print(ghe)
log.error(ghe)

if repo:
try:
repos = org.get_repos
except GithubException as ghe:
print(ghe)
log.error(ghe)

my_repos = [repo]
repos = [repo for repo in repos() if repo.name in my_repos]
for repo in repos:
print(repo)
log.info(repo)
if repos:
print("repo found")
log.info("repo found")
else:
print("repo not found")
log.error("repo not found")
sys.exit(1)

try:
teams = org.get_teams
except GithubException as ghe:
print(ghe)
log.error(ghe)

for team in teams():
if team.name == name:
print("team {} already exists".format(team))
log.error("team {} already exists".format(team))
sys.exit(1)

if repo:
try:
org.create_team(name=name, repo_names=repos, privacy=privacy)
except GithubException as ghe:
print(ghe)
log.error(ghe)

if not repo:
try:
org.create_team(name=name, privacy=privacy)
except GithubException as ghe:
print(ghe)
log.error(ghe)


@click.command(name="user")
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ lxml
multi-key-dict
nodeenv
oauth2client
openstacksdk<1.5.0
pbr
pyasn1
pyasn1-modules
Expand Down

0 comments on commit 885a4fa

Please sign in to comment.