Skip to content

Commit 6dade1b

Browse files
fix(compliance-audit): address reviewer comments on issue counters and output
- Add issue-counts.json to header Outputs comment (Copilot #36) - ISSUES_EXISTING: only increment when gh issue comment succeeds, not on || true failure (Copilot #1045) - ISSUES_REMOVED: only increment when gh issue close succeeds, not on || true failure (Copilot #1268) - Make issue-count JSON/summary conditional on issue management running; show skip notice when DRY_RUN=true or CREATE_ISSUES=false (CodeRabbit #1608) - Footer is now always the final element, written after the conditional Issue Management section Co-authored-by: Don Petry <don-petry@users.noreply.github.com>
1 parent 74bdf11 commit 6dade1b

1 file changed

Lines changed: 39 additions & 18 deletions

File tree

scripts/compliance-audit.sh

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
# standards/push-protection.md
99
#
1010
# Outputs:
11-
# $REPORT_DIR/findings.json — machine-readable findings
12-
# $REPORT_DIR/summary.md — human-readable report
11+
# $REPORT_DIR/findings.json — machine-readable findings
12+
# $REPORT_DIR/summary.md — human-readable report
13+
# $REPORT_DIR/issue-counts.json — issue management counts (added/existing/removed)
1314
#
1415
# Environment variables:
1516
# GH_TOKEN — GitHub token with repo/org scope (required)
@@ -1030,19 +1031,24 @@ create_issue_for_finding() {
10301031
2>/dev/null | head -1 || echo "")
10311032

10321033
if [ -n "$existing" ]; then
1033-
# Update existing issue with a comment
1034+
# Update existing issue with a comment; only count as existing if the update succeeds
1035+
local update_ok=true
10341036
gh issue comment "$existing" --repo "$ORG/$repo" \
10351037
--body "**Weekly Compliance Audit** ($(date -u +%Y-%m-%d))
10361038
10371039
This finding is still open.
10381040
10391041
**Detail:** $detail
10401042
1041-
**Standard:** [$standard_ref](https://github.com/$ORG/.github/blob/main/$standard_ref)" 2>/dev/null || true
1042-
# Ensure claude label is present on pre-existing issues
1043+
**Standard:** [$standard_ref](https://github.com/$ORG/.github/blob/main/$standard_ref)" 2>/dev/null || update_ok=false
1044+
# Ensure claude label is present on pre-existing issues regardless
10431045
gh issue edit "$existing" --repo "$ORG/$repo" --add-label "claude" 2>/dev/null || true
1044-
info "Updated existing issue #$existing in $repo for: $check"
1045-
ISSUES_EXISTING=$((ISSUES_EXISTING + 1))
1046+
if [ "$update_ok" = "true" ]; then
1047+
info "Updated existing issue #$existing in $repo for: $check"
1048+
ISSUES_EXISTING=$((ISSUES_EXISTING + 1))
1049+
else
1050+
warn "Failed to update existing issue #$existing in $repo for: $check"
1051+
fi
10461052
# Record existing issue for umbrella
10471053
jq --null-input \
10481054
--arg repo "$repo" \
@@ -1261,11 +1267,14 @@ close_resolved_issues() {
12611267

12621268
# If this check is no longer in findings, close the issue
12631269
if ! echo "$current_checks" | grep -qx "$check_name"; then
1264-
gh issue close "$issue_num" --repo "$ORG/$repo" \
1265-
--comment "Resolved! This check is now passing as of $(date -u +%Y-%m-%d). Closing automatically." \
1266-
2>/dev/null || true
1267-
info "Closed resolved issue #$issue_num in $repo: $issue_title"
1268-
ISSUES_REMOVED=$((ISSUES_REMOVED + 1))
1270+
if gh issue close "$issue_num" --repo "$ORG/$repo" \
1271+
--comment "Resolved! This check is now passing as of $(date -u +%Y-%m-%d). Closing automatically." \
1272+
2>/dev/null; then
1273+
info "Closed resolved issue #$issue_num in $repo: $issue_title"
1274+
ISSUES_REMOVED=$((ISSUES_REMOVED + 1))
1275+
else
1276+
warn "Failed to close resolved issue #$issue_num in $repo: $issue_title"
1277+
fi
12691278
fi
12701279
done <<< "$open_issues"
12711280
}
@@ -1588,12 +1597,11 @@ main() {
15881597
info "Skipping issue creation (DRY_RUN=$DRY_RUN, CREATE_ISSUES=$CREATE_ISSUES)"
15891598
fi
15901599

1591-
# Write issue-management counts
1592-
printf '{"added":%d,"existing":%d,"removed":%d}\n' \
1593-
"$ISSUES_ADDED" "$ISSUES_EXISTING" "$ISSUES_REMOVED" > "$ISSUE_COUNTS_FILE"
1594-
1595-
# Append issue-management count table and footer
1596-
cat >> "$SUMMARY_FILE" <<HEREDOC
1600+
# Write issue-management counts and append to summary (conditional on issue management running)
1601+
if [ "$CREATE_ISSUES" = "true" ] && [ "$DRY_RUN" != "true" ]; then
1602+
printf '{"added":%d,"existing":%d,"removed":%d}\n' \
1603+
"$ISSUES_ADDED" "$ISSUES_EXISTING" "$ISSUES_REMOVED" > "$ISSUE_COUNTS_FILE"
1604+
cat >> "$SUMMARY_FILE" <<HEREDOC
15971605
15981606
## Issue Management
15991607
@@ -1602,6 +1610,19 @@ main() {
16021610
| Added (new) | $ISSUES_ADDED |
16031611
| Existing (updated) | $ISSUES_EXISTING |
16041612
| Removed (resolved) | $ISSUES_REMOVED |
1613+
HEREDOC
1614+
else
1615+
printf '{"added":0,"existing":0,"removed":0}\n' > "$ISSUE_COUNTS_FILE"
1616+
cat >> "$SUMMARY_FILE" <<HEREDOC
1617+
1618+
## Issue Management
1619+
1620+
_Issue management was skipped (DRY\_RUN=$DRY_RUN, CREATE\_ISSUES=$CREATE_ISSUES)._
1621+
HEREDOC
1622+
fi
1623+
1624+
# Append footer (always last)
1625+
cat >> "$SUMMARY_FILE" <<HEREDOC
16051626
16061627
---
16071628
*Generated by the [weekly compliance audit](https://github.com/$ORG/.github/blob/main/.github/workflows/compliance-audit.yml) on $(date -u "+%Y-%m-%d %H:%M UTC").*

0 commit comments

Comments
 (0)