Skip to content

Instantly share code, notes, and snippets.

@adriansr
Created December 10, 2018 11:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adriansr/b6f5205d2cceb538f50065097f04cb41 to your computer and use it in GitHub Desktop.
Save adriansr/b6f5205d2cceb538f50065097f04cb41 to your computer and use it in GitHub Desktop.
Delete all Pull Request comments from HoundCI user
import json
import requests
REPO='user/repo'
PULL= # PULL_REQUEST_ID (1234)
USER_TO_DELETE='houndci-bot'
TOKEN=YOUR_GITHUB_API_TOKEN
headers = { 'Authorization': 'token ' + TOKEN }
BASE='https://api.github.com/repos/{0}/pulls'.format(REPO)
n = 1
while True:
comments = json.loads(requests.get(BASE + '/' + str(PULL) + '/comments', headers=headers).content)
to_delete = map(lambda x: x['_links']['self']['href'], filter(lambda c: c['user']['login'] == USER_TO_DELETE, comments))
print 'Read',len(to_delete),'comments'
if len(to_delete) == 0:
break
for comment_url in to_delete:
print 'Deleting comment', n
n+=1
requests.delete(comment_url, headers=headers)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment