def get_cr_comments(space_id, change_request_id, api_token):
"""Get all comments for a change request."""
response = requests.get(
f"https://api.gitbook.com/v1/spaces/{space_id}/change-requests/{change_request_id}/comments",
headers={
"Authorization": f"Bearer {api_token}",
"Accept": "*/*"
},
)
response.raise_for_status()
return response.json()
# Get comments for all recent change requests
all_comments = []
for cr_id in recent_crs['id']:
try:
comments_data = get_cr_comments(SPACE_ID, cr_id, API_TOKEN)
print(comments_data)
for comment in comments_data.get('items', []):
comment_id = comment.get('id') or ''
commenter_name = comment.get('postedBy').get('displayName') or ''
commenter_email = comment.get('postedBy').get('email') or '',
posted_at = comment.get('postedAt') or ''
body = comment.get('body') or ''
all_comments.append({
'cr_id': cr_id,
'comment_id': comment_id,
'commenter_name': commenter_name,
'posted_at': posted_at,
'commenter_email': commenter_email,
'body': body
})
except Exception as e:
print(f"Warning: Could not get comments for CR {cr_id}")
# Analyze comment activity
if all_comments:
comments_df = pd.DataFrame(all_comments)
print(f"\nFound {len(all_comments)} comments")
print("\nMost active commenters:")
print(comments_df['commenter_name'].value_counts().head(10))
# Find change requests with most discussion
cr_comment_counts = comments_df.groupby('cr_id').size().sort_values(ascending=False)
print(f"\nAverage comments per change request: {len(comments_df) / len(recent_crs):.1f}")