-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'tomlin7:main' into fix/linux-icon
- Loading branch information
Showing
30 changed files
with
414 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
biscuit/core/components/views/sidebar/github/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import os | ||
import threading | ||
import tkinter as tk | ||
|
||
from biscuit.core.components.floating.palette import ActionSet | ||
from biscuit.core.utils import WrappingLabel | ||
|
||
from ..sidebarview import SidebarView | ||
from .issues import Issues | ||
from .menu import GitHubMenu | ||
from .prs import PRs | ||
|
||
|
||
class GitHub(SidebarView): | ||
def __init__(self, master, *args, **kwargs) -> None: | ||
self.__buttons__ = [('refresh', self.on_directory_change)] | ||
super().__init__(master, *args, **kwargs) | ||
self.__icon__ = 'github' | ||
self.name = 'GitHub' | ||
|
||
self.menu = GitHubMenu(self, 'files') | ||
self.menu.add_checkable("Open Issues", self.toggle_issues, checked=True) | ||
self.menu.add_checkable("Pull Requests", self.toggle_prs, checked=True) | ||
self.add_button('ellipsis', self.menu.show) | ||
|
||
self.issues_enabled = True | ||
self.prs_enabled = True | ||
|
||
self.git = self.base.git | ||
self.issues = Issues(self) | ||
self.prs = PRs(self) | ||
|
||
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.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.info("No remote found.") | ||
self.show_placeholder("No remote found.") | ||
return | ||
|
||
if not "github.com" in remote.url: | ||
self.base.notifications.info("Remote is not a GitHub repository.") | ||
self.show_placeholder("Remote is not a GitHub repository.") | ||
return | ||
|
||
try: | ||
owner, repo_name = repo.get_owner_and_repo(remote.url) | ||
self.issues.set_url(owner, repo_name) | ||
self.prs.set_url(owner, repo_name) | ||
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: | ||
"""Fetches issues and PRs from the current repository.""" | ||
|
||
self.issues.fetch() | ||
self.prs.fetch() | ||
|
||
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() | ||
if self.issues_enabled: | ||
self.issues.pack(fill=tk.BOTH, expand=True) | ||
if self.prs_enabled: | ||
self.prs.pack(fill=tk.BOTH, expand=True) | ||
|
||
def toggle_issues(self) -> None: | ||
"""Toggles the visibility of the issues view.""" | ||
|
||
if self.issues_enabled: | ||
self.issues.pack_forget() | ||
else: | ||
self.issues.pack(fill=tk.BOTH, expand=True) | ||
self.issues_enabled = not self.issues_enabled | ||
|
||
def toggle_prs(self) -> None: | ||
"""Toggles the visibility of the PRs view.""" | ||
|
||
if self.prs_enabled: | ||
self.prs.pack_forget() | ||
else: | ||
self.prs.pack(fill=tk.BOTH, expand=True) | ||
self.prs_enabled = not self.prs_enabled |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import json | ||
import tkinter as tk | ||
import typing | ||
import webbrowser | ||
from tkinter import ttk | ||
|
||
import requests | ||
|
||
from biscuit.core.components.floating.palette.actionset import ActionSet | ||
from biscuit.core.utils.scrollbar import Scrollbar | ||
|
||
from ..item import SidebarViewItem | ||
|
||
|
||
class Issues(SidebarViewItem): | ||
def __init__(self, master, itembar=True, *args, **kwargs) -> None: | ||
self.title = 'Open Issues' | ||
self.__buttons__ = () | ||
super().__init__(master, itembar=itembar, *args, **kwargs) | ||
|
||
self.url_template = "https://api.github.com/repos/{}/{}/issues" | ||
self.url = None | ||
self.owner = None | ||
self.repo = None | ||
|
||
self.tree = ttk.Treeview(self.content, selectmode=tk.BROWSE, | ||
show="tree", displaycolumns='', columns=("link")) | ||
self.tree.grid(row=0, column=0, sticky=tk.NSEW) | ||
self.tree.bind("<Double-Button-1>", self.on_click) | ||
|
||
self.scrollbar = Scrollbar(self.content, style='TreeScrollbar', orient=tk.VERTICAL, command=self.tree.yview) | ||
self.scrollbar.grid(row=0, column=1, sticky=tk.NS) | ||
self.tree.config(yscrollcommand=self.scrollbar.set) | ||
|
||
self.issues_actionset = ActionSet("Search GitHub issues", "issue:", []) | ||
self.base.palette.register_actionset(lambda: self.issues_actionset) | ||
|
||
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: | ||
"""Event handler for treeview item click event.""" | ||
|
||
try: | ||
item = self.tree.selection()[0] | ||
link = self.tree.item(item, "values")[0] | ||
webbrowser.open(link) | ||
except Exception as e: | ||
pass | ||
|
||
def fetch(self) -> typing.List[dict]: | ||
"""Fetches issues from the current repository.""" | ||
|
||
response = requests.get(self.url) | ||
if response.status_code != 200: | ||
self.base.notifications.error(f"Failed to fetch issues from {self.owner}/{self.repo}") | ||
return | ||
|
||
issues = json.loads(response.text) | ||
if not issues: | ||
return | ||
|
||
self.issues_actionset.update([(f"{issue['title']} #{issue['number']}", lambda *_, link=issue['html_url']: webbrowser.open(link)) for issue in issues]) | ||
issues = ((f"{issue['title']} #{issue['number']}", issue['html_url']) for issue in issues) | ||
|
||
self.tree.delete(*self.tree.get_children()) | ||
for issue in issues: | ||
self.tree.insert('', tk.END, text=issue[0], values=(issue[1],)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from biscuit.core.components.floating import Menu | ||
|
||
|
||
class GitHubMenu(Menu): | ||
def get_coords(self, e) -> list: | ||
return e.widget.winfo_rootx(), e.widget.winfo_rooty() + e.widget.winfo_height() |
Oops, something went wrong.