-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Fetching latest releases with Biscuit's extension API
- Loading branch information
Showing
4 changed files
with
66 additions
and
4 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
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'] |
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