mirror of
https://github.com/Drop-OSS/flathub-app-bin.git
synced 2026-07-01 12:43:45 -04:00
domain_from_appid: Fix the script and post more detailed comment
This commit is contained in:
@@ -1,41 +1,56 @@
|
||||
# ONLY handle appids that need to use `org.flathub.VerifiedApps.txt`
|
||||
|
||||
import sys
|
||||
import re
|
||||
from publicsuffixlist import PublicSuffixList
|
||||
|
||||
CODE_HOSTS = (
|
||||
LOGINS = (
|
||||
"com.github.",
|
||||
"com.gitlab.",
|
||||
"io.github.",
|
||||
"io.frama.",
|
||||
"io.gitlab.",
|
||||
"page.codeberg.",
|
||||
"io.sourceforge.",
|
||||
"net.sourceforge.",
|
||||
"org.gnome.gitlab.",
|
||||
"org.freedesktop.gitlab.",
|
||||
"site.srht.",
|
||||
"org.gnome.World.",
|
||||
"org.gnome.design",
|
||||
"org.kde.",
|
||||
"org.gnome.",
|
||||
)
|
||||
|
||||
|
||||
def demangle(name: str) -> str:
|
||||
if name.startswith("_"):
|
||||
name = name[1:]
|
||||
return name.replace("_", "-")
|
||||
|
||||
def get_domain(appid: str) -> str | None:
|
||||
if appid.startswith(CODE_HOSTS) or appid.count(".") < 2:
|
||||
return None
|
||||
|
||||
if appid.startswith("org.gnome.") and not appid.startswith("org.gnome.gitlab."):
|
||||
return "gnome.org"
|
||||
elif appid.startswith("org.kde."):
|
||||
return "kde.org"
|
||||
elif appid.startswith("org.freedesktop.") and not appid.startswith("org.freedesktop.gitlab."):
|
||||
return "freedesktop.org"
|
||||
def get_domain(appid: str) -> str | None:
|
||||
if appid.startswith(LOGINS) or appid.count(".") < 2:
|
||||
return None
|
||||
elif appid.startswith(
|
||||
("io.frama.", "page.codeberg.", "io.sourceforge.", "net.sourceforge.")
|
||||
):
|
||||
tld, domain, name = appid.split(".")[0:3]
|
||||
name = demangle(name)
|
||||
if domain == "sourceforge":
|
||||
return f"{name}.{domain}.io".lower()
|
||||
else:
|
||||
return f"{name}.{domain}.{tld}".lower()
|
||||
elif appid.startswith(("io.sourceforge.", "net.sourceforge.")):
|
||||
[tld, domain, projectname] = appid.split(".")[0:3]
|
||||
projectname = demangle(projectname)
|
||||
return f"{projectname}.{domain}.io".lower()
|
||||
else:
|
||||
fqdn = ".".join(reversed(appid.split("."))).lower()
|
||||
psl = PublicSuffixList()
|
||||
if psl.is_private(fqdn):
|
||||
return demangle(psl.privatesuffix(fqdn))
|
||||
else:
|
||||
return ".".join(reversed([demangle(i) for i in appid.split(".")[:-1]])).lower()
|
||||
return ".".join(
|
||||
reversed([demangle(i) for i in appid.split(".")[:-1]])
|
||||
).lower()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
appid = sys.argv[1]
|
||||
print(get_domain(appid))
|
||||
# PR title as input "(Aa)dd com.foo.bar"
|
||||
appid = re.sub(r"^\s*add\s+", "", sys.argv[1], flags=re.IGNORECASE)
|
||||
print(get_domain(appid).strip())
|
||||
|
||||
@@ -114,11 +114,12 @@ jobs:
|
||||
echo "PR title validation failed"
|
||||
BLOCKED=1
|
||||
else
|
||||
APPID=$(echo "$PR_TITLE" | sed -E 's/^[[:space:]]*[Aa]dd[[:space:]]+//')
|
||||
DOMAIN=$(curl -sSL "$DOMAIN_SCRIPT_URL" | python3 - "$APPID")
|
||||
if [ "$DOMAIN" != "None" ] && [ -n "$DOMAIN" ]; then
|
||||
DOMAIN=$(curl -sSL "$DOMAIN_SCRIPT_URL" | python3 - "$PR_TITLE")
|
||||
if [ -n "$DOMAIN" ] && [ "$DOMAIN" != "None" ]; then
|
||||
echo "Domain is: $DOMAIN"
|
||||
DOMAIN_COMMENT="$DOMAIN_COMMENT_PARTIAL $DOMAIN. Please comment if incorrect."
|
||||
VERIF_URL="https://$DOMAIN/.well-known/org.flathub.VerifiedApps.txt"
|
||||
VERIF_COMMENT="If you intend to verify this app, please confirm that you can upload $VERIF_URL. Otherwise, ignore this."
|
||||
DOMAIN_COMMENT="$DOMAIN_COMMENT_PARTIAL $DOMAIN. $VERIF_COMMENT. Please comment if this incorrect."
|
||||
if ! comment_exists_full "$DOMAIN_COMMENT"; then
|
||||
echo "Did not find domain comment, commenting"
|
||||
gh pr comment "$PR_NUM" --body "$DOMAIN_COMMENT"
|
||||
|
||||
Reference in New Issue
Block a user