Example #1
0
async def check():
    print(
        "Information: https://hacs.xyz/docs/publish/include#check-repository")
    repo = get_repo()
    issues = []
    async with GitHub(TOKEN) as github:
        repository = await github.get_repo(repo)
        repo = repository.attributes

    if not repo["has_issues"]:
        issues.append("::error::Issues not enabled.")

    if not repo["description"]:
        issues.append(
            "::error::No description. (https://hacs.xyz/docs/publish/start#description)"
        )

    if not repo["topics"]:
        issues.append(
            "::error::No topics. (https://hacs.xyz/docs/publish/start#topics)")

    if issues:
        for issue in issues:
            print(issue)
        exit(1)
Example #2
0
async def check():
    print("Information: https://hacs.xyz/docs/publish/include#check-fork")
    repo = get_repo()
    async with GitHub(TOKEN) as github:
        repository = await github.get_repo(repo)
        repo = repository.attributes

    if repo["fork"]:
        exit(1)
Example #3
0
async def check():
    print("Information: https://hacs.xyz/docs/publish/include#check-owner")
    repo = get_repo()
    event = get_event()
    actor = event["pull_request"]["user"]["login"]

    if repo.split("/")[0] == event["pull_request"]["user"]["login"]:
        print(f"{actor} is the owner of the repository")
        return

    print(f"::warning::{actor} is the owner of the repository")
Example #4
0
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

    return
    # Currently broken. can not use ACTOR

    if ACTOR == repo["full_name"].split("/")[0]:
        print(f"{ACTOR} is the owner of the repository")
        return

    exit(1)
Example #5
0
async def check():
    print("Information: https://hacs.xyz/docs/publish/include#check-owner")
    repo = get_repo()
    event = get_event()
    actor = event["pull_request"]["user"]["login"]
    repo_owner = repo.split("/")[0].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={},
            )
            contributors = [
                {"login": x["login"], "contributions": x["contributions"]}
                for x in request or []
            ]
            _sorted = sorted(
                contributors, key=lambda x: x["contributions"], reverse=True
            )

            _top = _sorted[0]["contributions"]

            if actor not in [x["login"] for x in _sorted]:
                exit(f"::error::'{actor}' is not a contributor to '{repo}'")

            if [x["contributions"] for x in _sorted if x["login"] == actor].pop() > (
                _top / 3
            ):
                print(f"'{actor}' is a major contributor to '{repo}'")
                return
    except AIOGitHubAPIException as e:
        exit(f"::error::{e}")

    exit(f"::error::'{actor}' is not a major contributor to '{repo}'")