Skip to content

Commit 57ca931

Browse files
authored
Merge pull request #292 from netwrix/dev
script now handles the dict-wrapper case
2 parents 300f2a0 + 468b7e0 commit 57ca931

1 file changed

Lines changed: 24 additions & 1 deletion

File tree

.github/workflows/claude-documentation-reviewer.yml

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,27 @@ jobs:
112112
113113
try:
114114
with open('/tmp/suggestions.json') as f:
115-
suggestions = json.load(f)
115+
data = json.load(f)
116116
except (FileNotFoundError, json.JSONDecodeError) as e:
117117
print(f"Could not read /tmp/suggestions.json: {e}")
118118
sys.exit(1)
119119
120+
# Handle case where Claude wraps the array in an object
121+
if isinstance(data, dict):
122+
for key in data:
123+
if isinstance(data[key], list):
124+
data = data[key]
125+
break
126+
else:
127+
print(f"Unexpected dict structure: {list(data.keys())}")
128+
sys.exit(1)
129+
130+
if not isinstance(data, list):
131+
print(f"Expected array, got {type(data)}")
132+
sys.exit(1)
133+
134+
suggestions = data
135+
120136
if not suggestions:
121137
subprocess.run(
122138
['gh', 'pr', 'comment', pr_number, '--repo', repo,
@@ -128,13 +144,20 @@ jobs:
128144
129145
comments = []
130146
for s in suggestions:
147+
if not isinstance(s, dict):
148+
print(f"Skipping non-object suggestion: {repr(s)[:100]}")
149+
continue
131150
body = s['body'] + '\n```suggestion\n' + s['suggestion'] + '\n```'
132151
c = {'path': s['path'], 'line': s['line'], 'side': 'RIGHT', 'body': body}
133152
if s.get('start_line') and s['start_line'] != s['line']:
134153
c['start_line'] = s['start_line']
135154
c['start_side'] = 'RIGHT'
136155
comments.append(c)
137156
157+
if not comments:
158+
print("No valid suggestions to post")
159+
sys.exit(1)
160+
138161
review_data = {
139162
'commit_id': head_sha,
140163
'body': f'Found {len(comments)} issue(s). To apply all fixes at once, reply with `@claude` followed by your instructions (e.g. `@claude fix all issues`).',

0 commit comments

Comments
 (0)