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

Add single line display mode to gh issues #88

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
28 changes: 21 additions & 7 deletions gitsome/formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,13 +497,7 @@ def format_issue(self, view_entry):
:return: The formatted issue.
"""
issue = view_entry.item
item = self.format_index_title(view_entry.index, issue.title)
item += click.style('@' + str(issue.user) + ' ',
fg=self.config.clr_primary)
item += click.style(('(' +
self.format_issues_url_from_issue(issue) +
')'),
fg=self.config.clr_view_link)
item = self.format_issue_short(view_entry)
item += '\n'
indent = ' '
if len(item) == 8:
Expand All @@ -522,6 +516,26 @@ def format_issue(self, view_entry):
fg=self.config.clr_quaternary)
return item

def format_issue_short(self, view_entry):
"""Format an issue into a single line.

:type view_entry: :class:`github3` Issue
:param view_entry: An instance of `github3` Issue.

:rtype: str
:return: The formatted issue.
"""

issue = view_entry.item
item = self.format_index_title(view_entry.index, issue.title)
item += click.style('@' + str(issue.user) + ' ',
fg=self.config.clr_primary)
item += click.style(('(' +
self.format_issues_url_from_issue(issue) +
')'),
fg=self.config.clr_view_link)
return item

def format_repo(self, view_entry):
"""Format a repo.

Expand Down
17 changes: 14 additions & 3 deletions gitsome/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,8 @@ def issue(self, user_repo_number):
self.web_viewer.view_url(url)

@authenticate
def issues(self, issues_list, limit=1000, pager=False, sort=True):
def issues(self, issues_list, limit=1000, short=False, pager=False,
sort=True):
"""List all issues.

:type issues_list: list
Expand All @@ -430,6 +431,9 @@ def issues(self, issues_list, limit=1000, pager=False, sort=True):
:param pager: Determines whether to show the output in a pager,
if available.

:type short: bool
:param short: Determines whether to display only a single-line view.

:type sort: bool
:param sort: Determines whether to sort the issues by:
state, repo, created_at.
Expand All @@ -446,14 +450,20 @@ def issues(self, issues_list, limit=1000, pager=False, sort=True):
sort_key_tertiary=current_issue.created_at))
if sort:
view_entries = sorted(view_entries, reverse=False)

if short:
format_fn = self.formatter.format_issue_short
else:
format_fn = self.formatter.format_issue

self.table.build_table(view_entries,
limit,
pager,
self.formatter.format_issue)
format_fn)

@authenticate
def issues_setup(self, issue_filter='subscribed', issue_state='open',
limit=1000, pager=False):
limit=1000, short=False, pager=False):
"""Prepare to list all issues matching the filter.

