From 8721945b49a2e999a77d763022db8946f0d160dc Mon Sep 17 00:00:00 2001 From: ahauy Date: Thu, 5 Nov 2026 11:34:50 +0700 Subject: [PATCH 1/3] chore(repo): add GitHub rulesets and run macOS tests on every PR --- .github/rulesets/README.md | 48 ++++++++++++++++++++++ .github/rulesets/feature-branches.json | 21 ++++++++++ .github/rulesets/main.json | 57 ++++++++++++++++++++++++++ .github/workflows/macos-tests.yml | 12 ------ 4 files changed, 126 insertions(+), 12 deletions(-) create mode 100644 .github/rulesets/README.md create mode 100644 .github/rulesets/feature-branches.json create mode 100644 .github/rulesets/main.json diff --git a/.github/rulesets/README.md b/.github/rulesets/README.md new file mode 100644 index 0000000..1b19ab8 --- /dev/null +++ b/.github/rulesets/README.md @@ -0,0 +1,48 @@ +# Repository rulesets + +Ruleset definitions for `ahauy/FlowSnap`, enforced by GitHub on **push and PR merge**, not by +any tool in the repo. + +GitHub does not read this folder by itself. Each file is the exact request body for the +[create-ruleset API](https://docs.github.com/en/rest/repos/rules). + +## Apply + +```sh +# See the effect for a week without blocking anything: set "enforcement": "evaluate" first. +gh api -X POST repos/ahauy/FlowSnap/rulesets --input .github/rulesets/main.json +gh api -X POST repos/ahauy/FlowSnap/rulesets --input .github/rulesets/feature-branches.json + +# Confirm +gh api repos/ahauy/FlowSnap/rulesets --jq '.[] | {id, name, enforcement, .conditions?}' + +# Update an existing ruleset instead of creating a duplicate +gh api -X PATCH repos/ahauy/FlowSnap/rulesets/ --input .github/rulesets/main.json + +# Remove +gh api -X DELETE repos/ahauy/FlowSnap/rulesets/ +``` + +## Files + +| File | Enforces | +| --- | --- | +| `main.json` | A PR is required to land on `main`; `Swift unit tests (macOS)` and `GitGuardian Security Checks` must be green and current (`strict_required_status_checks_policy: true`); no force push (`non_fast_forward`); `main` cannot be deleted; review threads must be resolved; squash or merge only. | +| `feature-branches.json` | Every commit message on any non-`main` branch matches `type(scope): single-line summary` (AGENTS.md "Single-Line English Commits"). | + +## Decisions worth knowing + +- `required_approving_review_count: 0`. The repo has one owner, and GitHub does not count the + author's own review. Any number above 0 makes every PR unmergeable. +- `integration_id` values are read from real check runs, not guessed: GitHub Actions is `15368` + (context `Swift unit tests (macOS)`), GitGuardian is `46505`. +- `bypass_actors` grants the Admin repository role (`actor_id: 5`) bypass, so you can still + hot-fix `main` from the web UI. Delete that block for zero exceptions. +- `update` and `creation` are deliberately absent on `main`: they block direct pushes and can + also reject the merge commit a PR produces. +- The commit-message rule applies to feature branches only. Merge commits landing on `main` + (`Merge pull request #45 …`) would not match it. +- `dependabot/*` is excluded from the message rule because Dependabot writes its own subjects. + +Verified against history: the 12 most recent commit subjects on `feat/web-i18n-ux-refactor` all +match; multiline bodies, missing types, uppercase types and missing `: ` are rejected. diff --git a/.github/rulesets/feature-branches.json b/.github/rulesets/feature-branches.json new file mode 100644 index 0000000..b5f1e1c --- /dev/null +++ b/.github/rulesets/feature-branches.json @@ -0,0 +1,21 @@ +{ + "name": "Feature branches — single-line Conventional Commits", + "target": "branch", + "source_type": "Repository", + "enforcement": "active", + "conditions": { + "ref_name": { + "exclude": ["refs/heads/main", "refs/heads/master", "refs/heads/dependabot/*"], + "include": ["refs/heads/*"] + } + }, + "rules": [ + { + "type": "commit_message_pattern", + "parameters": { + "operator": "matches", + "pattern": "\\A(feat|fix|docs|test|chore|refactor|perf|ci|build|revert)(\\([a-z0-9._-]+\\))?: [^\\n]+\\z" + } + } + ] +} diff --git a/.github/rulesets/main.json b/.github/rulesets/main.json new file mode 100644 index 0000000..e7a13ea --- /dev/null +++ b/.github/rulesets/main.json @@ -0,0 +1,57 @@ +{ + "name": "Protect main — PR, required checks, no force push", + "target": "branch", + "source_type": "Repository", + "enforcement": "active", + "conditions": { + "ref_name": { + "exclude": [], + "include": ["refs/heads/main", "refs/heads/master"] + } + }, + "rules": [ + { + "type": "deletion", + "parameters": {} + }, + { + "type": "non_fast_forward", + "parameters": {} + }, + { + "type": "required_status_checks", + "parameters": { + "do_not_enforce_on_create": false, + "strict_required_status_checks_policy": true, + "required_status_checks": [ + { + "context": "Swift unit tests (macOS)", + "integration_id": 15368 + }, + { + "context": "GitGuardian Security Checks", + "integration_id": 46505 + } + ] + } + }, + { + "type": "pull_request", + "parameters": { + "required_approving_review_count": 0, + "require_code_owner_review": false, + "require_last_push_approval": false, + "dismiss_stale_reviews_on_push": true, + "required_review_thread_resolution": true, + "allowed_merge_methods": ["squash", "merge"] + } + } + ], + "bypass_actors": [ + { + "actor_type": "RepositoryRole", + "actor_id": 5, + "bypass_mode": "always" + } + ] +} diff --git a/.github/workflows/macos-tests.yml b/.github/workflows/macos-tests.yml index c3e82a3..b8ed61c 100644 --- a/.github/workflows/macos-tests.yml +++ b/.github/workflows/macos-tests.yml @@ -4,19 +4,7 @@ on: push: branches: - main - paths: - - "FlowSnap/**" - - "FlowSnapTests/**" - - "FlowSnap.xcodeproj/**" - - "project.yml" - - ".github/workflows/macos-tests.yml" pull_request: - paths: - - "FlowSnap/**" - - "FlowSnapTests/**" - - "FlowSnap.xcodeproj/**" - - "project.yml" - - ".github/workflows/macos-tests.yml" workflow_dispatch: concurrency: From 049fa124c301225959b3ee7e9deab530375e5534 Mon Sep 17 00:00:00 2001 From: ahauy Date: Thu, 5 Nov 2026 11:38:32 +0700 Subject: [PATCH 2/3] docs(repo): record that pattern rulesets are unavailable on this plan --- .github/rulesets/README.md | 51 ++++++++++++++++++++++---- .github/rulesets/feature-branches.json | 21 ----------- 2 files changed, 44 insertions(+), 28 deletions(-) delete mode 100644 .github/rulesets/feature-branches.json diff --git a/.github/rulesets/README.md b/.github/rulesets/README.md index 1b19ab8..179cd33 100644 --- a/.github/rulesets/README.md +++ b/.github/rulesets/README.md @@ -11,7 +11,6 @@ GitHub does not read this folder by itself. Each file is the exact request body ```sh # See the effect for a week without blocking anything: set "enforcement": "evaluate" first. gh api -X POST repos/ahauy/FlowSnap/rulesets --input .github/rulesets/main.json -gh api -X POST repos/ahauy/FlowSnap/rulesets --input .github/rulesets/feature-branches.json # Confirm gh api repos/ahauy/FlowSnap/rulesets --jq '.[] | {id, name, enforcement, .conditions?}' @@ -28,7 +27,37 @@ gh api -X DELETE repos/ahauy/FlowSnap/rulesets/ | File | Enforces | | --- | --- | | `main.json` | A PR is required to land on `main`; `Swift unit tests (macOS)` and `GitGuardian Security Checks` must be green and current (`strict_required_status_checks_policy: true`); no force push (`non_fast_forward`); `main` cannot be deleted; review threads must be resolved; squash or merge only. | -| `feature-branches.json` | Every commit message on any non-`main` branch matches `type(scope): single-line summary` (AGENTS.md "Single-Line English Commits"). | + +## Applied state (verified by reading the API back) + +`main.json` is live as ruleset **id `26587443`**, `enforcement: active`, conditions +`refs/heads/main` + `refs/heads/master`, and `bypass_actors` = RepositoryRole `5` (Admin) with +`bypass_mode: always`. GitHub also defaulted `require_extra_approval_for_unattributed_changes: true`. + +Because that ruleset requires `Swift unit tests (macOS)` on every PR, the workflow's `paths:` +filters were removed so the check always runs — a docs-only PR would otherwise hang on +"Expected — waiting" forever. + +## Pattern rules are not available on this plan + +Probing the same endpoint on 2026-11-05: + +| Rule tried | Result | +| --- | --- | +| `commit_message_pattern` (`operator: regex`, `matches`, with and without `positive_match`) | `422 Invalid rule 'commit_message_pattern'` | +| `branch_name_pattern` | `422 Invalid rule 'branch_name_pattern'` | +| `max_file_size` | `422 Invalid property /rules/0` (parameter shape also differs from the docs) | +| `required_signatures` | accepted | + +So the single-line Conventional Commit rule from AGENTS.md **cannot** be enforced by a ruleset on +this account. It is enforced two other ways instead: + +- `.qoder/hooks/flowgate.sh` + `.qoder/hooks/policy.json` block an agent's `git commit` unless the + user approved it — the message shape is the agent's responsibility there. +- A CI job can reject non-conforming subjects on a PR if you want it enforced for humans too; + that is the remaining gap. + +Do not re-add `feature-branches.json` until the plan supports pattern rules; it will fail to apply. ## Decisions worth knowing @@ -40,9 +69,17 @@ gh api -X DELETE repos/ahauy/FlowSnap/rulesets/ hot-fix `main` from the web UI. Delete that block for zero exceptions. - `update` and `creation` are deliberately absent on `main`: they block direct pushes and can also reject the merge commit a PR produces. -- The commit-message rule applies to feature branches only. Merge commits landing on `main` - (`Merge pull request #45 …`) would not match it. -- `dependabot/*` is excluded from the message rule because Dependabot writes its own subjects. -Verified against history: the 12 most recent commit subjects on `feat/web-i18n-ux-refactor` all -match; multiline bodies, missing types, uppercase types and missing `: ` are rejected. +## The commit-message regex, kept for a future CI check + +`git log --format=%s` style subjects only, because a ruleset cannot enforce it here: + +``` +\A(feat|fix|docs|test|chore|refactor|perf|ci|build|revert)(\([a-z0-9._-]+\))?: [^\n]+\z +``` + +Measured with Ruby `Regexp` (same engine GitHub uses for these patterns): the 12 most recent +subjects on `feat/web-i18n-ux-refactor` match, while `multiline body`, `no type prefix`, +`uppercase type`, `no colon space` and `empty desc` are all rejected. A PR-time job should match +this against each commit subject in the range, and skip merge commits. + diff --git a/.github/rulesets/feature-branches.json b/.github/rulesets/feature-branches.json deleted file mode 100644 index b5f1e1c..0000000 --- a/.github/rulesets/feature-branches.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "name": "Feature branches — single-line Conventional Commits", - "target": "branch", - "source_type": "Repository", - "enforcement": "active", - "conditions": { - "ref_name": { - "exclude": ["refs/heads/main", "refs/heads/master", "refs/heads/dependabot/*"], - "include": ["refs/heads/*"] - } - }, - "rules": [ - { - "type": "commit_message_pattern", - "parameters": { - "operator": "matches", - "pattern": "\\A(feat|fix|docs|test|chore|refactor|perf|ci|build|revert)(\\([a-z0-9._-]+\\))?: [^\\n]+\\z" - } - } - ] -} From 1f80395c77022ef918c283a64adae194759dc373 Mon Sep 17 00:00:00 2001 From: ahauy Date: Thu, 5 Nov 2026 11:44:26 +0700 Subject: [PATCH 3/3] ci(repo): enforce single-line Conventional Commits on pull requests --- .github/workflows/commit-lint.yml | 32 +++++++++++++++ scripts/check-commit-messages.py | 66 +++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 .github/workflows/commit-lint.yml create mode 100644 scripts/check-commit-messages.py diff --git a/.github/workflows/commit-lint.yml b/.github/workflows/commit-lint.yml new file mode 100644 index 0000000..a22b315 --- /dev/null +++ b/.github/workflows/commit-lint.yml @@ -0,0 +1,32 @@ +name: Conventional Commits + +on: + pull_request: + workflow_dispatch: + +concurrency: + group: commit-lint-${{ github.ref }} + cancel-in-progress: true + +jobs: + subjects: + name: Conventional commit subjects + runs-on: ubuntu-latest + steps: + - name: Checkout full history + uses: actions/checkout@v4 + with: + fetch-depth: 0 + persist-credentials: false + + - name: Check every commit subject and body + env: + BASE_SHA: ${{ github.event.pull_request.base.sha }} + HEAD_SHA: ${{ github.event.pull_request.head.sha }} + run: | + if [ -z "${BASE_SHA:-}" ] || [ -z "${HEAD_SHA:-}" ]; then + HEAD_SHA=$(git rev-parse HEAD) + BASE_SHA=$(git rev-parse HEAD~1) + fi + export BASE_SHA HEAD_SHA + python3 scripts/check-commit-messages.py diff --git a/scripts/check-commit-messages.py b/scripts/check-commit-messages.py new file mode 100644 index 0000000..d96949e --- /dev/null +++ b/scripts/check-commit-messages.py @@ -0,0 +1,66 @@ +#!/usr/bin/env python3 +"""Fail if any commit in a range breaks AGENTS.md's single-line Conventional Commit rule.""" + +import os +import re +import subprocess +import sys + +SUBJECT = re.compile( + r"(feat|fix|docs|test|chore|refactor|perf|ci|build|revert)" + r"(\([a-z0-9._-]+\))?(!)?: [^\s].*" +) +SKIP_AUTHORS = {"dependabot[bot]", "renovate[bot]", "github-actions[bot]"} +MERGE_PREFIXES = ("Merge ", "Revert \"", "revert \"") + + +def git(*args: str) -> str: + result = subprocess.run(["git", *args], capture_output=True, text=True) + if result.returncode: + # 2 = the check itself could not run (bad revision, shallow clone), + # which is different from 1 = a real commit-message violation. + print(f"git {' '.join(args)} failed: {result.stderr.strip()}", file=sys.stderr) + raise SystemExit(2) + return result.stdout + + +def commits(base: str, head: str) -> list[tuple[str, str]]: + out = git("log", "--no-merges", "--format=%H\x1f%an", f"{base}..{head}") + return [tuple(line.split("\x1f")) for line in out.splitlines() if line.strip()] + + +def body_lines(sha: str) -> int: + return len([line for line in git("show", "-s", "--format=%b", sha).splitlines() if line.strip()]) + + +def main() -> int: + base = os.environ.get("BASE_SHA") or sys.argv[1] + head = os.environ.get("HEAD_SHA") or sys.argv[2] + problems = [] + + for sha, author in commits(base, head): + subject = git("show", "-s", "--format=%s", sha).strip() + if author in SKIP_AUTHORS or subject.startswith(MERGE_PREFIXES): + continue + short = sha[:8] + if not SUBJECT.fullmatch(subject): + problems.append(f"{short} subject not Conventional Commits: {subject!r}") + extra = body_lines(sha) + if extra: + problems.append(f"{short} has a {extra}-line body; AGENTS.md requires a single line") + + if problems: + print("Commit message check failed:\n") + print("\n".join(f" - {p}" for p in problems)) + print( + "\nExpected: type(scope): summary on ONE line, no body.\n" + "Types: feat fix docs test chore refactor perf ci build revert" + ) + return 1 + + print(f"OK: {len(commits(base, head))} commit(s) follow single-line Conventional Commits.") + return 0 + + +if __name__ == "__main__": + sys.exit(main())