Skip to content

Commit c26e2a1

Browse files
committed
ci: surface governance warnings on PRs
1 parent d910ec5 commit c26e2a1

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

.github/workflows/agent_governance.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ on:
77
permissions:
88
contents: read
99
pull-requests: read
10+
issues: write
1011

1112
jobs:
1213
governance:
@@ -53,3 +54,40 @@ jobs:
5354
if: always()
5455
run: |
5556
cat agent_governance_summary.md >> "$GITHUB_STEP_SUMMARY"
57+
58+
- name: Comment governance warnings
59+
if: >-
60+
always() &&
61+
github.event.pull_request.head.repo.full_name == github.repository
62+
env:
63+
GH_TOKEN: ${{ github.token }}
64+
PR_NUMBER: ${{ github.event.pull_request.number }}
65+
run: |
66+
if ! grep -qi '^| warning |' agent_governance_summary.md; then
67+
exit 0
68+
fi
69+
70+
marker='<!-- agent-governance-warning -->'
71+
body_file="$(mktemp)"
72+
json_file="$(mktemp)"
73+
{
74+
echo "$marker"
75+
echo
76+
cat agent_governance_summary.md
77+
} > "$body_file"
78+
jq -Rs '{body: .}' < "$body_file" > "$json_file"
79+
80+
existing_comment_id="$(gh api --paginate \
81+
"repos/${GITHUB_REPOSITORY}/issues/${PR_NUMBER}/comments" \
82+
--jq ".[] | select(.body | contains(\"${marker}\")) | .id" \
83+
| head -n 1)"
84+
85+
if [ -n "$existing_comment_id" ]; then
86+
gh api --method PATCH \
87+
"repos/${GITHUB_REPOSITORY}/issues/comments/${existing_comment_id}" \
88+
--input "$json_file"
89+
else
90+
gh api --method POST \
91+
"repos/${GITHUB_REPOSITORY}/issues/${PR_NUMBER}/comments" \
92+
--input "$json_file"
93+
fi

0 commit comments

Comments
 (0)