|
22 | 22 | BRANCH_NAME: ${{ github.event.workflow_run.head_branch }} |
23 | 23 | RUN_URL: ${{ github.event.workflow_run.html_url }} |
24 | 24 | RUN_NAME: ${{ github.event.workflow_run.name }} |
| 25 | + MAX_CODEX_FEEDBACK_ROUNDS: "3" |
25 | 26 | run: | |
26 | 27 | mkdir -p data/output/codex_feedback |
27 | 28 | gh pr list --state open --head "${BRANCH_NAME}" --json number,title,url,body > data/output/codex_feedback/pr.json |
|
64 | 65 | Path("data/output/codex_feedback/comment.md").write_text(comment.strip() + "\n", encoding="utf-8") |
65 | 66 | PY |
66 | 67 | if [ -f data/output/codex_feedback/issue_number.txt ]; then |
67 | | - gh issue comment "$(cat data/output/codex_feedback/issue_number.txt)" --body-file data/output/codex_feedback/comment.md |
| 68 | + issue_number="$(cat data/output/codex_feedback/issue_number.txt)" |
| 69 | + gh issue view "${issue_number}" --comments --json comments > data/output/codex_feedback/issue.json |
| 70 | + python3 - <<'PY' |
| 71 | + import json |
| 72 | + import os |
| 73 | + import textwrap |
| 74 | + from pathlib import Path |
| 75 | +
|
| 76 | + output_dir = Path("data/output/codex_feedback") |
| 77 | + issue = json.loads((output_dir / "issue.json").read_text(encoding="utf-8")) |
| 78 | + comments = [comment.get("body") or "" for comment in issue.get("comments", [])] |
| 79 | + previous_rounds = sum(body.startswith("<!-- codex-pr-feedback:") for body in comments) |
| 80 | + max_rounds = int(os.environ.get("MAX_CODEX_FEEDBACK_ROUNDS", "3")) |
| 81 | + comment_path = output_dir / "comment.md" |
| 82 | + if previous_rounds >= max_rounds: |
| 83 | + comment = textwrap.dedent( |
| 84 | + f"""\ |
| 85 | + <!-- codex-pr-feedback:limit --> |
| 86 | + ## Codex PR Retry Limit Reached |
| 87 | +
|
| 88 | + Automatic Codex feedback reached the retry limit. |
| 89 | +
|
| 90 | + - Previous feedback rounds: `{previous_rounds}` |
| 91 | + - Maximum automatic rounds: `{max_rounds}` |
| 92 | +
|
| 93 | + The workflow removed `codex-bridge` from this issue. Please inspect the PR and re-apply the label only if another automated Codex pass is still appropriate. |
| 94 | + """ |
| 95 | + ) |
| 96 | + comment_path.write_text(comment.strip() + "\n", encoding="utf-8") |
| 97 | + (output_dir / "limit_reached").write_text("true\n", encoding="utf-8") |
| 98 | + else: |
| 99 | + attempt = previous_rounds + 1 |
| 100 | + comment = comment_path.read_text(encoding="utf-8").rstrip() |
| 101 | + comment_path.write_text( |
| 102 | + f"{comment}\n\n- Feedback round: `{attempt}` of `{max_rounds}`\n", |
| 103 | + encoding="utf-8", |
| 104 | + ) |
| 105 | + PY |
| 106 | + if [ -f data/output/codex_feedback/limit_reached ]; then |
| 107 | + gh issue edit "${issue_number}" --remove-label codex-bridge || true |
| 108 | + fi |
| 109 | + gh issue comment "${issue_number}" --body-file data/output/codex_feedback/comment.md |
68 | 110 | else |
69 | 111 | cat data/output/codex_feedback/skip.txt >> "$GITHUB_STEP_SUMMARY" |
70 | 112 | fi |
|
85 | 127 | REVIEW_URL: ${{ github.event.review.html_url }} |
86 | 128 | REVIEW_AUTHOR: ${{ github.event.review.user.login }} |
87 | 129 | REVIEW_BODY: ${{ github.event.review.body }} |
| 130 | + MAX_CODEX_FEEDBACK_ROUNDS: "3" |
88 | 131 | run: | |
89 | 132 | mkdir -p data/output/codex_feedback |
90 | 133 | python3 - <<'PY' |
@@ -122,7 +165,48 @@ jobs: |
122 | 165 | Path("data/output/codex_feedback/comment.md").write_text(comment.strip() + "\n", encoding="utf-8") |
123 | 166 | PY |
124 | 167 | if [ -f data/output/codex_feedback/issue_number.txt ]; then |
125 | | - gh issue comment "$(cat data/output/codex_feedback/issue_number.txt)" --body-file data/output/codex_feedback/comment.md |
| 168 | + issue_number="$(cat data/output/codex_feedback/issue_number.txt)" |
| 169 | + gh issue view "${issue_number}" --comments --json comments > data/output/codex_feedback/issue.json |
| 170 | + python3 - <<'PY' |
| 171 | + import json |
| 172 | + import os |
| 173 | + import textwrap |
| 174 | + from pathlib import Path |
| 175 | +
|
| 176 | + output_dir = Path("data/output/codex_feedback") |
| 177 | + issue = json.loads((output_dir / "issue.json").read_text(encoding="utf-8")) |
| 178 | + comments = [comment.get("body") or "" for comment in issue.get("comments", [])] |
| 179 | + previous_rounds = sum(body.startswith("<!-- codex-pr-feedback:") for body in comments) |
| 180 | + max_rounds = int(os.environ.get("MAX_CODEX_FEEDBACK_ROUNDS", "3")) |
| 181 | + comment_path = output_dir / "comment.md" |
| 182 | + if previous_rounds >= max_rounds: |
| 183 | + comment = textwrap.dedent( |
| 184 | + f"""\ |
| 185 | + <!-- codex-pr-feedback:limit --> |
| 186 | + ## Codex PR Retry Limit Reached |
| 187 | +
|
| 188 | + Automatic Codex feedback reached the retry limit. |
| 189 | +
|
| 190 | + - Previous feedback rounds: `{previous_rounds}` |
| 191 | + - Maximum automatic rounds: `{max_rounds}` |
| 192 | +
|
| 193 | + The workflow removed `codex-bridge` from this issue. Please inspect the PR and re-apply the label only if another automated Codex pass is still appropriate. |
| 194 | + """ |
| 195 | + ) |
| 196 | + comment_path.write_text(comment.strip() + "\n", encoding="utf-8") |
| 197 | + (output_dir / "limit_reached").write_text("true\n", encoding="utf-8") |
| 198 | + else: |
| 199 | + attempt = previous_rounds + 1 |
| 200 | + comment = comment_path.read_text(encoding="utf-8").rstrip() |
| 201 | + comment_path.write_text( |
| 202 | + f"{comment}\n\n- Feedback round: `{attempt}` of `{max_rounds}`\n", |
| 203 | + encoding="utf-8", |
| 204 | + ) |
| 205 | + PY |
| 206 | + if [ -f data/output/codex_feedback/limit_reached ]; then |
| 207 | + gh issue edit "${issue_number}" --remove-label codex-bridge || true |
| 208 | + fi |
| 209 | + gh issue comment "${issue_number}" --body-file data/output/codex_feedback/comment.md |
126 | 210 | else |
127 | 211 | cat data/output/codex_feedback/skip.txt >> "$GITHUB_STEP_SUMMARY" |
128 | 212 | fi |
0 commit comments