2022-03-18 13:00:42 +00:00
|
|
|
import re
|
|
|
|
from modules import util
|
2023-03-06 21:54:01 +00:00
|
|
|
from modules.util import Failed
|
2022-03-18 13:00:42 +00:00
|
|
|
|
|
|
|
logger = util.logger
|
|
|
|
|
2023-03-06 21:54:01 +00:00
|
|
|
base_url = "https://api.github.com"
|
|
|
|
pmm_base = f"{base_url}/repos/meisnate12/Plex-Meta-Manager"
|
2022-07-13 05:13:25 +00:00
|
|
|
configs_raw_url = "https://raw.githubusercontent.com/meisnate12/Plex-Meta-Manager-Configs"
|
2022-03-18 13:00:42 +00:00
|
|
|
|
|
|
|
class GitHub:
|
|
|
|
def __init__(self, config):
|
|
|
|
self.config = config
|
2023-03-04 20:20:52 +00:00
|
|
|
self.images_raw_url = "https://raw.githubusercontent.com/meisnate12/PMM-Image-Sets/master/"
|
2022-07-13 05:13:25 +00:00
|
|
|
self._configs_url = None
|
2022-09-22 18:34:25 +00:00
|
|
|
self._config_tags = []
|
2022-03-18 13:00:42 +00:00
|
|
|
|
2023-03-06 21:54:01 +00:00
|
|
|
def get_top_tree(self, repo):
|
|
|
|
if not str(repo).startswith("/"):
|
|
|
|
repo = f"/{repo}"
|
|
|
|
if not str(repo).endswith("/"):
|
|
|
|
repo = f"{repo}/"
|
|
|
|
response = self.config.get(f"{base_url}/repos{repo}commits")
|
|
|
|
if response.status_code >= 400:
|
|
|
|
raise Failed(f"Git Error: No repo found at https://github.com{repo}")
|
|
|
|
return self.get_tree(response.json()[0]["commit"]["tree"]["url"]), repo
|
|
|
|
|
|
|
|
def get_tree(self, tree_url):
|
|
|
|
response = self.config.get(tree_url)
|
|
|
|
if response.status_code >= 400:
|
|
|
|
raise Failed(f"Git Error: No tree found at {tree_url}")
|
|
|
|
return {i["path"]: i for i in response.json()["tree"]}
|
|
|
|
|
2022-03-18 13:00:42 +00:00
|
|
|
def latest_release_notes(self):
|
2023-03-06 21:54:01 +00:00
|
|
|
response = self.config.get_json(f"{pmm_base}/releases/latest")
|
2022-03-18 13:00:42 +00:00
|
|
|
return response["body"]
|
|
|
|
|
2022-05-05 12:48:04 +00:00
|
|
|
def get_commits(self, dev_version, nightly=False):
|
2023-03-06 21:54:01 +00:00
|
|
|
master_sha = self.config.get_json(f"{pmm_base}/commits/master")["sha"]
|
|
|
|
response = self.config.get_json(f"{pmm_base}/commits", params={"sha": "nightly" if nightly else "develop"})
|
2022-03-18 13:00:42 +00:00
|
|
|
commits = []
|
|
|
|
for commit in response:
|
|
|
|
if commit["sha"] == master_sha:
|
|
|
|
break
|
|
|
|
message = commit["commit"]["message"]
|
|
|
|
match = re.match("^\\[(\\d)\\]", message)
|
|
|
|
if match and int(match.group(1)) <= dev_version:
|
|
|
|
break
|
|
|
|
commits.append(message)
|
|
|
|
return "\n".join(commits)
|
2022-07-13 05:13:25 +00:00
|
|
|
|
|
|
|
@property
|
2022-09-22 18:34:25 +00:00
|
|
|
def config_tags(self):
|
|
|
|
if not self._config_tags:
|
2022-07-13 05:13:25 +00:00
|
|
|
try:
|
2023-03-06 21:54:01 +00:00
|
|
|
self._config_tags = [r["ref"][11:] for r in self.config.get_json(f"{pmm_base}-Configs/git/refs/tags")]
|
2022-07-13 05:13:25 +00:00
|
|
|
except TypeError:
|
2022-09-22 18:34:25 +00:00
|
|
|
pass
|
|
|
|
return self._config_tags
|
|
|
|
|
|
|
|
@property
|
|
|
|
def configs_url(self):
|
|
|
|
if self._configs_url is None:
|
|
|
|
self._configs_url = f"{configs_raw_url}/master/"
|
2022-09-25 18:43:58 +00:00
|
|
|
if self.config.version[1] in self.config_tags and (
|
|
|
|
self.config.latest_version[1] != self.config.version[1]
|
|
|
|
or (not self.config.check_nightly and 0 <= self.config.version[2] <= util.get_develop()[2])
|
|
|
|
):
|
|
|
|
self._configs_url = f"{configs_raw_url}/v{self.config.version[1]}/"
|
2022-07-13 05:13:25 +00:00
|
|
|
return self._configs_url
|