Skip to content

Instantly share code, notes, and snippets.

@ferminhg
Created December 11, 2020 09:42
Show Gist options
  • Save ferminhg/ab7b552c0d4a0f7936c5d7823b729367 to your computer and use it in GitHub Desktop.
Save ferminhg/ab7b552c0d4a0f7936c5d7823b729367 to your computer and use it in GitHub Desktop.
Get PR comments
# create env
# python3.8 -mvenv venv
# activate
# . venv/bin/activate
# install lib https://github.com/PyGithub/PyGithub
# pip3 install PyGithub
# run
# python get-pr-comments.py > comments.json
from github import Github
import json
g = Github("access_token")
repo = g.get_repo("project") # project or org/project
pr = repo.get_pull(52) #id_of_pr
comments = pr.get_comments()
list_of_comments = []
for comment in comments:
list_of_comments.append({
'id': comment.id,
'url': comment.url,
'user': comment.user.login,
'path': comment.path,
'created_at': comment.updated_at.strftime("%Y/%m/%d, %H:%M:%S"),
'original_position': comment.original_position,
'body': comment.body,
})
print(json.dumps(list_of_comments))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment