mirror of
https://github.com/outbackdingo/OpCore-Simplify.git
synced 2026-08-25 14:53:06 +00:00
Update functions to retrieve information from GitHub API
This commit is contained in:
@@ -63,7 +63,9 @@ class gatheringFiles:
|
|||||||
})
|
})
|
||||||
else:
|
else:
|
||||||
if self.github.check_ratelimit():
|
if self.github.check_ratelimit():
|
||||||
add_product_to_download_urls(self.github.get_latest_release(kext.github_repo.get("owner"), kext.github_repo.get("repo")))
|
latest_release = self.github.get_latest_release(kext.github_repo.get("owner"), kext.github_repo.get("repo")) or {}
|
||||||
|
|
||||||
|
add_product_to_download_urls(latest_release.get("assets"))
|
||||||
|
|
||||||
add_product_to_download_urls({
|
add_product_to_download_urls({
|
||||||
"product_name": "OpenCorePkg",
|
"product_name": "OpenCorePkg",
|
||||||
@@ -234,7 +236,9 @@ class gatheringFiles:
|
|||||||
if not isinstance(download_history, list):
|
if not isinstance(download_history, list):
|
||||||
download_history = []
|
download_history = []
|
||||||
|
|
||||||
for product in self.github.get_latest_release("lzhoang2801", "Hardware-Sniffer"):
|
latest_release = self.github.get_latest_release("lzhoang2801", "Hardware-Sniffer") or {}
|
||||||
|
|
||||||
|
for product in latest_release.get("assets"):
|
||||||
if product.get("product_name") == "Hardware-Sniffer-CLI":
|
if product.get("product_name") == "Hardware-Sniffer-CLI":
|
||||||
hardware_sniffer_cli = product
|
hardware_sniffer_cli = product
|
||||||
|
|
||||||
|
|||||||
+29
-7
@@ -24,12 +24,23 @@ class Github:
|
|||||||
|
|
||||||
response = self.fetcher.fetch_and_parse_content(url, "json")
|
response = self.fetcher.fetch_and_parse_content(url, "json")
|
||||||
|
|
||||||
return response[0]
|
try:
|
||||||
|
latest_commit = response[0].get("commit")
|
||||||
|
except:
|
||||||
|
return
|
||||||
|
|
||||||
|
if not isinstance(latest_commit, dict) or not latest_commit.get("tree"):
|
||||||
|
return
|
||||||
|
|
||||||
|
return {
|
||||||
|
"message": latest_commit.get("message").split("\n")[0],
|
||||||
|
"sha": latest_commit.get("tree").get("sha")
|
||||||
|
}
|
||||||
|
|
||||||
def get_latest_artifact(self, owner, repo):
|
def get_latest_artifact(self, owner, repo):
|
||||||
results = []
|
results = []
|
||||||
|
|
||||||
url = "https://api.github.com/repos/{}/{}/actions/artifacts?per_page=1".format(owner, repo)
|
url = "https://api.github.com/repos/{}/{}/actions/artifacts".format(owner, repo)
|
||||||
|
|
||||||
response = self.fetcher.fetch_and_parse_content(url, "json")
|
response = self.fetcher.fetch_and_parse_content(url, "json")
|
||||||
|
|
||||||
@@ -44,11 +55,19 @@ class Github:
|
|||||||
return results
|
return results
|
||||||
|
|
||||||
def get_latest_release(self, owner, repo):
|
def get_latest_release(self, owner, repo):
|
||||||
results = []
|
url = "https://api.github.com/repos/{}/{}/releases".format(owner, repo)
|
||||||
|
|
||||||
url = "https://api.github.com/repos/{}/{}/releases?per_page=1".format(owner, repo)
|
|
||||||
|
|
||||||
response = self.fetcher.fetch_and_parse_content(url, "json")
|
response = self.fetcher.fetch_and_parse_content(url, "json")
|
||||||
|
|
||||||
|
try:
|
||||||
|
latest_release = response[0]
|
||||||
|
except:
|
||||||
|
return
|
||||||
|
|
||||||
|
if not isinstance(latest_release, dict):
|
||||||
|
return
|
||||||
|
|
||||||
|
assets = []
|
||||||
|
|
||||||
for asset in response[0].get("assets"):
|
for asset in response[0].get("assets"):
|
||||||
asset_id = asset.get("id")
|
asset_id = asset.get("id")
|
||||||
@@ -56,13 +75,16 @@ class Github:
|
|||||||
asset_name = self.extract_asset_name(asset.get("name"))
|
asset_name = self.extract_asset_name(asset.get("name"))
|
||||||
|
|
||||||
if "tlwm" in download_url or ("tlwm" not in download_url and "DEBUG" not in download_url.upper()):
|
if "tlwm" in download_url or ("tlwm" not in download_url and "DEBUG" not in download_url.upper()):
|
||||||
results.append({
|
assets.append({
|
||||||
"product_name": asset_name,
|
"product_name": asset_name,
|
||||||
"id": asset_id,
|
"id": asset_id,
|
||||||
"url": download_url
|
"url": download_url
|
||||||
})
|
})
|
||||||
|
|
||||||
return results
|
return {
|
||||||
|
"describe": latest_release.get("body"),
|
||||||
|
"assets": assets
|
||||||
|
}
|
||||||
|
|
||||||
def extract_asset_name(self, file_name):
|
def extract_asset_name(self, file_name):
|
||||||
end_idx = len(file_name)
|
end_idx = len(file_name)
|
||||||
|
|||||||
+1
-1
@@ -29,7 +29,7 @@ class Updater:
|
|||||||
return current_sha_version.decode()
|
return current_sha_version.decode()
|
||||||
|
|
||||||
def get_latest_sha_version(self):
|
def get_latest_sha_version(self):
|
||||||
latest_commit = self.github.get_latest_commit("lzhoang2801", "OpCore-Simplify")
|
latest_commit = self.github.get_latest_commit("lzhoang2801", "OpCore-Simplify") or {}
|
||||||
|
|
||||||
return latest_commit.get("sha") or "0506fb67111d5c5230bf59b826c318ea4251dfc4"
|
return latest_commit.get("sha") or "0506fb67111d5c5230bf59b826c318ea4251dfc4"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user