-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
321 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
**/.DS_Store | ||
.env | ||
.venv | ||
__pycache__ | ||
.ruff_cache | ||
*.pyc | ||
.pytest_cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
3.12 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |