Skip to content

Commit

Permalink
commit
Browse files Browse the repository at this point in the history
  • Loading branch information
sckott committed Sep 16, 2024
1 parent 865e997 commit 8e98b48
Show file tree
Hide file tree
Showing 8 changed files with 321 additions and 0 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
on:
push:
branches: [main]
workflow_dispatch:

name: Check rules

jobs:
check-rules:
runs-on: ubuntu-latest
name: rules
strategy:
fail-fast: false

steps:
- uses: actions/checkout@v4

- name: Install uv
run: curl -LsSf https://astral.sh/uv/0.4.10/install.sh | sh

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version-file: .python-version

- name: Install
run: uv sync --all-extras --dev

- name: Check for main branch as default
run: uv run repository.py
env:
GITHUB_TOKEN: ${{ secrets.GH_PAT }}
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
**/.DS_Store
.env
.venv
__pycache__
.ruff_cache
*.pyc
.pytest_cache
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.12
12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.PHONY: test

lint-fix:
uv sync
ruff check --fix .

lint-check:
uv sync
ruff check .

test:
pytest
12 changes: 12 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[project]
name = "rules"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.12"
dependencies = [
"ghapi>=1.0.6",
"pygit2>=1.15.1",
"python-dateutil>=2.9.0.post0",
"rich>=13.8.1",
]
50 changes: 50 additions & 0 deletions registry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import urllib.request
import json
import dateutil.parser

REGISTRY_URL = "https://getwilds.org/registry/registry.json"


class WildsRegistry(object):
"""WildsRegistry
Examples:
reg = WildsRegistry()
reg
reg.repos
reg.updated
"""
def __init__(self):
self.load_data()
self.partition()

def __repr__(self):
return (
f"< {type(self).__name__} >\n"
f" updated: {self.updated}\n"
" Count of each badge\n"
f" concept: {len(self.concept)}\n"
f" experimental: {len(self.experimental)}\n"
f" prototype: {len(self.prototype)}\n"
f" stable: {len(self.stable)}\n"
f" deprecated: {len(self.deprecated)}\n"
)

def load_data(self):
with urllib.request.urlopen(REGISTRY_URL) as url:
data = json.load(url)
self.repos = data["repos"]
self.updated = dateutil.parser.parse(data["updated"]).strftime("%Y-%m-%d")

def partition(self):
self.all = [w for w in self.repos if w["badges"]]

for repo in self.all:
status_badge = [x for x in repo["badges"] if "Status" in x["alt"]]
repo['badge_status'] = status_badge[0]["href"].split("#")[-1]

self.concept = [w for w in self.all if w["badge_status"] == "concept"]
self.experimental = [w for w in self.all if w["badge_status"] == "experimental"]
self.prototype = [w for w in self.all if w["badge_status"] == "prototype"]
self.stable = [w for w in self.all if w["badge_status"] == "stable"]
self.deprecated = [w for w in self.all if w["badge_status"] == "deprecated"]
28 changes: 28 additions & 0 deletions repository.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# from pygit2 import Repository
from ghapi.all import GhApi
from registry import WildsRegistry
from rich import print

api = GhApi()
reg = WildsRegistry()
# repo = reg.all[0]
# repo_gh = api.repos.get("getwilds", repo["name"])
# repo_gh['default_branch']

def check_for_main(repo):
repo_gh = api.repos.get("getwilds", repo["name"])
default = repo_gh['default_branch']
if "mains" != default:
print(f'[bold red]{repo["name"]}[/bold red] needs a main branch as default; instead got {default}')
# raise Exception(f'[bold red]{repo["name"]}[/bold red] needs a main branch as default; instead got {default}')
else:
print(f"[bold green]{repo["name"]}[/bold green] all good")
# repo = Repository(".")
# if "mains" not in list(repo.branches.local):
# raise Exception(f'main branch not found for {repo}')

if __name__ == "__main__":
[check_for_main(repo) for repo in reg.all]

# repo = Repository(".")
# check_for_main(repo)
179 changes: 179 additions & 0 deletions uv.lock

Large diffs are not rendered by default.

0 comments on commit 8e98b48

Please sign in to comment.