:type issue_filter: str
Expand All @@ -472,6 +482,7 @@ def issues_setup(self, issue_filter='subscribed', issue_state='open',
"""
self.issues(self.config.api.issues(issue_filter, issue_state),
limit,
short,
pager)

@authenticate
Expand Down
10 changes: 8 additions & 2 deletions gitsome/githubcli.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,9 @@ def issue(github, user_repo_number):
@click.option('-s', '--issue_state', required=False, default='open')
@click.option('-l', '--limit', required=False, default=1000)
@click.option('-p', '--pager', is_flag=True)
@click.option('-t', '--short', is_flag=True)
@pass_github
def issues(github, issue_filter, issue_state, limit, pager):
def issues(github, issue_filter, issue_state, limit, short, pager):
"""List all issues matching the filter.

Usage:
Expand All @@ -364,6 +365,7 @@ def issues(github, issue_filter, issue_state, limit, pager):
gh issues -s all -l 20 -p
gh issues --issue_state closed --limit 20 --pager
gh issues -f created -s all -p
gh issues -t

:type github: :class:`github.GitHub`
:param github: An instance of `github.GitHub`.
Expand All @@ -377,11 +379,15 @@ def issues(github, issue_filter, issue_state, limit, pager):
:type limit: int
:param limit: The number of items to display.

:type short: bool
:param short: Determines whether to show a single-line view of
the issue.

:type pager: bool
:param pager: Determines whether to show the output in a pager,
if available.
"""
github.issues_setup(issue_filter, issue_state, limit, pager)
github.issues_setup(issue_filter, issue_state, limit, short, pager)

@cli.command()
@click.argument('license_name')
Expand Down
1 change: 1 addition & 0 deletions tests/data/issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@
# language governing permissions and limitations under the License.

formatted_issues = u'\x1b[35m 1. \x1b[0mtitle1 \x1b[0m@user2 \x1b[0m\x1b[35m(user1/repo1/issues/1)\x1b[0m\n\x1b[32m State: open \x1b[0m\x1b[36mComments: 1 \x1b[0m\x1b[33mAssignee: user1 \x1b[0m\n\x1b[35m 2. \x1b[0mtitle2 \x1b[0m@user2 \x1b[0m\x1b[35m(user1/repo1/issues/2)\x1b[0m\n\x1b[32m State: open \x1b[0m\x1b[36mComments: 1 \x1b[0m\x1b[33mAssignee: user1 \x1b[0m\n\x1b[35m 3. \x1b[0mtitle3 \x1b[0m@user2 \x1b[0m\x1b[35m(user1/repo1/issues/3)\x1b[0m\n\x1b[32m State: open \x1b[0m\x1b[36mComments: 1 \x1b[0m\x1b[33mAssignee: user1 \x1b[0m\n View the page for \x1b[0m\x1b[35m1 through \x1b[0m\x1b[35m3\x1b[0m with the following command:\n\x1b[0m\x1b[35m gh view [#] \x1b[0moptional: [-b/--browser] [--help]\n\x1b[0m\x1b[0m'
formatted_issues_short = u'\x1b[35m 1. \x1b[0mtitle1 \x1b[0m@user2 \x1b[0m\x1b[35m(user1/repo1/issues/1)\x1b[0m\n\x1b[35m 2. \x1b[0mtitle2 \x1b[0m@user2 \x1b[0m\x1b[35m(user1/repo1/issues/2)\x1b[0m\n\x1b[35m 3. \x1b[0mtitle3 \x1b[0m@user2 \x1b[0m\x1b[35m(user1/repo1/issues/3)\x1b[0m\n View the page for \x1b[0m\x1b[35m1 through \x1b[0m\x1b[35m3\x1b[0m with the following command:\n\x1b[0m\x1b[35m gh view [#] \x1b[0moptional: [-b/--browser] [--help]\n\x1b[0m\x1b[0m'
formatted_pull_requests = u'\x1b[35m 1. \x1b[0mtitle1 \x1b[0m@user2 \x1b[0m\x1b[35m(user1/repo1/issues/1)\x1b[0m\n\x1b[32m State: open \x1b[0m\x1b[36mComments: 1 \x1b[0m\x1b[33mAssignee: user1 \x1b[0m\n\x1b[35m 2. \x1b[0mtitle1 \x1b[0m@user2 \x1b[0m\x1b[35m(user1/repo1/issues/1)\x1b[0m\n\x1b[32m State: open \x1b[0m\x1b[36mComments: 1 \x1b[0m\x1b[33mAssignee: user1 \x1b[0m\n\x1b[35m 3. \x1b[0mtitle1 \x1b[0m@user2 \x1b[0m\x1b[35m(user1/repo1/issues/1)\x1b[0m\n\x1b[32m State: open \x1b[0m\x1b[36mComments: 1 \x1b[0m\x1b[33mAssignee: user1 \x1b[0m\n View the page for \x1b[0m\x1b[35m1 through \x1b[0m\x1b[35m3\x1b[0m with the following command:\n\x1b[0m\x1b[35m gh view [#] \x1b[0moptional: [-b/--browser] [--help]\n\x1b[0m\x1b[0m'
8 changes: 7 additions & 1 deletion tests/test_github.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
from tests.data.events import formatted_events
from tests.data.user import formatted_org, formatted_user, formatted_users
from tests.data.gitignores import formatted_gitignores, formatted_gitignores_tip
from tests.data.issue import formatted_issues, formatted_pull_requests
from tests.data.issue import (formatted_issues, formatted_issues_short,
formatted_pull_requests)
from tests.data.license import formatted_licenses, formatted_licenses_tip
from tests.data.thread import formatted_threads
from tests.data.trends import formatted_trends
Expand Down Expand Up @@ -192,6 +193,11 @@ def test_issues_setup(self, mock_click_secho):
self.github.issues_setup()
mock_click_secho.assert_called_with(formatted_issues)

@mock.patch('gitsome.github.click.secho')
def test_issues_setup_short(self, mock_click_secho):
self.github.issues_setup(short=True)
mock_click_secho.assert_called_with(formatted_issues_short)

@mock.patch('gitsome.github.click.secho')
def test_license(self, mock_click_secho):
self.github.license('valid_license')
Expand Down
3 changes: 2 additions & 1 deletion tests/test_github_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,9 @@ def test_issues(self, mock_gh_call):
'--issue_filter', 'mentioned',
'--issue_state', 'closed',
'--limit', '10',
'--short',
'--pager'])
mock_gh_call.assert_called_with('mentioned', 'closed', 10, True)
mock_gh_call.assert_called_with('mentioned', 'closed', 10, True, True)
assert result.exit_code == 0

@mock.patch('gitsome.githubcli.GitHub.license')
Expand Down