Skip to content

Commit b486bf8

Browse files
committed
Enhance review processing script and GitHub Actions workflow
Added a function to ensure required labels exist in the GitHub repository, improving issue creation reliability. Updated the workflow to handle failures gracefully during the processing of JSON reviews, ensuring commits are attempted even if previous steps fail. Enhanced error handling in the script for better debugging and user feedback.
1 parent d99b6d5 commit b486bf8

File tree

2 files changed

+39
-6
lines changed

2 files changed

+39
-6
lines changed

.github/workflows/process_json_reviews.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,19 @@ jobs:
3535
env:
3636
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3737
run: |
38-
python scripts/process_json_reviews.py
38+
python scripts/process_json_reviews.py || exit 1
3939
4040
- name: Commit and push processed files
41+
if: success() || failure() # Run even if previous step failed
4142
run: |
4243
git config --local user.email "[email protected]"
4344
git config --local user.name "GitHub Action"
4445
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git
45-
git add reviews/processed/
46+
git add reviews/processed/ || true
4647
if git diff --staged --quiet; then
4748
echo "No processed files to commit"
4849
else
49-
git commit -m "Move processed JSON reviews to processed/ directory [skip ci]"
50-
git push origin HEAD:main
50+
git commit -m "Move processed JSON reviews to processed/ directory [skip ci]" || exit 0
51+
git push origin HEAD:main || exit 0
5152
fi
5253

Scripts/process_json_reviews.py

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,33 @@ def format_issue_body(review_data: Dict[str, Any]) -> str:
108108
return "\n".join(body_lines)
109109

110110

111+
def ensure_labels_exist(repo: Any) -> None:
112+
"""Ensure required labels exist in the repository."""
113+
required_labels = {
114+
"review": "1f76b4", # Blue
115+
"correct": "0e8a16", # Green
116+
"needs-review": "fbca04", # Yellow
117+
"incorrect": "d73a4a", # Red
118+
}
119+
120+
existing_labels = {label.name: label for label in repo.get_labels()}
121+
122+
for label_name, label_color in required_labels.items():
123+
if label_name not in existing_labels:
124+
try:
125+
repo.create_label(label_name, label_color)
126+
print(f" ✓ Created label: {label_name}")
127+
except Exception as e:
128+
# Label might already exist or we don't have permission
129+
print(f" ⚠ Could not create label '{label_name}': {e}", file=sys.stderr)
130+
131+
111132
def create_github_issue(repo: Any, review_data: Dict[str, Any]) -> Optional[int]:
112133
"""Create a GitHub Issue from review data."""
113134
try:
135+
# Ensure labels exist
136+
ensure_labels_exist(repo)
137+
114138
title = f"[Review] {review_data['method'].replace('-', ' ').title()}"
115139
body = format_issue_body(review_data)
116140

@@ -129,6 +153,8 @@ def create_github_issue(repo: Any, review_data: Dict[str, Any]) -> Optional[int]
129153

130154
except Exception as e:
131155
print(f" ✗ Error creating issue: {e}", file=sys.stderr)
156+
import traceback
157+
traceback.print_exc()
132158
return None
133159

134160

@@ -172,8 +198,14 @@ def main() -> None:
172198
sys.exit(1)
173199

174200
# Initialize GitHub client
175-
g = Github(github_token)
176-
repo = g.get_repo(f"{REPO_OWNER}/{REPO_NAME}")
201+
try:
202+
g = Github(github_token)
203+
repo = g.get_repo(f"{REPO_OWNER}/{REPO_NAME}")
204+
except Exception as e:
205+
print(f"Error: Failed to connect to GitHub repository: {e}", file=sys.stderr)
206+
import traceback
207+
traceback.print_exc()
208+
sys.exit(2)
177209

178210
# Ensure directories exist
179211
os.makedirs(REVIEWS_DIR, exist_ok=True)

0 commit comments

Comments
 (0)