codersforge 0.0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- codersforge/__init__.py +4 -0
- codersforge/__main__.py +8 -0
- codersforge/_core/CORE_VERSION +33 -0
- codersforge/_core/__init__.py +8 -0
- codersforge/_core/archive.py +319 -0
- codersforge/_core/backup.py +417 -0
- codersforge/_core/config.py +206 -0
- codersforge/_core/domain.py +382 -0
- codersforge/_core/errors.py +36 -0
- codersforge/_core/events.py +381 -0
- codersforge/_core/findings.py +265 -0
- codersforge/_core/gates.py +395 -0
- codersforge/_core/identity.py +259 -0
- codersforge/_core/index.py +262 -0
- codersforge/_core/items.py +513 -0
- codersforge/_core/ledger.py +194 -0
- codersforge/_core/lessons.py +142 -0
- codersforge/_core/messages.py +293 -0
- codersforge/_core/migrate.py +221 -0
- codersforge/_core/output.py +41 -0
- codersforge/_core/paths.py +62 -0
- codersforge/_core/py.typed +0 -0
- codersforge/_core/schema.py +113 -0
- codersforge/_core/ulid.py +36 -0
- codersforge/_core/upgrade.py +57 -0
- codersforge/_core/versions.py +20 -0
- codersforge/_core/views.py +67 -0
- codersforge/_core/walls.py +231 -0
- codersforge/_core/workflow.py +745 -0
- codersforge/_docs.py +33 -0
- codersforge/checks.py +94 -0
- codersforge/cli.py +865 -0
- codersforge/domain.py +270 -0
- codersforge/py.typed +0 -0
- codersforge/workflows.yaml +129 -0
- codersforge-0.0.1.dist-info/METADATA +81 -0
- codersforge-0.0.1.dist-info/RECORD +41 -0
- codersforge-0.0.1.dist-info/WHEEL +4 -0
- codersforge-0.0.1.dist-info/entry_points.txt +2 -0
- codersforge-0.0.1.dist-info/licenses/LICENSE +202 -0
- codersforge-0.0.1.dist-info/licenses/NOTICE +7 -0
codersforge/_docs.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
"""Generated parts of the docs. ``scripts/gen_docs.py`` writes them; a test checks them."""
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
from codersforge._core.workflow import to_markdown
|
|
9
|
+
from codersforge.domain import DOMAIN, WORKFLOW_TITLES
|
|
10
|
+
|
|
11
|
+
BEGIN = "<!-- generated:workflows (scripts/gen_docs.py; edit src/codersforge/workflows.yaml) -->"
|
|
12
|
+
END = "<!-- /generated:workflows -->"
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def workflows_markdown() -> str:
|
|
16
|
+
"""CONTRACT §6's diagrams and condition tables, from ``workflows.yaml``."""
|
|
17
|
+
return to_markdown(DOMAIN.workflows, DOMAIN.all_checks, WORKFLOW_TITLES)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def render(contract: str) -> str:
|
|
21
|
+
"""``contract`` with its generated block replaced."""
|
|
22
|
+
start = contract.index(BEGIN) + len(BEGIN)
|
|
23
|
+
end = contract.index(END)
|
|
24
|
+
return contract[:start] + "\n\n" + workflows_markdown() + "\n" + contract[end:]
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def update(path: Path) -> bool:
|
|
28
|
+
"""Rewrite ``path`` if its generated block is stale. Returns whether it changed."""
|
|
29
|
+
old = path.read_text(encoding="utf-8")
|
|
30
|
+
new = render(old)
|
|
31
|
+
if new != old:
|
|
32
|
+
path.write_text(new, encoding="utf-8")
|
|
33
|
+
return new != old
|
codersforge/checks.py
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
"""Codersforge's workflow checks (CONTRACT §6).
|
|
3
|
+
|
|
4
|
+
Each is named in ``workflows.yaml``. The core supplies ``gate``,
|
|
5
|
+
``gate_revise``, ``gate_if_opened`` and ``field_in``. Conditions that a later
|
|
6
|
+
feature will record are ``pending_check``: they refuse, with reason
|
|
7
|
+
``condition_unavailable``, until then.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
from collections.abc import Mapping
|
|
13
|
+
from datetime import date
|
|
14
|
+
from typing import Any
|
|
15
|
+
|
|
16
|
+
from codersforge._core.workflow import (
|
|
17
|
+
Check,
|
|
18
|
+
CheckContext,
|
|
19
|
+
Outcome,
|
|
20
|
+
gate_history,
|
|
21
|
+
pending_check,
|
|
22
|
+
simple_check,
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def _for_item(ctx: CheckContext, event_type: str) -> list[Mapping[str, Any]]:
|
|
27
|
+
return [e for e in ctx.events if e["type"] == event_type and e.get("item") == ctx.item.id]
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def open_findings(ctx: CheckContext) -> list[str]:
|
|
31
|
+
"""IDs of the item's findings that have no ``finding_resolved``."""
|
|
32
|
+
resolved = {e["data"].get("finding_id") for e in _for_item(ctx, "finding_resolved")}
|
|
33
|
+
found = [e["data"].get("finding_id") for e in _for_item(ctx, "finding")]
|
|
34
|
+
return [f for f in dict.fromkeys(found) if f not in resolved]
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def _findings_open(ctx: CheckContext) -> Outcome:
|
|
38
|
+
if open_findings(ctx):
|
|
39
|
+
return Outcome(True)
|
|
40
|
+
return Outcome(False, "no findings are open")
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def _findings_closed(ctx: CheckContext) -> Outcome:
|
|
44
|
+
still = open_findings(ctx)
|
|
45
|
+
if not still:
|
|
46
|
+
return Outcome(True)
|
|
47
|
+
return Outcome(False, f"open: {', '.join(still)}")
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def _checks_pass(ctx: CheckContext) -> Outcome:
|
|
51
|
+
"""Every check in ``config.yaml`` has a latest ``check_run`` of ``pass`` for the item."""
|
|
52
|
+
required = list(ctx.config.get("checks") or {})
|
|
53
|
+
latest: dict[str, str] = {}
|
|
54
|
+
for event in _for_item(ctx, "check_run"):
|
|
55
|
+
latest[event["data"].get("check", "")] = event["data"].get("result", "")
|
|
56
|
+
failing = [name for name in required if latest.get(name) != "pass"]
|
|
57
|
+
if not failing:
|
|
58
|
+
return Outcome(True)
|
|
59
|
+
return Outcome(False, ", ".join(f"{n} {latest.get(n, 'not run')}" for n in failing))
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def _pr_merged(ctx: CheckContext) -> Outcome:
|
|
63
|
+
if any(e["data"].get("action") == "merged" for e in _for_item(ctx, "pr")):
|
|
64
|
+
return Outcome(True)
|
|
65
|
+
return Outcome(False, "no merged PR recorded")
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def _review_due(ctx: CheckContext) -> Outcome:
|
|
69
|
+
"""The latest RESPONSE ruling's ``review_by`` date is before today."""
|
|
70
|
+
history = gate_history(ctx.events, ctx.item.id, "RESPONSE")
|
|
71
|
+
ruled = [r for _, r, _ in history if r is not None]
|
|
72
|
+
if not ruled or "review_by" not in ruled[-1]:
|
|
73
|
+
return Outcome(False, "the latest RESPONSE ruling has no review date")
|
|
74
|
+
try:
|
|
75
|
+
until = date.fromisoformat(str(ruled[-1]["review_by"]))
|
|
76
|
+
except ValueError:
|
|
77
|
+
return Outcome(False, f"review date {ruled[-1]['review_by']!r} is not YYYY-MM-DD")
|
|
78
|
+
if until < ctx.today:
|
|
79
|
+
return Outcome(True)
|
|
80
|
+
return Outcome(False, f"under review until {until.isoformat()}")
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
CHECKS: Mapping[str, Check] = {
|
|
84
|
+
"findings_open": simple_check("findings open", _findings_open),
|
|
85
|
+
"findings_closed": simple_check("no open findings", _findings_closed),
|
|
86
|
+
"checks_pass": simple_check("required checks pass", _checks_pass),
|
|
87
|
+
"pr_merged": simple_check("PR merged", _pr_merged),
|
|
88
|
+
"review_due": simple_check("review date passed", _review_due),
|
|
89
|
+
"criteria_pass": pending_check("all acceptance criteria pass"),
|
|
90
|
+
"integration_failed": pending_check("integration fails"),
|
|
91
|
+
"fix_merged": pending_check("fix or removal merged"),
|
|
92
|
+
"recheck_failed": pending_check("Auditor re-check fails"),
|
|
93
|
+
"recheck_passed": pending_check("Auditor re-check passes"),
|
|
94
|
+
}
|