-
Notifications
You must be signed in to change notification settings - Fork 0
fix(scripts): declare the pull-request requirement and cover the elixir repos #138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
9943129
ba6127f
d1544c4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -56,6 +56,16 @@ log() { | |
|
|
||
| branch=$(jq -r '.branch' "$CONFIG_PATH") | ||
| count=$(jq '.repositories | length' "$CONFIG_PATH") | ||
| # require_pull_request が true のリポジトリに送る中身。有効な側は設定が全て同じ | ||
| # なので宣言では 1 箇所にまとめてある。 | ||
| # | ||
| # 欠けていたら止める。null のまま進むと required_pull_request_reviews に null を | ||
| # 送ることになり、「Require a pull request before merging」を外す動作に戻る | ||
| review_settings=$(jq -c '.review_settings' "$CONFIG_PATH") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
review_settings=$(jq -c '.review_settings' "$CONFIG_PATH")この時点で 以下のようなガード節を追加することを検討してください: review_settings=$(jq -c '.review_settings' "$CONFIG_PATH")
if [ -z "$review_settings" ] || [ "$review_settings" = "null" ]; then
log "ERROR: review_settings が設定ファイルに存在しません"
exit 1
fi
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 妥当な指摘です。ガードを入れました(
audit 側にも同じガードを入れました。こちらは null のまま進むと全リポジトリが drift として報告され、実際にはずれていないのに「ずれている」という報告が毎週出ることになります。 終了コードも確認しました。 週次 workflow は非ゼロ終了で失敗扱いにするので、宣言が壊れた状態は「何も見ていない監査が success を返す」ではなく赤として出ます。 |
||
| if [ -z "$review_settings" ] || [ "$review_settings" = "null" ]; then | ||
| log "review_settings が宣言に無い。require_pull_request の適用先が決まらないので中止する" | ||
| exit 1 | ||
| fi | ||
|
|
||
| log "desired state: $CONFIG_PATH" | ||
| log "対象: ${count} リポジトリ (org: ${ORG}, branch: ${branch})" | ||
|
|
@@ -86,9 +96,10 @@ while IFS= read -r spec; do | |
| am=$(printf '%s' "$spec" | jq -r '.allow_auto_merge') | ||
| admins=$(printf '%s' "$spec" | jq -r '.enforce_admins') | ||
| checks=$(printf '%s' "$spec" | jq -c '.required_status_checks') | ||
| pr_required=$(printf '%s' "$spec" | jq -r '.require_pull_request') | ||
|
|
||
| if [ "$APPLY" != "true" ]; then | ||
| log " would apply: ${name} — allow_auto_merge=${am} enforce_admins=${admins} checks=${checks}" | ||
| log " would apply: ${name} — allow_auto_merge=${am} enforce_admins=${admins} require_pull_request=${pr_required} checks=${checks}" | ||
| applied=$((applied + 1)) | ||
| continue | ||
| fi | ||
|
|
@@ -102,10 +113,14 @@ while IFS= read -r spec; do | |
| log " ERROR: ${name} — allow_auto_merge を設定できなかった: ${err}" | ||
| fi | ||
|
|
||
| body=$(printf '%s' "$spec" | jq '{ | ||
| # required_pull_request_reviews は宣言から組み立てる。PUT は全項目置換なので、 | ||
| # ここを無条件に null にすると「Require a pull request before merging」が外れ、 | ||
| # main へ直接 push できる状態になる。宣言している 11 リポジトリのうち 9 つが | ||
| # この設定を持っており、null 固定は保護を落とす操作だった | ||
| body=$(printf '%s' "$spec" | jq --argjson reviews "$review_settings" '{ | ||
| required_status_checks: .required_status_checks, | ||
| enforce_admins: .enforce_admins, | ||
| required_pull_request_reviews: null, | ||
| required_pull_request_reviews: (if .require_pull_request then $reviews else null end), | ||
| restrictions: null | ||
| }') | ||
| if ! err=$(printf '%s' "$body" | gh api -X PUT \ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -55,6 +55,14 @@ log() { | |
|
|
||
| branch=$(jq -r '.branch' "$CONFIG_PATH") | ||
| count=$(jq '.repositories | length' "$CONFIG_PATH") | ||
| # require_pull_request が true のリポジトリに期待する中身。 | ||
| # 欠けていたら止める。null のまま進むと全リポジトリが drift として報告され、 | ||
| # 実際にはずれていないのに「ずれている」と読める報告が毎週出ることになる | ||
| review_settings=$(jq -cS '.review_settings' "$CONFIG_PATH") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ℹ️ [LOW]
ただし、
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 据え置きます。ご指摘のとおり実害はなく、取得方法が違うのは用途が違うためです。
audit 側にだけ コメントで意図を書く案は採りませんでした。 |
||
| if [ -z "$review_settings" ] || [ "$review_settings" = "null" ]; then | ||
| log "review_settings が宣言に無い。期待値が決まらないので中止する" | ||
| exit 1 | ||
| fi | ||
|
|
||
| log "desired state: $CONFIG_PATH" | ||
| log "対象: ${count} リポジトリ (org: ${ORG}, branch: ${branch})" | ||
|
|
@@ -130,6 +138,23 @@ while IFS= read -r spec; do | |
| report "${name}: enforce_admins want=${want_admins} got=${got_admins}" | ||
| fi | ||
|
|
||
| # 「Require a pull request before merging」の有無。これが外れると main へ | ||
| # 直接 push できるようになるが、PR も check run も出ないので気付く手段が無い | ||
| want_pr=$(printf '%s' "$spec" | jq -r '.require_pull_request') | ||
| got_pr=$(printf '%s' "$prot" | jq -r '.required_pull_request_reviews != null') | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ℹ️ [LOW] 通常は一致しますが、GitHub API が
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 据え置きます。ご指摘の分析どおり、現状の書き方で意図どおり動きます(キーが無い場合も 提案の 2 案も挙動は同じです。
jq の なお There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ℹ️ [LOW] 現在のロジックは以下の通りです: got_pr=$(printf '%s' "$prot" | jq -r '.required_pull_request_reviews != null')GitHub API が 一方、 現時点では実測で問題ないとのことですが、
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 据え置きます。ご指摘の「継続的に確認できる仕組み」は、このスクリプト自体がそれです。
つまり「API の応答形式が変わったら誤検知が起きる」ではなく、変わったら報告される方に倒れています。監査対象に入れたことがそのまま継続確認になっている、という関係です。 なお There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ℹ️ [LOW] got_pr=$(printf '%s' "$prot" | jq -r '.required_pull_request_reviews != null')この判定は GitHub API が より堅牢にするなら
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 同じ箇所への 2 回目の指摘で、前のスレッドで回答済みです。据え置きます。 なお今回の本文は冒頭で「フィールドを返さない場合に 提案の |
||
| if [ "$want_pr" != "$got_pr" ]; then | ||
| report "${name}: require_pull_request want=${want_pr} got=${got_pr}" | ||
| elif [ "$want_pr" = "true" ]; then | ||
| got_reviews=$(printf '%s' "$prot" | jq -cS '.required_pull_request_reviews | { | ||
| required_approving_review_count, | ||
| dismiss_stale_reviews, | ||
| require_code_owner_reviews | ||
| }') | ||
| if [ "$review_settings" != "$got_reviews" ]; then | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
現在の実装では また、
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 明記しました(
実測もしました。宣言していない 3 フィールドは 9 リポジトリすべて API 既定値です。 したがって現時点で apply がリセットするものはありません。ただしご指摘のとおり「宣言していない = 保たれる」ではなく「宣言していない = 既定に戻る」が正しい理解なので、それを書いた形です。desired state を一方的に送るスクリプトの性質そのもので、 |
||
| report "${name}: review settings want=${review_settings} got=${got_reviews}" | ||
| fi | ||
| fi | ||
|
|
||
| want_strict=$(printf '%s' "$spec" | jq -r '.required_status_checks.strict') | ||
| # `// "なし"` は使えない。jq の // は false も空として扱うため、 | ||
| # strict=false が「なし」に化ける | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ℹ️ [LOW]
tenbin_cacheのrequire_pull_request: falseとstrict: trueの組み合わせtenbin_cacheはrequire_pull_request: false(PR 不要)かつstrict: true(up-to-date 必須)という設定になっています。PR が不要ならstrictの設定は実質的に意味を持ちません。invariantsに「揃えるかどうかは未決」と記載されており、現状を写したものであることは理解できますが、この矛盾した組み合わせについてinvariantsまたは当該エントリのコメントで明示的に言及しておくと、将来の混乱を防げます。There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
鋭い指摘です。ただし「実質的に意味を持たない」よりもう少し込み入っています。
strictは無意味にはなりません。 required status checks は PR のマージだけでなく、保護ブランチへの push にも効きます。tenbin_cacheに PR 必須が無くても、checks が緑でないコミットは push できません。むしろ効いているのは
enforce_admins: falseの方です。管理者はブランチ保護を突破できるので、require_pull_request: falseと組み合わさると 管理者はtenbin_cacheとlatex-environmentの main へ直接 push できます。これらは実質的に単独メンテナのリポジトリなので、現実的にはこの経路が開いています。それが望ましいかどうかが
invariantsに書いた「揃えるかどうかは未決」の中身です。この PR は現状を写して監査対象に載せるところまでで、値の是非は変えていません(変えるなら 2 リポジトリの保護を強める操作になり、別の判断が要ります)。指摘の趣旨(この組み合わせが目に付く形で残っている)はそのとおりなので、判断が必要になったときのために、いま監査で毎週報告される状態にしてあります。値を変えれば drift として出ます。