Skip to content

Commit

Permalink
fix: Handling empty issues & prs, added placeholder for github view
Browse files Browse the repository at this point in the history
  • Loading branch information
tomlin7 committed May 12, 2024
1 parent 9daf97b commit ab2274d
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 12 deletions.
39 changes: 27 additions & 12 deletions biscuit/core/components/views/sidebar/github/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import tkinter as tk

from biscuit.core.components.floating.palette import ActionSet
from biscuit.core.utils.label import WrappingLabel

from ..sidebarview import SidebarView
from .issues import Issues
Expand All @@ -24,27 +25,31 @@ def __init__(self, master, *args, **kwargs) -> None:
self.git = self.base.git

self.issues = Issues(self)
self.add_item(self.issues)

self.prs = PRs(self)
self.add_item(self.prs)

self.placeholder = WrappingLabel(self, text="Open a GitHub repository to see issues & pull requests.", font=self.base.settings.uifont,
**self.base.theme.utils.label)
self.placeholder.pack(fill=tk.X, side=tk.TOP)

self.base.bind("<<DirectoryChanged>>", self.on_directory_change, add=True)

def on_directory_change(self, e) -> None:
"""Event handler for directory change event."""

if not self.base.git_found:

if not (self.base.active_directory and self.base.git_found):
self.show_placeholder("Open a GitHub repository to see issues & pull requests.")
return

repo = self.git.repo
remote = repo.get_remote_origin()
if not remote:
self.base.notifications.error("No remote found for repository.")
self.base.notifications.info("No remote found.")
self.show_placeholder("No remote found.")
return

if not "github.com" in remote.url:

Check failure

Code scanning / CodeQL

Incomplete URL substring sanitization High

The string
github.com
may be at an arbitrary position in the sanitized URL.
self.base.notifications.info("Remote is not a GitHub repository.")
self.show_placeholder("Remote is not a GitHub repository.")
return

try:
Expand All @@ -54,8 +59,10 @@ def on_directory_change(self, e) -> None:
except Exception as e:
self.base.notifications.error(f"Failed to fetch remote info.")
self.base.logger.error(f"Failed to fetch remote info: {e}")
self.show_placeholder("Failed to fetch remote info.")
return

self.show_content()
threading.Thread(target=self.fetch_issues_and_prs, daemon=True).start()

def fetch_issues_and_prs(self) -> None:
Expand All @@ -64,9 +71,17 @@ def fetch_issues_and_prs(self) -> None:
self.issues.fetch()
self.prs.fetch()

# def toggle_active_editors(self):
# if self.active_editors_visible:
# self.open_editors.pack_forget()
# else:
# self.open_editors.pack(fill=tk.X, before=self.directory)
# self.active_editors_visible = not self.active_editors_visible
def show_placeholder(self, text: str) -> None:
"""Adds a placeholder label to the view."""

self.issues.pack_forget()
self.prs.pack_forget()
self.placeholder.config(text=text)
self.placeholder.pack(fill=tk.X, side=tk.TOP)

def show_content(self) -> None:
"""Shows the content of the view."""

self.placeholder.pack_forget()
self.issues.pack(fill=tk.BOTH, expand=True)
self.prs.pack(fill=tk.BOTH, expand=True)
2 changes: 2 additions & 0 deletions biscuit/core/components/views/sidebar/github/prs.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ def __init__(self, master, itembar=True, *args, **kwargs) -> None:
def set_url(self, owner: str, repo: str) -> None:
"""Sets the URL for the current repository."""

self.owner = owner
self.repo = repo
self.url = self.url_template.format(owner, repo)

def on_click(self, *_) -> None:
Expand Down
1 change: 1 addition & 0 deletions biscuit/core/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ def close_active_directory(self) -> None:
self.set_title()
self.git_found = False
self.update_git()
self.event_generate("<<DirectoryChanged>>")

def close_active_editor(self) -> None:
self.editorsmanager.close_active_editor()
Expand Down
1 change: 1 addition & 0 deletions biscuit/core/settings/config/theme/theme.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ def __init__(self, *args, **kwargs) -> None:
theme = self.master

self.button = HighlightableThemeObject(self, theme.biscuit, "white", theme.biscuit_dark)
self.label = ThemeObject(self)
self.linklabel = ThemeObject(self, theme.secondary_background, theme.biscuit, self.highlightbackground)
self.colorlabel = ThemeObject(self, theme.biscuit, "white", theme.biscuit_dark)
self.tree = FrameThemeObject(self)
Expand Down

0 comments on commit ab2274d

Please sign in to comment.