Skip to content

Commit 5006273

Browse files
authored
🤖 Add CI job to block merge on unresolved Codex comments (#76)
This PR adds a CI check that blocks merging when the `chatgpt-codex-connector[bot]` has unresolved comments on a PR. ## Changes - **New CI job**: `check-codex-comments` that runs on every PR - **Script**: `scripts/check_codex_comments.sh` that detects Codex bot comments - **Integration**: Added Codex check to `wait_pr_checks.sh` loop ## How it works 1. The CI job runs on every pull request 2. It checks for any comments from `chatgpt-codex-connector[bot]` 3. If comments exist, the check fails and blocks merge 4. The `wait_pr_checks.sh` script also checks before declaring a PR ready ## Example On PR #74, the bot left a comment about the macOS signing certificate. With this change, that PR would be blocked from merging until the comment is addressed or resolved. _Generated with `cmux`_
1 parent 9543f22 commit 5006273

File tree

3 files changed

+116
-2
lines changed

3 files changed

+116
-2
lines changed

.github/workflows/ci.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,19 @@ jobs:
8181
env:
8282
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
8383
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
84+
85+
check-codex-comments:
86+
name: Check Codex Comments
87+
runs-on: ubuntu-latest
88+
if: github.event_name == 'pull_request'
89+
steps:
90+
- name: Checkout code
91+
uses: actions/checkout@v4
92+
93+
- name: Check for unresolved Codex comments
94+
env:
95+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
96+
run: |
97+
./scripts/check_codex_comments.sh ${{ github.event.pull_request.number }}
98+
8499
# Trigger CI run

scripts/check_codex_comments.sh

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# Check if PR number is provided
5+
if [ $# -eq 0 ]; then
6+
echo "Usage: $0 <pr_number>"
7+
exit 1
8+
fi
9+
10+
PR_NUMBER=$1
11+
BOT_LOGIN_REST="chatgpt-codex-connector[bot]" # REST API uses [bot] suffix
12+
BOT_LOGIN_GRAPHQL="chatgpt-codex-connector" # GraphQL does not
13+
14+
echo "Checking for unresolved Codex comments in PR #${PR_NUMBER}..."
15+
16+
# Get all regular issue comments from the Codex bot (these can't be resolved)
17+
REGULAR_COMMENTS=$(gh api "/repos/{owner}/{repo}/issues/${PR_NUMBER}/comments" \
18+
--jq "[.[] | select(.user.login == \"${BOT_LOGIN_REST}\")]")
19+
20+
REGULAR_COUNT=$(echo "$REGULAR_COMMENTS" | jq 'length')
21+
22+
# Use GraphQL to get review threads and their resolution status
23+
# Only count threads from the bot that are NOT resolved
24+
GRAPHQL_QUERY='query($owner: String!, $repo: String!, $pr: Int!) {
25+
repository(owner: $owner, name: $repo) {
26+
pullRequest(number: $pr) {
27+
reviewThreads(first: 100) {
28+
nodes {
29+
isResolved
30+
comments(first: 1) {
31+
nodes {
32+
author {
33+
login
34+
}
35+
body
36+
createdAt
37+
path
38+
line
39+
}
40+
}
41+
}
42+
}
43+
}
44+
}
45+
}'
46+
47+
# Extract owner and repo from gh cli
48+
REPO_INFO=$(gh repo view --json owner,name --jq '{owner: .owner.login, name: .name}')
49+
OWNER=$(echo "$REPO_INFO" | jq -r '.owner')
50+
REPO=$(echo "$REPO_INFO" | jq -r '.name')
51+
52+
# Query for unresolved review threads from the bot
53+
UNRESOLVED_THREADS=$(gh api graphql \
54+
-f query="$GRAPHQL_QUERY" \
55+
-F owner="$OWNER" \
56+
-F repo="$REPO" \
57+
-F pr="$PR_NUMBER" \
58+
--jq "[.data.repository.pullRequest.reviewThreads.nodes[] | select(.isResolved == false and .comments.nodes[0].author.login == \"${BOT_LOGIN_GRAPHQL}\")]")
59+
60+
UNRESOLVED_COUNT=$(echo "$UNRESOLVED_THREADS" | jq 'length')
61+
62+
echo "Found ${REGULAR_COUNT} regular comment(s) from bot"
63+
echo "Found ${UNRESOLVED_COUNT} unresolved review thread(s) from bot"
64+
65+
# If there are any unresolved comments or threads from Codex, fail
66+
TOTAL_UNRESOLVED=$((REGULAR_COUNT + UNRESOLVED_COUNT))
67+
68+
if [ $TOTAL_UNRESOLVED -gt 0 ]; then
69+
echo ""
70+
echo "❌ Found ${TOTAL_UNRESOLVED} unresolved comment(s) from Codex in PR #${PR_NUMBER}"
71+
echo ""
72+
echo "Codex comments:"
73+
74+
if [ $REGULAR_COUNT -gt 0 ]; then
75+
echo "$REGULAR_COMMENTS" | jq -r '.[] | " - [\(.created_at)] \(.body[0:100] | gsub("\n"; " "))..."'
76+
fi
77+
78+
if [ $UNRESOLVED_COUNT -gt 0 ]; then
79+
echo "$UNRESOLVED_THREADS" | jq -r '.[] | " - [\(.comments.nodes[0].createdAt)] \(.comments.nodes[0].path // "comment"):\(.comments.nodes[0].line // "") - \(.comments.nodes[0].body[0:100] | gsub("\n"; " "))..."'
80+
fi
81+
82+
echo ""
83+
echo "Please address or resolve all Codex comments before merging."
84+
exit 1
85+
else
86+
echo "✅ No unresolved Codex comments found"
87+
exit 0
88+
fi

scripts/wait_pr_checks.sh

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,21 @@ while true; do
6868
# Check if all checks passed and merge state is clean
6969
if echo "$CHECKS" | grep -q "pass" && ! echo "$CHECKS" | grep -qE "pending|fail"; then
7070
if [ "$MERGE_STATE" = "CLEAN" ]; then
71-
echo "✅ All checks passed and PR is ready to merge!"
71+
# Check for unresolved Codex comments
72+
echo "✅ All checks passed!"
7273
echo ""
7374
gh pr checks "$PR_NUMBER"
74-
exit 0
75+
echo ""
76+
echo "🤖 Checking for unresolved Codex comments..."
77+
if ./scripts/check_codex_comments.sh "$PR_NUMBER"; then
78+
echo ""
79+
echo "✅ PR is ready to merge!"
80+
exit 0
81+
else
82+
echo ""
83+
echo "❌ Please resolve Codex comments before merging."
84+
exit 1
85+
fi
7586
elif [ "$MERGE_STATE" = "BLOCKED" ]; then
7687
echo "⏳ All checks passed but still blocked (waiting for required checks)..."
7788
fi

0 commit comments

Comments
 (0)