def test_shorten_url(self): url = ( 'https://github.com/plone/plone.app.registry/pull/402#issuecomment-29038192' ) self.assertEqual( shorten_comment_url(url), 'plone/plone.app.registry#402-29038192' )
def handle_comment(request): """Handle comments on issues/pull requests events. Do some verification and issue internal events that will do they own thing. """ # bail out early if it's just a github check ?? see pull requests payload = json.loads(request.POST['payload']) if 'action' not in payload: return 'No action' # handle github pings if 'comment' not in payload: return 'Comment is missing in payload. No action.' if 'issue' not in payload or 'pull_request' not in payload['issue']: return 'The comment is not from a pull request. No action.' action = payload['action'] comment_payload = payload['comment'] comment_short_url = shorten_comment_url(comment_payload['html_url']) comment_user_id = comment_payload['user']['login'] github_users = request.registry.settings['github_users'] if comment_user_id in github_users: logger.info( f'COMMENT {comment_short_url}: IGNORED as it is from {comment_user_id}' ) return f'Comment on PR {comment_short_url} ignored as is from {comment_user_id}. No action.' pull_request_payload = payload['issue']['pull_request'] pull_request_short_url = shorten_pull_request_url(pull_request_payload['html_url']) logger.info( u'COMMENT {0}: with action {1} on pull request {2}'.format( comment_short_url, action, pull_request_short_url ) ) if action == 'created': request.registry.notify( CommentOnPullRequest(comment_payload, pull_request_payload, request) ) msg = 'Thanks! Handlers already took care of this comment' return json.dumps({'message': msg})
def handle_comment(request): """Handle comments on issues/pull requests events. Do some verification and issue internal events that will do they own thing. """ # bail out early if it's just a github check ?? see pull requests payload = json.loads(request.POST['payload']) if 'action' not in payload: return 'No action' # handle github pings if 'comment' not in payload: return 'Comment is missing in payload. No action.' if 'issue' not in payload or 'pull_request' not in payload['issue']: return 'The comment is not from a pull request. No action.' action = payload['action'] comment_payload = payload['comment'] comment_short_url = shorten_comment_url(comment_payload['html_url']) comment_user_id = comment_payload['user']['login'] github_users = request.registry.settings['github_users'] if comment_user_id in github_users: logger.info( f'COMMENT {comment_short_url}: IGNORED as it is from {comment_user_id}' ) return f'Comment on PR {comment_short_url} ignored as is from {comment_user_id}. No action.' pull_request_payload = payload['issue']['pull_request'] pull_request_short_url = shorten_pull_request_url( pull_request_payload['html_url']) logger.info(u'COMMENT {0}: with action {1} on pull request {2}'.format( comment_short_url, action, pull_request_short_url)) if action == 'created': request.registry.notify( CommentOnPullRequest(comment_payload, pull_request_payload, request)) msg = 'Thanks! Handlers already took care of this comment' return json.dumps({'message': msg})
def test_another_url(self): url = 'https://github.com/plone/plone.app.discussion/pull/147#issuecomment-461373454' self.assertEqual( shorten_comment_url(url), 'plone/plone.app.discussion#147-461373454' )
def test_fallback(self): url = 'https://github.com/plone/random/url' self.assertEqual(shorten_comment_url(url), url)
def short_url(self): return shorten_comment_url(self.event.comment['html_url'])