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

Refactor conversion of None to empty introduced in #49 and #40 #93

Closed
wants to merge 1 commit into from
Closed
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
6 changes: 4 additions & 2 deletions gitsome/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from .table import Table
from .view_entry import ViewEntry
from .web_viewer import WebViewer
from .utils import TextUtils


class GitHub(object):
Expand Down Expand Up @@ -68,6 +69,7 @@ def __init__(self):
self.table = Table(self.config)
self.web_viewer = WebViewer(self.config)
self.trend_parser = feedparser
self.text_utils = TextUtils()

def authenticate(func):
"""Decorator that authenticates credentials.
Expand Down Expand Up @@ -222,7 +224,7 @@ def create_issue(self, user_repo, issue_title, issue_desc=''):
issue_title,
issue_desc)
if type(issue) is not null.NullObject:
body = issue.body if issue.body is not None else ''
body = self.text_utils.sanitize_if_none(issue.body)
click.secho('Created issue: ' + issue.title + '\n' + body,
fg=self.config.clr_message)
else:
Expand All @@ -245,7 +247,7 @@ def create_repo(self, repo_name, repo_desc='', private=False):
repo = self.config.api.create_repository(repo_name,
repo_desc,
private=private)
desc = repo.description if repo.description is not None else ''
desc = self.text_utils.sanitize_if_none(repo.description)
click.secho(('Created repo: ' + repo.full_name + '\n' + desc),
fg=self.config.clr_message)
except UnprocessableEntity as e:
Expand Down
11 changes: 11 additions & 0 deletions gitsome/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,14 @@ def _safe_split(self, text):
return words
except:
return text

def sanitize_if_none(self, text):
"""Sanitizes text to ensure it is not None
Copy link
Owner

Choose a reason for hiding this comment

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

Could you PEP-257-ify this docstring to the following?

Sanitize text to ensure it is not None.


:type text:str
:param text: String to sanitize
Copy link
Owner

Choose a reason for hiding this comment

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

Also, a period here.

String to sanitize.


:rtype: str
:return: String which is empty if None.
"""
return text if text is not None else ''