From b4647a3c6b7718d7e8712631ab99628d7deaa04e Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Sun, 7 Jan 2024 13:30:02 +0000 Subject: [PATCH] feat(updatechecker): added gitea/forgejo support --- updatechecker/updatechecker.py | 42 +++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/updatechecker/updatechecker.py b/updatechecker/updatechecker.py index 0ed5cc2..520d116 100644 --- a/updatechecker/updatechecker.py +++ b/updatechecker/updatechecker.py @@ -37,7 +37,7 @@ import aiohttp import discord from redbot.cogs.downloader.repo_manager import Repo from redbot.core import Config, commands -from redbot.core.utils.chat_formatting import humanize_list, inline +from redbot.core.utils.chat_formatting import box, humanize_list, inline import feedparser @@ -113,15 +113,26 @@ class UpdateChecker(commands.Cog): repo = cog._repo_manager.get_repo(repo_name) if not repo: continue - url = repo.url + r"/commits/" + repo.branch + ".atom" - response = await self.fetch_feed(url) - try: - commit = response.entries[0]["id"][33:] - hash = "[" + commit + "](" + response.entries[0]["link"] + ")" - cn = response.entries[0]["title"] + " - " + response.entries[0]["author"] - image = response.entries[0]["media_thumbnail"][0]["url"].split("?")[0] - except AttributeError: - continue + if repo.url.startswith("https://github.com"): + url = repo.url + r"/commits/" + repo.branch + ".atom" + response = await self.fetch_feed(url) + try: + commit = response.entries[0]["id"][33:] + hash = "[" + commit + "](" + response.entries[0]["link"] + ")" + cn = response.entries[0]["title"] + " - " + response.entries[0]["author"] + image = response.entries[0]["media_thumbnail"][0]["url"].split("?")[0] + except AttributeError: + continue + else: + url = repo.url + "rss/branch/" + repo.branch + response = await self.fetch_feed(url) + try: + commit = response.entries[0]["id"][33:] + hash = "[" + commit + "](" + response.entries[0]["link"] + ")" + cn = response.entries[0]["title"] + " - " + response.entries[0]["author"] + image = None + except AttributeError: + continue saving_dict[repo_name] = commit if whitelist: if repo_name not in whitelist: @@ -147,18 +158,17 @@ class UpdateChecker(commands.Cog): e.add_field(name="Branch", value=repo.branch) e.add_field(name="Commit", value=cn) e.add_field(name="Hash", value=hash) - e.set_thumbnail(url=image) + if image is not None: + e.set_thumbnail(url=image) else: - e = ( - "```css\n" + e = box( "[Update Checker]" - "``````css\n" f" Repo: {repo.name}\n" f" URL: {repo.url}\n" f" Commit: {cn}\n" f" Hash: {commit}\n" - f" Time: {datetime.utcnow()}" - "```" + f" Time: {datetime.utcnow()}", + 'css' ) try: if use_embed: