Skip to content

Commit

Permalink
Handle cases where user tasks data isnt returned
Browse files Browse the repository at this point in the history
  • Loading branch information
kostajh committed Jan 23, 2013
1 parent d117667 commit 18494dc
Showing 1 changed file with 43 additions and 47 deletions.
90 changes: 43 additions & 47 deletions bugwarrior/services/activecollab2.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,13 @@
from bugwarrior.services import IssueService
from bugwarrior.config import die
from bugwarrior.db import MARKUP
from HTMLParser import HTMLParser

import urllib2
import time
import json
import datetime


class MLStripper(HTMLParser):
def __init__(self):
self.reset()
self.fed = []

def handle_data(self, d):
self.fed.append(d)

def get_data(self):
return ''.join(self.fed)
api_count = 0


class Client(object):
Expand All @@ -44,43 +33,48 @@ def find_issues(self, user_id=None, project_id=None, project_name=None):

assigned_tasks = []

for key, task in enumerate(user_tasks_data):
assigned_task = dict()
if task[u'type'] == 'Ticket':
# Load Ticket data
ticket_data = self.call_api("/projects/" + str(task[u'project_id']) + "/tickets/" + str(task[u'ticket_id']))
assignees = ticket_data[u'assignees']

for k, v in enumerate(assignees):
if (v[u'is_owner'] is True) and (v[u'user_id'] == int(self.user_id)):
assigned_task['permalink'] = ticket_data[u'permalink']
assigned_task['ticket_id'] = ticket_data[u'ticket_id']
assigned_task['project_id'] = ticket_data[u'project_id']
assigned_task['project'] = project_name
assigned_task['description'] = ticket_data[u'name']
assigned_task['type'] = "ticket"
assigned_task['created_on'] = ticket_data[u'created_on']
assigned_task['created_by_id'] = ticket_data[u'created_by_id']

elif task[u'type'] == 'Task':
# Load Task data
assigned_task['permalink'] = task[u'permalink']
assigned_task['project'] = project_name
assigned_task['description'] = task[u'body']
assigned_task['project_id'] = task[u'project_id']
assigned_task['ticket_id'] = ""
assigned_task['type'] = "task"
assigned_task['created_on'] = task[u'created_on']
assigned_task['created_by_id'] = task[u'created_by_id']

if assigned_task:
log.debug("Adding '" + assigned_task['description'] + "' to issue list")
assigned_tasks.append(assigned_task)

log.debug(" Found {0} total.", len(assigned_tasks))
try:
for key, task in enumerate(user_tasks_data):
assigned_task = dict()
if task[u'type'] == 'Ticket':
# Load Ticket data
# @todo Implement threading here.
ticket_data = self.call_api("/projects/" + str(task[u'project_id']) + "/tickets/" + str(task[u'ticket_id']))
assignees = ticket_data[u'assignees']

for k, v in enumerate(assignees):
if (v[u'is_owner'] is True) and (v[u'user_id'] == int(self.user_id)):
assigned_task['permalink'] = ticket_data[u'permalink']
assigned_task['ticket_id'] = ticket_data[u'ticket_id']
assigned_task['project_id'] = ticket_data[u'project_id']
assigned_task['project'] = project_name
assigned_task['description'] = ticket_data[u'name']
assigned_task['type'] = "ticket"
assigned_task['created_on'] = ticket_data[u'created_on']
assigned_task['created_by_id'] = ticket_data[u'created_by_id']

elif task[u'type'] == 'Task':
# Load Task data
assigned_task['permalink'] = task[u'permalink']
assigned_task['project'] = project_name
assigned_task['description'] = task[u'body']
assigned_task['project_id'] = task[u'project_id']
assigned_task['ticket_id'] = ""
assigned_task['type'] = "task"
assigned_task['created_on'] = task[u'created_on']
assigned_task['created_by_id'] = task[u'created_by_id']

if assigned_task:
log.debug("Adding '" + assigned_task['description'] + "' to issue list")
assigned_tasks.append(assigned_task)
except:
log.debug('Could not parse user tasks data')

return assigned_tasks

def call_api(self, uri, get=None):
global api_count
api_count += 1
url = self.url.rstrip("/") + "?token=" + self.key + "&path_info=" + uri + "&format=json"
req = urllib2.Request(url)
res = urllib2.urlopen(req)
Expand Down Expand Up @@ -155,13 +149,15 @@ def issues(self):
start = time.time()
issues = []
projects = self.projects
# @todo Implement threading here.
for project in projects:
for project_id, project_name in project.iteritems():
log.debug("Getting tasks for #" + project_id + " " + project_name + '"')
issues += self.client.find_issues(self.user_id, project_id, project_name)

log.debug(" Found {0} total.", len(issues))

global api_count
log.debug(" {0} api calls", api_count)
log.debug("Elapsed Time: %s" % (time.time() - start))

return [dict(
Expand Down

0 comments on commit 18494dc

Please sign in to comment.