Skip to content

Commit 1b9e7f8

Browse files
committed
ci: Fix comment update and content
Signed-off-by: Chaitanya Tata <[email protected]>
1 parent 8b41d2c commit 1b9e7f8

File tree

1 file changed

+17
-89
lines changed

1 file changed

+17
-89
lines changed

.github/workflows/module-monitor.yml

Lines changed: 17 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -248,42 +248,7 @@ jobs:
248248
diff_content.append("")
249249
diff_content.extend(table_rows)
250250
251-
# Add commit details section
252-
diff_content.append("")
253-
diff_content.append("### Commit Details:")
254-
diff_content.append("")
255-
256-
# Collect unique commits
257-
unique_commits = set()
258-
for path in sorted(all_paths):
259-
old_blob = old_blobs.get(path, {})
260-
new_blob = new_blobs.get(path, {})
261-
old_commit_hash = extract_commit_from_url(old_blob.get('url', ''))
262-
new_commit_hash = extract_commit_from_url(new_blob.get('url', ''))
263-
if old_commit_hash != "Unknown":
264-
unique_commits.add(old_commit_hash)
265-
if new_commit_hash != "Unknown":
266-
unique_commits.add(new_commit_hash)
267-
268-
# Show commit details
269-
for commit_hash in sorted(unique_commits):
270-
commit_info = get_commit_info(commit_hash)
271-
commit_status = get_commit_status(commit_hash)
272-
273-
if 'subject' in commit_info:
274-
commit_line = f"- **{commit_info['hash']}**: {commit_info['subject']} (by {commit_info['author']} on {commit_info['date']})"
275-
# Add branch information if available
276-
if 'display' in commit_status and '(' in commit_status['display']:
277-
branch_info = commit_status['display'].split('(')[1].rstrip(')')
278-
commit_line += f" - {branch_info}"
279-
diff_content.append(commit_line)
280-
else:
281-
commit_line = f"- **{commit_info['hash']}**: Commit details not available"
282-
# Add branch information if available
283-
if 'display' in commit_status and '(' in commit_status['display']:
284-
branch_info = commit_status['display'].split('(')[1].rstrip(')')
285-
commit_line += f" - {branch_info}"
286-
diff_content.append(commit_line)
251+
287252
else:
288253
diff_content.append("## No Changes Detected")
289254
diff_content.append("")
@@ -303,36 +268,12 @@ jobs:
303268
print('\n'.join(diff_content), file=sys.stdout)
304269
print("EOF", file=sys.stdout)
305270
306-
# Also output current blob summary
307-
blob_info = []
308-
for blob in new_data.get('blobs', []):
309-
info = f"- **{blob.get('path', 'Unknown')}**\n"
310-
info += f" - Version: {blob.get('version', 'Unknown')}\n"
311-
info += f" - SHA256: {blob.get('sha256', 'Unknown')[:16]}...\n"
312-
info += f" - Type: {blob.get('type', 'Unknown')}\n"
313-
info += f" - Description: {blob.get('description', 'No description')}\n"
314-
blob_info.append(info)
315-
316-
blob_content = ["## Current Firmware Blobs:"] + blob_info
317-
318-
# Write to file for GitHub Actions output
319-
print(f"DEBUG: Writing {len(blob_content)} lines to blob_summary.txt", file=sys.stderr)
320-
with open('blob_summary.txt', 'w') as f:
321-
f.write('\n'.join(blob_content))
322-
323-
print(f"DEBUG: Successfully wrote blob_summary.txt", file=sys.stderr)
324-
325-
print("blob_summary<<EOF", file=sys.stdout)
326-
print('\n'.join(blob_content), file=sys.stdout)
327-
print("EOF", file=sys.stdout)
271+
328272
329273
except Exception as e:
330274
print("diff_output<<EOF", file=sys.stdout)
331275
print(f"Error generating comparison: {e}", file=sys.stdout)
332276
print("EOF", file=sys.stdout)
333-
print("blob_summary<<EOF", file=sys.stdout)
334-
print(f"Error parsing module.yml: {e}", file=sys.stdout)
335-
print("EOF", file=sys.stdout)
336277
print("DEBUG: Python script completed successfully", file=sys.stderr)
337278
EOF
338279
@@ -354,42 +295,30 @@ jobs:
354295
echo "EOF" >> $GITHUB_OUTPUT
355296
fi
356297
357-
if [ -f blob_summary.txt ]; then
358-
echo "DEBUG: blob_summary.txt exists, size: $(wc -c < blob_summary.txt)" >&2
359-
echo "blob_summary<<EOF" >> $GITHUB_OUTPUT
360-
cat blob_summary.txt >> $GITHUB_OUTPUT
361-
echo "EOF" >> $GITHUB_OUTPUT
362-
else
363-
echo "DEBUG: blob_summary.txt not found" >&2
364-
echo "blob_summary<<EOF" >> $GITHUB_OUTPUT
365-
echo "No blob summary available" >> $GITHUB_OUTPUT
366-
echo "EOF" >> $GITHUB_OUTPUT
367-
fi
298+
368299
369300
- name: Create or update comment
370301
uses: actions/github-script@v7
371302
with:
372303
github-token: ${{ secrets.GITHUB_TOKEN }}
373304
script: |
374-
const { data: comments } = await github.rest.issues.listComments({
375-
owner: context.repo.owner,
376-
repo: context.repo.repo,
377-
issue_number: context.issue.number
378-
});
379-
380-
const existingComment = comments.find(comment =>
381-
comment.body.includes('Module Monitor')
382-
);
383-
384305
console.log('DEBUG: diff_output length:', process.env.diff_output ? process.env.diff_output.length : 0);
385-
console.log('DEBUG: blob_summary length:', process.env.blob_summary ? process.env.blob_summary.length : 0);
386306
387-
const commentBody = 'Module Monitor\n\nChanges detected in module.yml\n\n' +
307+
const commentBody = '## Module Monitor\n\nChanges detected in module.yml\n\n' +
388308
(process.env.diff_output || 'No changes detected') + '\n\n' +
389-
(process.env.blob_summary || '') + '\n\n' +
390309
'This comment was automatically generated.';
391310
392311
try {
312+
const { data: comments } = await github.rest.issues.listComments({
313+
owner: context.repo.owner,
314+
repo: context.repo.repo,
315+
issue_number: context.issue.number
316+
});
317+
318+
const existingComment = comments.find(comment =>
319+
comment.body.includes('Module Monitor')
320+
);
321+
393322
if (existingComment) {
394323
await github.rest.issues.updateComment({
395324
owner: context.repo.owner,
@@ -408,17 +337,18 @@ jobs:
408337
console.log('Successfully created new comment');
409338
}
410339
} catch (error) {
411-
console.log('Could not create/update comment due to permissions. This is normal for forks.');
340+
console.log('Could not create/update comment due to permissions.');
412341
console.log('Error:', error.message);
413342
console.log('Comment body that would have been posted:');
343+
console.log('---');
414344
console.log(commentBody);
345+
console.log('---');
415346
416347
// Don't fail the workflow - the PR detection worked correctly
417348
console.log('Workflow completed successfully - PR detection and diff generation worked correctly.');
418349
}
419350
env:
420351
diff_output: ${{ steps.set-output.outputs.diff_output }}
421-
blob_summary: ${{ steps.set-output.outputs.blob_summary }}
422352

423353

424354

@@ -430,5 +360,3 @@ jobs:
430360
echo '```diff' >> $GITHUB_STEP_SUMMARY
431361
echo "${{ steps.set-output.outputs.diff_output }}" >> $GITHUB_STEP_SUMMARY
432362
echo '```' >> $GITHUB_STEP_SUMMARY
433-
echo "" >> $GITHUB_STEP_SUMMARY
434-
echo "${{ steps.set-output.outputs.blob_summary }}" >> $GITHUB_STEP_SUMMARY

0 commit comments

Comments
 (0)