mirror of
https://github.com/alexhopeoconnor/default.git
synced 2026-10-04 02:58:10 +10:00
Add remove publishers script
This commit is contained in:
+11
-2
@@ -3,6 +3,7 @@ import os
|
||||
|
||||
from scripts.changed.repo import get_repo
|
||||
from scripts.helpers.event import get_event
|
||||
from scripts.remove_publishers import REMOVED_PUBLISHERS
|
||||
from aiogithubapi import GitHub, AIOGitHubAPIException
|
||||
|
||||
TOKEN = os.getenv("GITHUB_TOKEN")
|
||||
@@ -13,15 +14,23 @@ async def check():
|
||||
repo = get_repo()
|
||||
event = get_event()
|
||||
actor = event["pull_request"]["user"]["login"]
|
||||
repo_owner = repo.split("/")[0].lower()
|
||||
|
||||
if repo.split("/")[0].lower() == actor.lower():
|
||||
for removed in REMOVED_PUBLISHERS:
|
||||
if repo_owner == removed["publisher"].lower():
|
||||
exit(
|
||||
f"::error::'{repo_owner}' is not allowed to publish default repositories"
|
||||
)
|
||||
|
||||
if repo_owner == actor.lower():
|
||||
print(f"'{actor}' is the owner of '{repo}'")
|
||||
return
|
||||
|
||||
try:
|
||||
async with GitHub(TOKEN) as github:
|
||||
request = await github.client.get(
|
||||
f"/repos/{repo}/contributors", headers={},
|
||||
f"/repos/{repo}/contributors",
|
||||
headers={},
|
||||
)
|
||||
contributors = [
|
||||
{"login": x["login"], "contributions": x["contributions"]}
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
import json
|
||||
|
||||
# Information https://hacs.xyz/docs/publish/remove
|
||||
REMOVED_PUBLISHERS = []
|
||||
|
||||
CATEGORIES = [
|
||||
"appdaemon",
|
||||
"integration",
|
||||
"netdaemon",
|
||||
"plugin",
|
||||
"python_script",
|
||||
"theme",
|
||||
]
|
||||
|
||||
TO_REMOVE = {category: [] for category in CATEGORIES}
|
||||
for entry in REMOVED_PUBLISHERS:
|
||||
for category in CATEGORIES:
|
||||
with open(category, "r") as cat_file:
|
||||
content = json.loads(cat_file.read())
|
||||
for key in content.copy():
|
||||
if entry["publisher"] in key.lower():
|
||||
print(f"Found {key} in {category}")
|
||||
TO_REMOVE[category].append(
|
||||
{"repository": key, "link": entry["link"]}
|
||||
)
|
||||
|
||||
with open("blacklist", "r") as blacklist_file:
|
||||
blacklistcontent = json.loads(blacklist_file.read())
|
||||
|
||||
with open("removed", "r") as removed_file:
|
||||
removedcontent = json.loads(removed_file.read())
|
||||
|
||||
for category in TO_REMOVE:
|
||||
if len(TO_REMOVE[category]) != 0:
|
||||
with open(category, "r") as cat_file:
|
||||
categorycontent = json.loads(cat_file.read())
|
||||
|
||||
for entry in TO_REMOVE[category]:
|
||||
blacklistcontent.append(entry["repository"])
|
||||
removedcontent.append(
|
||||
{**entry, "reason": "Author removed", "removal_type": "removal"}
|
||||
)
|
||||
categorycontent.remove(entry["repository"])
|
||||
|
||||
with open(category, "w") as cat_file:
|
||||
cat_file.write(
|
||||
json.dumps(sorted(categorycontent, key=str.casefold), indent=2)
|
||||
)
|
||||
|
||||
|
||||
with open("blacklist", "w") as blacklist_file:
|
||||
blacklist_file.write(
|
||||
json.dumps(sorted(blacklistcontent, key=str.casefold), indent=2)
|
||||
)
|
||||
|
||||
with open("removed", "w") as removed_file:
|
||||
removed_file.write(json.dumps(removedcontent, indent=2))
|
||||
@@ -1,6 +1,7 @@
|
||||
import sys
|
||||
import json
|
||||
|
||||
# Information https://hacs.xyz/docs/publish/remove
|
||||
|
||||
if len(sys.argv) < 3:
|
||||
print(
|
||||
|
||||
Reference in New Issue
Block a user