From 8dab6140ee3aa45d5fc3c314de38d8d0ec28100f Mon Sep 17 00:00:00 2001 From: derAnfaenger Date: Thu, 2 Nov 2017 15:00:55 +0100 Subject: [PATCH] zulip_bots: Remove git_hub_comment bot. This bot has no tests and a command set that is impractical and confusing to use. It offers no practical benefit. --- .../bots/git_hub_comment/__init__.py | 0 .../zulip_bots/bots/git_hub_comment/doc.md | 51 ------- .../bots/git_hub_comment/git_hub_comment.py | 126 ------------------ 3 files changed, 177 deletions(-) delete mode 100644 zulip_bots/zulip_bots/bots/git_hub_comment/__init__.py delete mode 100644 zulip_bots/zulip_bots/bots/git_hub_comment/doc.md delete mode 100644 zulip_bots/zulip_bots/bots/git_hub_comment/git_hub_comment.py diff --git a/zulip_bots/zulip_bots/bots/git_hub_comment/__init__.py b/zulip_bots/zulip_bots/bots/git_hub_comment/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/zulip_bots/zulip_bots/bots/git_hub_comment/doc.md b/zulip_bots/zulip_bots/bots/git_hub_comment/doc.md deleted file mode 100644 index 8c21fe1..0000000 --- a/zulip_bots/zulip_bots/bots/git_hub_comment/doc.md +++ /dev/null @@ -1,51 +0,0 @@ -# Overview - -This is the documentation for how to set up and run the GitHub comment bot. (`git_hub_comment.py`) - -This directory contains library code for running Zulip -bots that react to messages sent by users. - -This bot will allow you to comment on a GitHub issue. -You should preface messages with `@comment` or `@gcomment`. -You will need to have a GitHub account, and a GitHub OAuth token. - -## Setup -Before running this bot, make sure to get a GitHub OAuth token. -You can look at this tutorial if you need help: - -The token will need to be authorized for the following scopes: `gist, public_repo, user`. -Store it in the `~/github-auth.conf` file, along with your username, in the format: -github_repo = (The name of the repo to post to) -github_repo_owner = (The owner of the repo to post to) -github_username = (The username of the GitHub bot) -github_token = (The personal access token for the GitHub bot) -`/// - site=https://zulip.somewhere.com diff --git a/zulip_bots/zulip_bots/bots/git_hub_comment/git_hub_comment.py b/zulip_bots/zulip_bots/bots/git_hub_comment/git_hub_comment.py deleted file mode 100644 index 06f16c9..0000000 --- a/zulip_bots/zulip_bots/bots/git_hub_comment/git_hub_comment.py +++ /dev/null @@ -1,126 +0,0 @@ -# See readme.md for instructions on running this code. -from __future__ import absolute_import -from __future__ import print_function -from . import github -import json -import logging -import os -import requests - - -class InputError(IndexError): - '''raise this when there is an error with the information the user has entered''' - - -class GitHubHandler(object): - ''' - This plugin allows you to comment on a GitHub issue, under a certain repository. - It looks for messages starting with '@mention-bot'. - ''' - - def usage(self): - return ''' - This bot will allow users to comment on a GitHub issue. - Users should preface messages with '@mention-bot'. - You will need to have a GitHub account. - - Before running this, make sure to get a GitHub OAuth token. - The token will need to be authorized for the following scopes: - 'gist, public_repo, user'. - Store it in the '~/.github_auth.conf' file, along with your username, in the format: - github_repo = (The name of the repo to post to) - github_repo_owner = (The owner of the repo to post to) - github_username = (The username of the GitHub bot) - github_token = (The personal access token for the GitHub bot) - - Leave the first two options blank. - - Please use this format in your message to the bot: - '///'. - ''' - - def handle_message(self, message, bot_handler): - original_content = message['content'] - original_sender = message['sender_email'] - - handle_input(bot_handler, original_content, original_sender) - -handler_class = GitHubHandler - - -def send_to_github(repo_owner, repo, issue, comment_body): - session = github.auth() - comment = { - 'body': comment_body - } - r = session.post('https://api.github.com/repos/%s/%s/issues/%s/comments' % (repo_owner, repo, issue), - json.dumps(comment)) - - return r.status_code - - -def get_values_message(original_content): - # gets rid of whitespace around the edges, so that they aren't a problem in the future - message_content = original_content.strip() - # splits message by '/' which will work if the information was entered correctly - message_content = message_content.split('/') - try: - # this will work if the information was entered correctly - user = github.get_username() - repo_owner = message_content[2] - repo = message_content[3] - issue = message_content[4] - comment_body = message_content[5] - - return dict(user=user, repo_owner=repo_owner, repo=repo, issue=issue, comment_body=comment_body) - except IndexError: - raise InputError - - -def handle_input(bot_handler, original_content, original_sender): - try: - params = get_values_message(original_content) - - status_code = send_to_github(params['repo_owner'], params['repo'], - params['issue'], params['comment_body']) - - if status_code == 201: - # sending info to github was successful! - reply_message = "You commented on issue number " + params['issue'] + " under " + \ - params['repo_owner'] + "'s repository " + params['repo'] + "!" - - send_message(bot_handler, reply_message, original_sender) - - elif status_code == 404: - # this error could be from an error with the OAuth token - reply_message = "Error code: " + str(status_code) + " :( There was a problem commenting on issue number " \ - + params['issue'] + " under " + \ - params['repo_owner'] + "'s repository " + params['repo'] + \ - ". Do you have the right OAuth token?" - - send_message(bot_handler, reply_message, original_sender) - - else: - # sending info to github did not work - reply_message = "Error code: " + str(status_code) +\ - " :( There was a problem commenting on issue number " \ - + params['issue'] + " under " + \ - params['repo_owner'] + "'s repository " + params['repo'] + \ - ". Did you enter the information in the correct format?" - - send_message(bot_handler, reply_message, original_sender) - except InputError: - message = "It doesn't look like the information was entered in the correct format." \ - " Did you input it like this? " \ - "'/////'." - send_message(bot_handler, message, original_sender) - logging.error('there was an error with the information you entered') - - -def send_message(bot_handler, message, original_sender): - # function for sending a message - bot_handler.send_message(dict( - type='private', - to=original_sender, - content=message, - ))