diff --git a/.github/workflows/check-fork.yml b/.github/workflows/check-fork.yml new file mode 100644 index 0000000..788269a --- /dev/null +++ b/.github/workflows/check-fork.yml @@ -0,0 +1,30 @@ +name: "Check Fork" +on: + pull_request: + types: unlabeled + +jobs: + check: + if: github.event.label.name == 'Not finished' + runs-on: ubuntu-latest + steps: + - name: Check out repository + uses: actions/checkout@v2 + + - name: Clone origin + run: git clone --depth 1 https://github.com/hacs/default /tmp/default + + - name: Clone new addition + run: | + repo=$(python3 -m scripts.changed.repo) + git clone --depth 1 "https://github.com/$repo" /tmp/addition + + - name: Install dependencies + run: | + python3 -m pip install setuptools wheel + python3 -m pip install aiogithubapi + + - name: Check fork + run: python3 -m scripts.check.fork + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/check-owner.yml b/.github/workflows/check-owner.yml new file mode 100644 index 0000000..8b6b2e3 --- /dev/null +++ b/.github/workflows/check-owner.yml @@ -0,0 +1,30 @@ +name: "Check Owner" +on: + pull_request: + types: unlabeled + +jobs: + check: + if: github.event.label.name == 'Not finished' + runs-on: ubuntu-latest + steps: + - name: Check out repository + uses: actions/checkout@v2 + + - name: Clone origin + run: git clone --depth 1 https://github.com/hacs/default /tmp/default + + - name: Clone new addition + run: | + repo=$(python3 -m scripts.changed.repo) + git clone --depth 1 "https://github.com/$repo" /tmp/addition + + - name: Install dependencies + run: | + python3 -m pip install setuptools wheel + python3 -m pip install aiogithubapi + + - name: Check owner + run: python3 -m scripts.check.owner + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/scripts/check/fork.py b/scripts/check/fork.py new file mode 100644 index 0000000..cd5c4ec --- /dev/null +++ b/scripts/check/fork.py @@ -0,0 +1,23 @@ +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") + + +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) + +if __name__ == "__main__": + asyncio.get_event_loop().run_until_complete(check()) diff --git a/scripts/check/owner.py b/scripts/check/owner.py new file mode 100644 index 0000000..4388df2 --- /dev/null +++ b/scripts/check/owner.py @@ -0,0 +1,27 @@ +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", "ludeeus") + + +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 + + if ACTOR == repo["full_name"].split("/")[0]: + print(f"{ACTOR} is the owner of the repository") + return + + exit(1) + +if __name__ == "__main__": + asyncio.get_event_loop().run_until_complete(check())