Skip to content

Commit

Permalink
[github, meetbot, url, youtube] 4.0 standards per #276
Browse files Browse the repository at this point in the history
  • Loading branch information
embolalia committed Jun 22, 2013
1 parent 3d0e181 commit 55d0830
Show file tree
Hide file tree
Showing 4 changed files with 185 additions and 183 deletions.
68 changes: 33 additions & 35 deletions willie/modules/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
from urllib2 import HTTPError
import json
import re
import willie.web as web
from willie import web
from willie.module import commands

def checkConfig(willie):
if not willie.config.has_option('github', 'oauth_token') or not willie.config.has_option('github', 'repo'):
def checkConfig(bot):
if not bot.config.has_option('github', 'oauth_token') or not bot.config.has_option('github', 'repo'):
return False
else:
return [willie.config.github.oauth_token, willie.config.github.repo]
return [bot.config.github.oauth_token, bot.config.github.repo]


def configure(config):
"""
Expand All @@ -31,74 +33,70 @@ def configure(config):
config.interactive_add('github', 'repo', 'Github repository', 'embolalia/willie')
return chunk

def issue(willie, trigger):

@commands('makeissue', 'makebug')
def issue(bot, trigger):
"""Create a GitHub issue, also known as a bug report. Syntax: .makeissue Title of the bug report"""
#check input
if not trigger.group(2):
return willie.say('Please title the issue')
return bot.say('Please title the issue')

#Is the Oauth token and repo available?
gitAPI = checkConfig(willie)
gitAPI = checkConfig(bot)
if gitAPI == False:
return willie.say('Git module not configured, make sure github.oauth_token and github.repo are defined')
return bot.say('Git module not configured, make sure github.oauth_token and github.repo are defined')

#parse input
now = ' '.join(str(datetime.utcnow()).split(' ')).split('.')[0]+' UTC'
now = ' '.join(str(datetime.utcnow()).split(' ')).split('.')[0] + ' UTC'
body = 'Submitted by: %s\nFrom channel: %s\nAt %s' % (trigger.nick, trigger.sender, now)
data = {"title":trigger.group(2).encode('utf-8'), "body":body, "labels": ["IRC"]}
data = {"title": trigger.group(2).encode('utf-8'), "body": body, "labels": ["IRC"]}
#submit
try:
raw = web.post('https://api.github.com/repos/'+gitAPI[1]+'/issues?access_token='+gitAPI[0], json.dumps(data))
raw = web.post('https://api.github.com/repos/' + gitAPI[1] + '/issues?access_token=' + gitAPI[0], json.dumps(data))
except HTTPError:
return willie.say('The GitHub API returned an error.')
return bot.say('The GitHub API returned an error.')

data = json.loads(raw)
willie.say('Issue #%s posted. %s' % (data['number'], data['html_url']))
willie.debug('GitHub','Issue #%s created in %s' % (data['number'],trigger.sender),'warning')
issue.commands = ['makeissue','makebug']
issue.priority = 'medium'
bot.say('Issue #%s posted. %s' % (data['number'], data['html_url']))
bot.debug('GitHub', 'Issue #%s created in %s' % (data['number'], trigger.sender), 'warning')

def findIssue(willie, trigger):

@commands('findissue', 'findbug')
def findIssue(bot, trigger):
"""Search for a GitHub issue by keyword or ID. usage: .findissue search keywords/ID (optional) You can specify the first keyword as "CLOSED" to search closed issues."""
if not trigger.group(2):
return willie.reply('What are you searching for?')
return bot.reply('What are you searching for?')

#Is the Oauth token and repo available?
gitAPI = checkConfig(willie)
gitAPI = checkConfig(bot)
if gitAPI == False:
return willie.say('Git module not configured, make sure github.oauth_token and github.repo are defined')
return bot.say('Git module not configured, make sure github.oauth_token and github.repo are defined')
firstParam = trigger.group(2).split(' ')[0]
if firstParam.isdigit():
URL = 'https://api.github.com/repos/%s/issues/%s' % (gitAPI[1], trigger.group(2))
elif firstParam == 'CLOSED':
if '%20'.join(trigger.group(2).split(' ')[1:]) not in ('','\x02','\x03'):
URL = 'https://api.github.com/legacy/issues/search/'+gitAPI[1]+'/closed/'+'%20'.join(trigger.group(2).split(' ')[1:])
if '%20'.join(trigger.group(2).split(' ')[1:]) not in ('', '\x02', '\x03'):
URL = 'https://api.github.com/legacy/issues/search/' + gitAPI[1] + '/closed/' + '%20'.join(trigger.group(2).split(' ')[1:])
else:
return willie.reply('What are you searching for?')
return bot.reply('What are you searching for?')
else:
URL = 'https://api.github.com/legacy/issues/search/%s/open/%s' % (gitAPI[1], trigger.group(2))

try:
raw = web.get(URL)
except HTTPError:
return willie.say('The GitHub API returned an error.')
return bot.say('The GitHub API returned an error.')

try:
if firstParam.isdigit():
data = json.loads(raw)
else:
data = json.loads(raw)['issues'][-1]
except (KeyError, IndexError):
return willie.say('No search results.')
return bot.say('No search results.')
if len(data['body'].split('\n')) > 1:
body = data['body'].split('\n')[0]+'...'
body = data['body'].split('\n')[0] + '...'
else:
body = data['body'].split('\n')[0]
willie.reply('[#%s]\x02title:\x02 %s \x02|\x02 %s' % (data['number'],data['title'],body))
willie.say(data['html_url'])
findIssue.commands = ['findissue','findbug']
findIssue.priority = 'medium'

if __name__ == '__main__':
print __doc__.strip()

bot.reply('[#%s]\x02title:\x02 %s \x02|\x02 %s' % (data['number'], data['title'], body))
bot.say(data['html_url'])
Loading

0 comments on commit 55d0830

Please sign in to comment.