diff --git a/Scripts/gathering_files.py b/Scripts/gathering_files.py index 245991e..21c7fda 100644 --- a/Scripts/gathering_files.py +++ b/Scripts/gathering_files.py @@ -64,10 +64,8 @@ class gatheringFiles: "url": dortania_builds_data[name]["versions"][0]["links"]["release"] }) else: - if self.github.check_ratelimit(): - 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")) + 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({ "product_name": "OpenCorePkg", diff --git a/Scripts/github.py b/Scripts/github.py index 1199775..fa2f7be 100644 --- a/Scripts/github.py +++ b/Scripts/github.py @@ -1,88 +1,73 @@ from Scripts import resource_fetcher from Scripts import utils +import random class Github: def __init__(self): self.utils = utils.Utils() - # Set the headers for GitHub API requests self.headers = { - "Accept": "application/vnd.github+json", - "#Authorization": "token GITHUB_TOKEN", - "X-GitHub-Api-Version": "2022-11-28", + "User-Agent": 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36' } self.fetcher = resource_fetcher.ResourceFetcher(self.headers) - - def check_ratelimit(self): - url = "https://api.github.com/rate_limit" - - response = self.fetcher.fetch_and_parse_content(url, "json") - - return response.get("rate").get("remaining") != 0 - def get_latest_commit(self, owner, repo): - url = "https://api.github.com/repos/{}/{}/commits".format(owner, repo) + def get_latest_commit(self, owner, repo, branch="main"): + url = "https://github.com/{}/{}/commits/{}".format(owner, repo, branch) - response = self.fetcher.fetch_and_parse_content(url, "json") + response = self.fetcher.fetch_and_parse_content(url) - try: - latest_commit = response[0].get("commit") - except: - return + for line in response.splitlines(): + if "href=\"" in line and "/commit/" in line and "title=\"" in line: + sha = line.split("href=\"", 1)[1].split("\"", 1)[0].split("/commit/")[-1] + try: + message = line.split("title=\"", 1)[1].split("\"", 1)[0] + except: + message = line.split(sha)[1].split(">", 1)[1].split("<")[0] - 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): - results = [] - - url = "https://api.github.com/repos/{}/{}/actions/artifacts".format(owner, repo) - - response = self.fetcher.fetch_and_parse_content(url, "json") - - latest_artifact_id = response.get("artifacts")[0].get("id") - - results.append({ - "product_name": repo, - "id": latest_artifact_id, - "url": "https://api.github.com/repos/{}/{}/actions/artifacts/{}/{}".format(owner, repo, latest_artifact_id, "zip") - }) - - return results + return { + "message": message, + "sha": sha + } + + return None def get_latest_release(self, owner, repo): - url = "https://api.github.com/repos/{}/{}/releases".format(owner, repo) + url = "https://github.com/{}/{}/releases".format(owner, repo) + response = self.fetcher.fetch_and_parse_content(url) - response = self.fetcher.fetch_and_parse_content(url, "json") - - try: - latest_release = response[0] - except: - return - - if not isinstance(latest_release, dict): - return - + body = "" + tag_name = None assets = [] + + for line in response.splitlines(): + if "