Skip to content

Commit

Permalink
refactor: don't run isatty if we don't need to
Browse files Browse the repository at this point in the history
isatty on stdout fails during tests, this change makes less tests
fail
  • Loading branch information
kylef committed Jul 13, 2024
1 parent 0472dd2 commit a8eb043
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 20 deletions.
19 changes: 4 additions & 15 deletions goji/client.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,14 @@
import datetime
import mimetypes
import os
import pickle
from typing import Any, Generator, List, Optional
from typing import Any, Dict, Generator, List, Optional

import click
import requests
from requests.auth import AuthBase, HTTPBasicAuth
from requests.compat import urljoin

from goji.models import (
Attachment,
Comment,
Comments,
Issue,
IssueLinkType,
SearchResults,
Sprint,
Transition,
UserDetails,
)
from goji.models import (Attachment, Comment, Comments, Issue, IssueLinkType,
SearchResults, Sprint, Transition, UserDetails)


class JIRAException(click.ClickException):
Expand Down Expand Up @@ -170,7 +159,7 @@ def search(
max_results: Optional[int] = None,
start_at: Optional[int] = None,
) -> SearchResults:
body = {'jql': query}
body: Dict[str, Any] = {'jql': query}

if start_at:
body['startAt'] = start_at
Expand Down
5 changes: 3 additions & 2 deletions goji/commands.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import importlib
import io
import pkgutil
import sys
from os import isatty
Expand Down Expand Up @@ -354,7 +355,7 @@ def search(client: JIRAClient, all: bool, count: bool, format: str, limit: Optio
return

formatter = Formatter()
fields = [v[1] for v in formatter.parse(format)]
fields = [v[1] for v in formatter.parse(format) if v[1]]

if all:
issues = client.search_all(query, fields=fields)
Expand All @@ -372,7 +373,7 @@ def search(client: JIRAClient, all: bool, count: bool, format: str, limit: Optio
resolution=issue.resolution,
)

if isatty(sys.stdout.fileno()):
if 'key' in fields and not isinstance(sys.stdout, io.TextIOWrapper) and isatty(sys.stdout.fileno()):
url = urljoin(client.base_url, 'browse/%s' % issue.key)
format_kwargs['key'] = f'\033]8;;{url}\a{issue.key}\033]8;;\a'

Expand Down
4 changes: 2 additions & 2 deletions goji/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ def __init__(self, key: str):
self.key = key
self.summary = None
self.description = None
self.creator: Optional[User] = None
self.creator: Optional[UserDetails] = None
self.created: Optional[datetime] = None
self.resolutiondate: Optional[datetime] = None
self.assignee: Optional[User] = None
self.assignee: Optional[UserDetails] = None
self.status: Optional['StatusDetails'] = None
self.resolution: Optional[Resolution] = None
self.links: List['IssueLink'] = []
Expand Down
3 changes: 2 additions & 1 deletion tests/models/test_issue.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import unittest

from goji.models import Issue, IssueLink, IssueLinkType, StatusCategory, StatusDetails
from goji.models import (Issue, IssueLink, IssueLinkType, StatusCategory,
StatusDetails)
from tests.server import OPEN_STATUS


Expand Down

0 comments on commit a8eb043

Please sign in to comment.