mirror of
https://github.com/alexhopeoconnor/default.git
synced 2026-10-04 02:58:10 +10:00
Add preflight (#490)
* Add preflight * fix syntax * move check * get event * print * return event * use path * tt * move to helper * add issue_comment * remove should run * check owner * add more information to the logs * test * add finished * move keys * Update errors * remove repo * fix JQ run * filter
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import json
|
||||
|
||||
|
||||
DEFAULT = "/tmp/default"
|
||||
DEFAULT = "/tmp/repositories/default"
|
||||
|
||||
CATEGORIES = [
|
||||
"appdaemon",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import json
|
||||
from scripts.changed.category import get_category
|
||||
|
||||
DEFAULT = "/tmp/default"
|
||||
DEFAULT = "/tmp/repositories/default"
|
||||
|
||||
|
||||
def get_repo():
|
||||
|
||||
@@ -17,7 +17,7 @@ async def check():
|
||||
repo = repository.attributes
|
||||
|
||||
if repo["archived"]:
|
||||
exit("Repository is archived")
|
||||
exit("::error::Repository is archived")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -29,7 +29,7 @@ async def check():
|
||||
files = await repository.get_contents("custom_integrations")
|
||||
if domain not in [x.attributes["name"] for x in files]:
|
||||
exit(
|
||||
f"{domain} is not added to https://github.com/home-assistant/brands, "
|
||||
f"::error::{domain} is not added to https://github.com/home-assistant/brands, "
|
||||
+ "this is needed to ensure the best possible experience for the user"
|
||||
)
|
||||
else:
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
from scripts.helpers.event import get_event
|
||||
|
||||
|
||||
def check():
|
||||
event = get_event()
|
||||
labels = event.get("pull_request", {}).get("labels", [])
|
||||
|
||||
for label in labels:
|
||||
if label["name"] == "Not finished":
|
||||
exit("::error::Pull request is not ready for CI runs")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
check()
|
||||
@@ -17,7 +17,7 @@ async def check():
|
||||
repo = repository.attributes
|
||||
|
||||
if repo["fork"]:
|
||||
exit(78)
|
||||
print("::warning:: {repo} is a fork")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -9,10 +9,12 @@ def check():
|
||||
return
|
||||
|
||||
manifest = get_hacs_manifest()
|
||||
fail = "::error::Missing required value for key '{key}' in {path}"
|
||||
path = "hacs.json"
|
||||
issues = []
|
||||
|
||||
if manifest.get("name") is None:
|
||||
issues.append("No name")
|
||||
issues.append(fail.format(key="name", path=path))
|
||||
|
||||
if issues:
|
||||
for issue in issues:
|
||||
|
||||
@@ -13,8 +13,7 @@ def check():
|
||||
print("Has image(s)")
|
||||
return
|
||||
|
||||
print("There should be images to show the user what they get.")
|
||||
exit(1)
|
||||
exit("::error::There should be images to show the user what they get.")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -6,9 +6,7 @@ def check():
|
||||
print("Information: https://hacs.xyz/docs/publish/include#check-info")
|
||||
info = get_info()
|
||||
if not info:
|
||||
print("No information provided.")
|
||||
exit(1)
|
||||
|
||||
exit("::error::No information provided.")
|
||||
|
||||
if __name__ == "__main__":
|
||||
check()
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from scripts.changed.category import get_category
|
||||
from scripts.helpers.manifest import get_manifest
|
||||
from scripts.helpers.integration_path import get_integration_path
|
||||
|
||||
|
||||
def check():
|
||||
@@ -8,23 +9,24 @@ def check():
|
||||
print("Only integrations are checked.")
|
||||
return
|
||||
|
||||
fail = "::error::Missing required value for key '{key}' in {path}"
|
||||
integration = get_integration_path()
|
||||
path = f"{integration.replace('/tmp/repositories/addition/', '')}/manifest.json"
|
||||
|
||||
manifest = get_manifest()
|
||||
issues = []
|
||||
|
||||
if manifest.get("domain") is None or manifest.get("domain") == "":
|
||||
issues.append("No domain")
|
||||
issues.append(fail.format(key="domain", path=path))
|
||||
|
||||
if manifest.get("documentation") is None or manifest.get("documentation") == "":
|
||||
issues.append("No documentation")
|
||||
issues.append(fail.format(key="documentation", path=path))
|
||||
|
||||
if manifest.get("issue_tracker") is None or manifest.get("issue_tracker") == "":
|
||||
issues.append("No issue_tracker")
|
||||
issues.append(fail.format(key="issue_tracker", path=path))
|
||||
|
||||
if manifest.get("codeowners") is None:
|
||||
issues.append("No codeowners")
|
||||
|
||||
if manifest.get("homeassistant"):
|
||||
issues.append("homeassistant is not valid here")
|
||||
issues.append(fail.format(key="codeowners", path=path))
|
||||
|
||||
if issues:
|
||||
for issue in issues:
|
||||
|
||||
+6
-15
@@ -1,30 +1,21 @@
|
||||
import asyncio
|
||||
import json
|
||||
import os
|
||||
from glob import glob
|
||||
|
||||
from aiogithubapi import GitHub
|
||||
from scripts.changed.repo import get_repo
|
||||
|
||||
TOKEN = os.getenv("GITHUB_TOKEN")
|
||||
ACTOR = os.getenv("GITHUB_ACTOR")
|
||||
from scripts.helpers.event import get_event
|
||||
|
||||
|
||||
async def check():
|
||||
print("Information: https://hacs.xyz/docs/publish/include#check-owner")
|
||||
repo = get_repo()
|
||||
async with GitHub(TOKEN) as github:
|
||||
repository = await github.get_repo(repo)
|
||||
repo = repository.attributes
|
||||
event = get_event()
|
||||
actor = event["pull_request"]["user"]["login"]
|
||||
|
||||
return
|
||||
# Currently broken. can not use ACTOR
|
||||
|
||||
if ACTOR == repo["full_name"].split("/")[0]:
|
||||
print(f"{ACTOR} is the owner of the repository")
|
||||
if repo.split("/")[0] == event["pull_request"]["user"]["login"]:
|
||||
print(f"{actor} is the owner of the repository")
|
||||
return
|
||||
|
||||
exit(78)
|
||||
print(f"::warning::{actor} is the owner of the repository")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -18,15 +18,15 @@ async def check():
|
||||
repo = repository.attributes
|
||||
|
||||
if not repo["has_issues"]:
|
||||
issues.append("Issues not enabled.")
|
||||
issues.append("::error::Issues not enabled.")
|
||||
|
||||
if not repo["description"]:
|
||||
issues.append(
|
||||
"No description. (https://hacs.xyz/docs/publish/start#description)"
|
||||
"::error::No description. (https://hacs.xyz/docs/publish/start#description)"
|
||||
)
|
||||
|
||||
if not repo["topics"]:
|
||||
issues.append("No topics. (https://hacs.xyz/docs/publish/start#topics)")
|
||||
issues.append("::error::No topics. (https://hacs.xyz/docs/publish/start#topics)")
|
||||
|
||||
if issues:
|
||||
for issue in issues:
|
||||
|
||||
@@ -38,7 +38,7 @@ async def check():
|
||||
)
|
||||
return
|
||||
exit(
|
||||
f"{domain} is not added to https://github.com/home-assistant/wheels-custom-integrations, "
|
||||
f"::error::{domain} is not added to https://github.com/home-assistant/wheels-custom-integrations, "
|
||||
+ "this is needed to ensure the best possible experience for the user"
|
||||
)
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
import os
|
||||
import json
|
||||
|
||||
|
||||
def get_event():
|
||||
with open(os.getenv("GITHUB_EVENT_PATH"), "r") as event_data:
|
||||
event = json.loads(event_data.read())
|
||||
|
||||
return event
|
||||
@@ -5,7 +5,7 @@ from glob import glob
|
||||
|
||||
def get_hacs_manifest():
|
||||
files = []
|
||||
for dir, _, _ in os.walk("/tmp/addition"):
|
||||
for dir, _, _ in os.walk("/tmp/repositories/addition"):
|
||||
files.extend(glob(os.path.join(dir, "*hacs.json")))
|
||||
|
||||
if len(files) != 1:
|
||||
@@ -13,7 +13,9 @@ def get_hacs_manifest():
|
||||
exit(1)
|
||||
|
||||
hacs_manifest = files.pop()
|
||||
print(f"Found HACS manifest at {hacs_manifest.replace('/tmp/addition','')}")
|
||||
print(
|
||||
f"Found HACS manifest at {hacs_manifest.replace('/tmp/repositories/addition','')}"
|
||||
)
|
||||
|
||||
with open(hacs_manifest, "r") as mf:
|
||||
hacs_manifest = json.loads(mf.read())
|
||||
|
||||
@@ -14,8 +14,8 @@ def get_info():
|
||||
content = ""
|
||||
|
||||
for alternative in ALTERNATIVES[info]:
|
||||
if os.path.exists(f"/tmp/addition/{alternative}"):
|
||||
if os.path.exists(f"/tmp/repositories/addition/{alternative}"):
|
||||
print(f"Found info file at /{alternative}")
|
||||
with open(f"/tmp/addition/{alternative}", "r") as alt:
|
||||
with open(f"/tmp/repositories/addition/{alternative}", "r") as alt:
|
||||
content = alt.read()
|
||||
return content
|
||||
|
||||
@@ -5,7 +5,7 @@ from glob import glob
|
||||
|
||||
def get_integration_path():
|
||||
files = []
|
||||
for dir, _, _ in os.walk("/tmp/addition"):
|
||||
for dir, _, _ in os.walk("/tmp/repositories/addition"):
|
||||
files.extend(glob(os.path.join(dir, "*manifest.json")))
|
||||
|
||||
if len(files) != 1:
|
||||
|
||||
Reference in New Issue
Block a user