Loading...
Loading...
Audit GitHub repository branch governance and workflow hygiene. Use when asked to review rulesets, required status checks, update restrictions, delete-on-merge settings, auto-merge workflow reliability, stale branches, ghost workflow registrations, or branch-policy drift.
npx skill4agent add oceanswave/i-know-kung-fu github-branch-policyCannot update this protected refghrepoworkflowjqOWNER/REPOOWNER_REPO="${OWNER_REPO:-$(gh repo view --json nameWithOwner -q .nameWithOwner)}"
OWNER="${OWNER_REPO%/*}"
REPO="${OWNER_REPO#*/}"
DEFAULT_BRANCH="$(gh repo view "$OWNER_REPO" --json defaultBranchRef -q .defaultBranchRef.name)"
echo "Auditing $OWNER_REPO (default: $DEFAULT_BRANCH)"gh api "repos/$OWNER/$REPO" \
--jq '{allow_auto_merge,allow_squash_merge,allow_merge_commit,allow_rebase_merge,delete_branch_on_merge,default_branch}'allow_auto_merge: truedelete_branch_on_merge: trueallowed_merge_methodsgh api "repos/$OWNER/$REPO/rulesets" \
--jq '.[] | {id,name,enforcement,target,include:(.conditions.ref_name.include // []),rules:[.rules[].type]}'
gh api "repos/$OWNER/$REPO/rulesets" \
--jq '.[] | select(.enforcement=="active") | .rules[] | select(.type=="pull_request" or .type=="required_status_checks")'~DEFAULT_BRANCHpull_requestrequired_status_checksrequired_linear_historynon_fast_forwarddeletionpull_requestrequired_status_checksgh api "repos/$OWNER/$REPO/rulesets" \
--jq '.[] | .rules[] | select(.type=="required_status_checks") | .parameters.required_status_checks[].context'
gh pr list --state all --limit 20 --json number \
--jq '.[0].number' | xargs -I{} gh pr view {} --json statusCheckRollupciVercelVercel Preview Commentsgh api "repos/$OWNER/$REPO/rulesets" \
--jq '.[] | {name, pull_request_rules:[.rules[] | select(.type=="pull_request") | .parameters.require_code_owner_review]}'require_code_owner_reviewfalserequire_code_owner_review: falsegh api "repos/$OWNER/$REPO/actions/permissions" \
--jq '{enabled,allowed_actions,sha_pinning_required}'
gh api "repos/$OWNER/$REPO/actions/permissions/selected-actions" \
--jq '{github_owned_allowed,verified_allowed,patterns_allowed}'allowed_actions: selectedgh api "repos/$OWNER/$REPO/actions/workflows" \
--jq '.workflows[] | [.id,.name,.path,.state] | @tsv' | sort
gh workflow list --allgh workflow disable <workflow_id>AUTO_WF="Enable PR Auto-Merge" # adjust if needed
gh workflow view "$AUTO_WF" --yaml | sed -n '1,220p'
gh run list --workflow "$AUTO_WF" --limit 20 \
--json databaseId,event,status,conclusion,headBranch,createdAtRUN_ID="<id>"
gh run view "$RUN_ID" --json event,conclusion,jobspull_request_targetpull_requestpushpull_request_targetCannot update this protected refgh workflow list --all
gh run list --workflow "Auto Update PR Branches" --limit 20gh api "repos/$OWNER/$REPO" --jq '{delete_branch_on_merge}'
gh api "repos/$OWNER/$REPO/actions/workflows" \
--jq '.workflows[] | {name,path,state}'delete_branch_on_merge: truegh api "repos/$OWNER/$REPO/branches" --paginate --jq '.[].name' | sort -u > /tmp/live-branches.txt
gh pr list --state merged --limit 500 --json headRefName --jq '.[].headRefName' | sort -u > /tmp/merged-pr-branches.txt
gh pr list --state closed --limit 500 --json headRefName,mergedAt \
--jq '.[] | select(.mergedAt==null) | .headRefName' | sort -u > /tmp/closed-pr-branches.txt
cat /tmp/merged-pr-branches.txt /tmp/closed-pr-branches.txt | sort -u > /tmp/candidate-stale-branches.txt
comm -12 /tmp/live-branches.txt /tmp/candidate-stale-branches.txtgit push origin --delete "<branch>"gh api "repos/$OWNER/$REPO/rulesets" --jq 'length'
gh api "repos/$OWNER/$REPO/branches/$DEFAULT_BRANCH/protection" 2>/dev/null | jq '.'gh pr view <pr_number> --json autoMergeRequestgh run list --workflow "Enable PR Auto-Merge" --limit 5## Branch Policy Audit Report
- Repository: OWNER/REPO
- Default branch: <branch>
- Timestamp (UTC): <iso8601>
- Overall status: PASS | NEEDS_ACTION | BLOCKED
### Findings
1. [SEV-<1-3>] <check name> - <pass/fail summary>
Evidence: <key command output summary>
Remediation: <next action>
### Actions Taken
1. <action performed or "none">
### Follow-up
1. <required human decision or "none">push + 0 jobs + no logsgh api