Skip to content

Commit

Permalink
feat: Fetching latest releases with Biscuit's extension API
Browse files Browse the repository at this point in the history
  • Loading branch information
tomlin7 committed May 15, 2024
1 parent ae804a2 commit e6778b4
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 4 deletions.
4 changes: 4 additions & 0 deletions biscuit/core/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import typing

from biscuit.core.api.releases import Releases

if typing.TYPE_CHECKING:
from biscuit.core import App

Expand Down Expand Up @@ -40,6 +42,8 @@ def __init__(self, base: App) -> None:
self.utils = Utils(self.base)
self.views = Views(self.base)

self.releases = Releases(self.base)

self.Game = BaseGame
self.Editor = BaseEditor

Expand Down
58 changes: 58 additions & 0 deletions biscuit/core/api/releases.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import json

import requests


class Releases:
"""A class to interact with the GitHub API to get release information.
If extensions require any prebuilt binaries, use the methods in this class."""

def __init__(self, base=None):
self.base = base

def get(self, url: str):
resp = requests.get(url)
if resp.status_code == 200:
return json.loads(resp.text)

def get_latest_release(self, owner: str, repo: str):
return self.get(f"https://api.github.com/repos/{owner}/{repo}/releases/latest")

def get_release(self, owner: str, repo: str, tag: str):
return self.get(f"https://api.github.com/repos/{owner}/{repo}/releases/tags/{tag}")

def get_latest_windows_release(self, owner: str, repo: str):
resp = self.get_latest_release(owner, repo)
for asset in resp['assets']:
if "-windows-" in asset['name'].lower():
return asset['browser_download_url']

def get_latest_macos_release(self, owner: str, repo: str):
resp = self.get_latest_release(owner, repo)
for asset in resp['assets']:
if "-mac-" in asset['name'].lower():
return asset['browser_download_url']

def get_latest_linux_release(self, owner: str, repo: str):
resp = self.get_latest_release(owner, repo)
for asset in resp['assets']:
if "-linux-" in asset['name'].lower():
return asset['browser_download_url']

def get_windows_release(self, owner: str, repo: str, tag: str):
resp = self.get_release(owner, repo, tag)
for asset in resp['assets']:
if "-windows-" in asset['name'].lower():
return asset['browser_download_url']

def get_macos_release(self, owner: str, repo: str, tag: str):
resp = self.get_release(owner, repo, tag)
for asset in resp['assets']:
if "-mac-" in asset['name'].lower():
return asset['browser_download_url']

def get_linux_release(self, owner: str, repo: str, tag: str):
resp = self.get_release(owner, repo, tag)
for asset in resp['assets']:
if "-linux-" in asset['name'].lower():
return asset['browser_download_url']
2 changes: 1 addition & 1 deletion biscuit/core/components/lsp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def _update_symbols(self, tab, resp) -> None:
#TODO: currently only supports lsp.SymbolInformation; implement this for lsp.DocumentSymbol
pass

def register_langserver(self, language, command) -> None:
def register_langserver(self, language: str, command: str) -> None:
self.langservers[language] = command

def tab_opened(self, tab: Text) -> None:
Expand Down
6 changes: 3 additions & 3 deletions biscuit/core/components/lsp/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@


class IO:
def __init__(self, master: App, cmd: str, cwd: str) -> None:
def __init__(self, master, cmd: str, cwd: str) -> None:
"""IO for LSP Client
Attributes
Expand All @@ -28,7 +28,7 @@ def __init__(self, master: App, cmd: str, cwd: str) -> None:
"""

self.master = master
self.base = master.base
self.base: App = master.base
self.alive = True
self.cmd = cmd
self.cwd = cwd
Expand All @@ -55,7 +55,7 @@ def read(self) -> None:
def start(self, *_) -> None:
"Start the process"
self.p = subprocess.Popen(
self.cmd,
self.cmd, cwd=self.cwd,
stdout=subprocess.PIPE,
stdin=subprocess.PIPE,
stderr=subprocess.PIPE,
Expand Down

0 comments on commit e6778b4

Please sign in to comment.