feat(updatechecker): added gitea/forgejo support

This commit is contained in:
SeaswimmerTheFsh 2024-01-07 13:30:02 +00:00
parent c2b2dcb8a0
commit b4647a3c6b
Signed by untrusted user: cswimr
GPG key ID: D74DDDDF420E13DF

View file

@ -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: