Add remove publishers script

This commit is contained in:
Joakim Sørensen
2021-06-10 09:17:34 +00:00
parent 23bc922cc3
commit d081e51b1e
3 changed files with 69 additions and 2 deletions
+11 -2
View File
@@ -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"]}
+57
View File
@@ -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
View File
@@ -1,6 +1,7 @@
import sys
import json
# Information https://hacs.xyz/docs/publish/remove
if len(sys.argv) < 3:
print(