Skip to content

feat: .github/policies/ テンプレート群を追加 (closes #723) - #725

Merged
keito4 merged 4 commits into
mainfrom
feat/github-policies-templates
May 9, 2026
Merged

feat: .github/policies/ テンプレート群を追加 (closes #723)#725
keito4 merged 4 commits into
mainfrom
feat/github-policies-templates

Conversation

@keito4

@keito4 keito4 commented May 9, 2026

Copy link
Copy Markdown
Owner

Why

config-contribution-discover の網羅的スキャン (Issue #723) で発見した、複数 repo (Elu-co-jp/job_description, Elu-co-jp/job-post-generator) で共通の .github/policies/ 設定を keito4/config に取り込む。

判定基準を一元管理することで:

  • ライセンス例外の追跡が可能 (現行 security.yml の --failOn ハードコードでは不可)
  • 複雑度しきい値を CI ワークフロー間で共有
  • セキュリティ SLA を明文化し、対応基準を共通化

What

新規テンプレート 3 ファイル + repo-maintenance section 3.22 への配布登録:

新規ファイル

ファイル 内容
templates/github/policies/complexity-thresholds.json McCabe / 認知的複雑度・関数行数・ネスト深さ・ファイル行数の warning/error 閾値 (JSON Schema 検証付き)
templates/github/policies/allowed-licenses.json 許可 (MIT/Apache-2.0/BSD/ISC 等)・禁止 (GPL/AGPL/LGPL/SSPL/BUSL)・例外パッケージリスト
templates/github/policies/severity-definitions.md Critical (24h SLA) / High (7d) / Medium (30d) / Low (90d) と対応フロー・エスカレーションポリシー

repo-maintenance.md 変更

  • section 3.22 同期テーブルに .github/policies/* をテンプレート行として追加
  • テンプレートファイル同期ロジックに path-mapping ブロックを追加 (templates/github/policies/.github/policies/)
  • 配布ポリシーは「欠落ファイルのみ追加」(各 repo でカスタマイズされうるため上書きしない)

How

/repo-maintenance --mode full 実行時、以下が起きる:

  1. 既存の MANAGED_FILES と TEMPLATE_DIRS の処理後
  2. templates/github/policies/*.{json,md}.github/policies/ へコピー (欠落のみ)
  3. 既存の policies は保持される (上書きしない)

Risk

  • 低: 新規テンプレート追加と配布ロジック追加のみ
  • 既存ファイルは上書きしない (欠落のみ追加) ため、各 repo でカスタマイズ済みの policies は影響を受けない
  • 配布された policies はそのままでは何も起こらず、ワークフローから参照して初めて機能する (後続作業)

Test plan

  • prettier --check パス
  • pre-commit hooks (test 95 件) パス
  • 別 repo で /repo-maintenance --mode full を実行し、.github/policies/ 3 ファイルが配置されることを確認
  • 既に policies がある repo で実行し、上書きされないことを確認

Follow-up

Closes #723

🤖 Generated with Claude Code

Summary by CodeRabbit

Release Notes

  • New Features

    • Added GitHub policy templates for license management, code complexity thresholds, and vulnerability severity definitions.
  • Documentation

    • Added security severity levels guide with SLA targets and response workflows.
  • Tests

    • Added validation tests for policy templates.
  • Chores

    • Updated repository maintenance procedures to include policy template synchronization.

setup-team-protection と CI ワークフローで参照する判定基準を一元管理する
ためのポリシーテンプレート (issue #723)。

- templates/github/policies/complexity-thresholds.json: McCabe / 認知的
  複雑度・関数行数・ネスト深さ・ファイル行数の warning/error 閾値
- templates/github/policies/allowed-licenses.json: 許可・禁止・例外
  ライセンスポリシー (複合ライセンス対応)
- templates/github/policies/severity-definitions.md: セキュリティ重大度
  (Critical/High/Medium/Low) と SLA・対応フローの定義

repo-maintenance.md section 3.22 に「テンプレート (欠落ファイルのみ追加)」
として登録。templates/github/policies/ → .github/policies/ の path mapping
で配布される。

ソース: Elu-co-jp/job_description, Elu-co-jp/job-post-generator

Refs: #723
@coderabbitai

coderabbitai Bot commented May 9, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

This PR establishes three reusable GitHub policy templates for managing license compliance, code complexity standards, and security vulnerability response. It registers these templates with the Config Template Sync workflow so they distribute missing files to target repositories, and validates all three templates with comprehensive test coverage.

Changes

Policy Templates Addition

Layer / File(s) Summary
Maintenance Documentation & Sync Logic
.claude/commands/repo-maintenance.md
Registers .github/policies/* as a template sync target in the Config Template Sync section. Adds logic to copy only missing policy files from templates/github/policies/ to target repositories.
Policy Template Definitions
templates/github/policies/allowed-licenses.json, templates/github/policies/complexity-thresholds.json, templates/github/policies/severity-definitions.md
Three new policy templates: (1) allowed-licenses.json defines allowed permissive/open-source licenses and blocks GPL/AGPL/LGPL/SSPL/BUSL with exceptions support; (2) complexity-thresholds.json specifies warning/error thresholds for cyclomatic complexity, cognitive complexity, lines per function, nesting depth, and file lines, with exclusion patterns for tests and type declarations; (3) severity-definitions.md defines Critical/High/Medium/Low severity tiers with SLA targets, classification conditions, response workflows, escalation policies, and exception request procedures.
Policy Template Validation
test/policy-templates.test.js
Jest test suite validates that all three templates exist, contain required structure and properties, enforce data integrity (non-overlapping license lists, warning < error ordering), include expected entries (e.g., MIT/Apache-2.0 allowed, GPL/AGPL blocked), and contain severity patterns with SLA timeline references.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related issues

  • #723: This PR directly implements the feature proposed in issue #723 by adding the three GitHub policy templates (complexity-thresholds.json, allowed-licenses.json, severity-definitions.md) and registering them in the Config Template Sync workflow.

Possibly related PRs

  • keito4/config#597: Both PRs modify the Config Template Sync section in repo-maintenance.md to register new template sync targets; this PR adds policy files while the referenced PR implements the broader sync infrastructure.
  • keito4/config#575: Both PRs extend repo-maintenance documentation by adding new template-sync or template-check steps to organize template distribution and validation.

Poem

A rabbit hops through config lands so wide,
Bringing order where the policies hide,
Licenses sorted, complexity tamed,
SLA targets now properly named,
Templates shared with precision and pride! 🐰✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: adding three policy templates for GitHub configuration (.github/policies/), with a reference to the closing issue #723.
Description check ✅ Passed The PR description comprehensively covers all required sections from the template: Summary, Why, What, How to test, Checklist, and Related issues, with clear details about objectives and implementation.
Linked Issues check ✅ Passed The PR fully implements the requirements from issue #723: adds three policy templates (complexity-thresholds.json, allowed-licenses.json, severity-definitions.md) to templates/github/policies/, registers them in repo-maintenance.md section 3.22, and includes validation tests.
Out of Scope Changes check ✅ Passed All code changes are directly aligned with issue #723 objectives: policy template files, repo-maintenance.md updates, and test suite for template validation. No extraneous changes detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/github-policies-templates

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@claude

claude Bot commented May 9, 2026

Copy link
Copy Markdown
Contributor

Claude finished @keito4's task in 1m 39s —— View job


PR レビュー

  • コンテキスト収集・ファイル読み込み
  • 変更内容の分析
  • レビューフィードバックの作成

総評

Verdict: APPROVE (minor / recommendation レベルの指摘のみ)

新規テンプレート3ファイル + repo-maintenance.md への配布ロジック追加という additive-only な変更。既存ファイルの上書きなし・破壊的変更なし・PR説明の Why/What/How/Risk/Test plan が揃っており、全体的に品質は高い。


指摘事項

minor: $schema フィールドの用途が不正確

complexity-thresholds.json (L2)・allowed-licenses.json (L2) の両ファイルで

"$schema": "https://json-schema.org/draft/2020-12/schema"

を宣言しているが、これは「このファイル自体が JSON Schema メタスキーマに準拠した スキーマ定義である」という宣言。実際にはデータファイルであるため、JSON Schema バリデーターが meta-schema を使って検証しようとすると false-positive エラーになる可能性がある。

対処案:

  • 自己検証スキーマ("$schema": "./complexity-thresholds.schema.json" のような別途作成した schema ファイルへの参照)を使う
  • または $schema を削除して description フィールドで代替する

Fix this →


minor: complexity-thresholds.json と既存スクリプトの乖離

script/code-complexity-check.shTHRESHOLD=10(循環的複雑度)をハードコードしており、complexity-thresholds.json を参照していない。現状では JSON ファイルの閾値は CI に反映されない。

PR説明にフォローアップとして記載されているが、ファイル内のコメントか README に「このファイルはスクリプトからは未参照。後続 Issue で統合予定」と明示しておくと将来の混乱を防げる。


minor: LGPL 系のブロックはユースケースによっては過剰

allowed-licenses.jsonblockedLGPL-2.0 / LGPL-2.1 / LGPL-3.0 が含まれているが、LGPL(特に 2.1)は動的リンク利用であれば商用プロダクトでも問題ないケースが多い。readlinencurses 等の一般的な間接依存が誤検知になる可能性がある。

対処案: notes.blocked に「LGPL は動的リンク利用の場合は例外申請なしで使用可」等の補足を追記する。


recommendation: exceptions 配列のエントリ構造が未定義

"exceptions": []

最初の例外を追加する際にどのような構造で書けば良いか不明。以下のようなインラインコメント(JSON はコメント非対応なので notes 内)を追加しておくと運用しやすい:

"exception_format": {
  "package": "example-pkg",
  "license": "GPL-3.0",
  "reason": "...",
  "approved_by": "security-team",
  "approved_at": "2026-01-01",
  "expires_at": "2027-01-01"
}

recommendation: severity-definitions.mdSECURITY.md リンク

L137 の ../../SECURITY.md.github/policies/ への配置を前提とした相対パスで正しい。ただし templates/ 内にあるうちは相対リンクが broken になる。テンプレートであることを明示するコメントをファイル冒頭に追加すると良い(例: ``)。


肯定的な点

  • JSON バリデーション・構文は問題なし(両ファイルとも valid JSON)
  • 配布ロジックの [ ! -f "$dst_file" ] チェックにより既存ファイルの上書き防止が適切に実装されている
  • severity-definitions.md のSLA定義とエスカレーションポリシーが具体的で実用的
  • allowed-licenses.json のブロックリストが security.yml のハードコード --failOn "GPL-3.0;AGPL-3.0;GPL-2.0;AGPL-1.0" より網羅的(SSPL-1.0・BUSL-1.1 追加は適切)

@keito4 keito4 self-assigned this May 9, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ce400b7124

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +29 to +31
"LGPL-2.0",
"LGPL-2.1",
"LGPL-3.0",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Block LGPL SPDX variants explicitly

Add the -only / -or-later SPDX variants for LGPL to the blocked list, otherwise exact-string license checks can miss common identifiers such as LGPL-2.1-or-later and LGPL-3.0-or-later. This file already enumerates those variants for GPL/AGPL, so leaving LGPL as only LGPL-2.0, LGPL-2.1, and LGPL-3.0 creates an inconsistency that can let copyleft dependencies slip through policy enforcement.

Useful? React with 👍 / 👎.

@keito4

keito4 commented May 9, 2026

Copy link
Copy Markdown
Owner Author

(aside)
@claude PRがbaseにマージする際にCIが落ちています。
修正してください。

@claude

claude Bot commented May 9, 2026

Copy link
Copy Markdown
Contributor

Claude finished @keito4's task in 12m 23s —— View job


CI 修正完了 ✅

  • コンテキスト収集・リクエスト理解
  • CI失敗の原因調査
  • テストファイル追加でCIを実際に実行させる(19テスト追加)
  • ローカルでテスト確認(114/114 pass)
  • コミット・プッシュ完了

調査結果と修正内容

根本原因

CI自体は失敗していないが、Lint & Format / Unit Tests / Integration Tests がすべて SKIPPING 状態でした。

原因は ci.ymldorny/paths-filter の内部フィルタ設定にあります:

フィルタ マッチ対象 マッチ結果
code **.js, **.ts, src/** など ❌ false
scripts **.sh, script/** など ❌ false
dependencies package.json, package-lock.json ❌ false
workflows .github/workflows/** ❌ false

PRで変更されたファイル(.mdtemplates/**/*.json)はどのフィルタにもマッチしないため、substantive なCI検証がスキップされていました。

また mergeStateStatus: BLOCKED の理由は reviewDecision: REVIEW_REQUIRED(CI失敗ではなく、承認が未了)です。

実施した修正

test/policy-templates.test.js を新規追加(19テスト):

  • allowed-licenses.json:allowed/blocked の存在・重複なし・主要ライセンス確認
  • complexity-thresholds.json:各メトリクスの warning < error 一貫性検証
  • severity-definitions.md:Critical/High/Medium/Low/SLA 定義の存在確認

.js ファイルの追加により code フィルタが true になり、次回プッシュ以降は Lint & FormatUnit Tests が実際に実行されます。

CI結果

Test Suites: 6 passed, 6 total
Tests:       114 passed, 114 total (95 既存 + 19 新規)

⚠️ マージについて: PRは REVIEW_REQUIRED でブロックされています(CI失敗ではありません)。レビュアーの承認が必要です。
| Branch: feat/github-policies-templates

github-actions Bot and others added 3 commits May 9, 2026 03:13
templates/github/policies/ 以下のJSONとMarkdownファイルは
dorny/paths-filter の code/scripts/dependencies フィルタに
マッチしないためCIジョブがすべてSKIPしていた。

テストファイル追加により:
- CI Lint & Format / Unit Tests が実際に実行される
- policy JSON のスキーマ・閾値一貫性を自動検証
- severity-definitions.md のSLA定義存在確認

Co-authored-by: keito4 <keito4@users.noreply.github.com>
…templates

# Conflicts:
#	.claude/commands/repo-maintenance.md
@keito4
keito4 merged commit dea741e into main May 9, 2026
15 of 16 checks passed
@keito4
keito4 deleted the feat/github-policies-templates branch May 9, 2026 03:27
@github-actions

github-actions Bot commented May 9, 2026

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 1.112.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released リリース済み

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: Add .github/policies/ templates (complexity / license / severity definitions)

1 participant