from Scripts import resource_fetcher from Scripts import utils import random class Github: def __init__(self): self.utils = utils.Utils() self.fetcher = resource_fetcher.ResourceFetcher() 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) if not response: raise ValueError("Failed to fetch commit information from GitHub.") 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] return { "message": message, "sha": sha } return None def get_latest_release(self, owner, repo): url = "https://github.com/{}/{}/releases".format(owner, repo) response = self.fetcher.fetch_and_parse_content(url) if not response: raise ValueError("Failed to fetch release information from GitHub.") tag_name = self._extract_tag_name(response) body = self._extract_body_content(response) release_tag_url = "https://github.com/{}/{}/releases/expanded_assets/{}".format(owner, repo, tag_name) response = self.fetcher.fetch_and_parse_content(release_tag_url) if not response: raise ValueError("Failed to fetch expanded assets information from GitHub.") assets = self._extract_assets(response) return { "body": body, "assets": assets } def _extract_tag_name(self, response): for line in response.splitlines(): if "", 1)[0], 1)[1].split("", 1)[0][1:] return "" def _extract_assets(self, response): assets = [] in_li_block = False download_link = None for line in response.splitlines(): if "