def create_issue(self, project): try: r = self.browser.get_project(project) except BrowserHTTPNotFound: return None issue = Issue(0) issue.project = self._build_project(r) issue.fields = self.browser.get_custom_fields(project) return issue
def create_issue(self, project): try: with self.browser: r = self.browser.query_issues(project) except BrowserHTTPNotFound: return None issue = Issue(0) issue.project = self._build_project(r['project']) return issue
def get_issue(self, issue): if isinstance(issue, Issue): id = issue.id else: id = issue issue = Issue(issue) try: params = self.browser.get_issue(id) except BrowserHTTPNotFound: return None issue.project = self._build_project(params['project']) issue.title = params['subject'] issue.body = params['body'] issue.creation = params['created_on'] issue.updated = params['updated_on'] issue.start = params['start_date'] issue.due = params['due_date'] issue.fields = {} for key, value in params['fields'].items(): issue.fields[key] = value issue.attachments = [] for a in params['attachments']: attachment = Attachment(a['id']) attachment.filename = a['filename'] attachment.url = a['url'] issue.attachments.append(attachment) issue.history = [] for u in params['updates']: update = Update(u['id']) update.author = issue.project.find_user(*u['author']) update.date = u['date'] update.message = u['message'] update.changes = [] for i, (field, last, new) in enumerate(u['changes']): change = Change(i) change.field = field change.last = last change.new = new update.changes.append(change) issue.history.append(update) issue.author = issue.project.find_user(*params['author']) issue.assignee = issue.project.find_user(*params['assignee']) issue.tracker = params['tracker'][1] issue.category = params['category'][1] issue.version = issue.project.find_version(*params['version']) issue.status = issue.project.find_status(params['status'][1]) issue.priority = params['priority'][1] return issue
def iter_issues(self, query): """ Iter issues with optionnal patterns. @param query [Query] @return [iter(Issue)] issues """ params = self.browser.get_project(query.project) kwargs = { 'subject': query.title, 'author_id': self._attr_to_id(params['members'], query.author), 'assigned_to_id': self._attr_to_id(params['members'], query.assignee), 'fixed_version_id': self._attr_to_id(params['versions'], query.version), 'category_id': self._attr_to_id(params['categories'], query.category), 'status_id': self._attr_to_id(params['statuses'], query.status), } r = self.browser.query_issues(query.project, **kwargs) project = self._build_project(r['project']) for issue in r['iter']: obj = Issue(issue['id']) obj.project = project obj.title = issue['subject'] obj.creation = issue['created_on'] obj.updated = issue['updated_on'] obj.start = issue['start_date'] obj.due = issue['due_date'] if isinstance(issue['author'], tuple): obj.author = project.find_user(*issue['author']) else: obj.author = User(0, issue['author']) if isinstance(issue['assigned_to'], tuple): obj.assignee = project.find_user(*issue['assigned_to']) else: obj.assignee = issue['assigned_to'] obj.tracker = issue['tracker'] obj.category = issue['category'] if issue['fixed_version'] is not None: obj.version = project.find_version(*issue['fixed_version']) else: obj.version = None obj.status = project.find_status(issue['status']) obj.priority = issue['priority'] yield obj
def iter_issues(self, query): """ Iter issues with optionnal patterns. @param query [Query] @return [iter(Issue)] issues """ # TODO link between text and IDs. kwargs = { 'subject': query.title, 'author_id': query.author, 'assigned_to_id': query.assignee, 'fixed_version_id': query.version, 'category_id': query.category, 'status_id': query.status, } r = self.browser.query_issues(query.project, **kwargs) project = self._build_project(r['project']) for issue in r['iter']: obj = Issue(issue['id']) obj.project = project obj.title = issue['subject'] obj.creation = issue['created_on'] obj.updated = issue['updated_on'] if isinstance(issue['author'], tuple): obj.author = project.find_user(*issue['author']) else: obj.author = User(0, issue['author']) if isinstance(issue['assigned_to'], tuple): obj.assignee = project.find_user(*issue['assigned_to']) else: obj.assignee = issue['assigned_to'] obj.category = issue['category'] if issue['fixed_version'] is not None: obj.version = project.find_version(*issue['fixed_version']) else: obj.version = None obj.status = project.find_status(issue['status']) yield obj
def get_issue(self, issue): if isinstance(issue, Issue): id = issue.id else: id = issue issue = Issue(issue) try: with self.browser: params = self.browser.get_issue(id) except BrowserHTTPNotFound: return None issue.project = self._build_project(params['project']) issue.title = params['subject'] issue.body = params['body'] issue.creation = params['created_on'] issue.updated = params['updated_on'] issue.start = params['start_date'] issue.due = params['due_date'] issue.fields = {} for key, value in params['fields'].iteritems(): issue.fields[key] = value issue.attachments = [] for a in params['attachments']: attachment = Attachment(a['id']) attachment.filename = a['filename'] attachment.url = a['url'] issue.attachments.append(attachment) issue.history = [] for u in params['updates']: update = Update(u['id']) update.author = issue.project.find_user(*u['author']) update.date = u['date'] update.message = u['message'] update.changes = [] for i, (field, last, new) in enumerate(u['changes']): change = Change(i) change.field = field change.last = last change.new = new update.changes.append(change) issue.history.append(update) issue.author = issue.project.find_user(*params['author']) issue.assignee = issue.project.find_user(*params['assignee']) issue.tracker = params['tracker'][1] issue.category = params['category'][1] issue.version = issue.project.find_version(*params['version']) issue.status = issue.project.find_status(params['status'][1]) issue.priority = params['priority'][1] return issue
def _make_issue(self, data): if data['name'].endswith(':'): # section, not task return None i = Issue(str(data['gid'])) i.url = 'https://app.asana.com/0/0/%s/f' % i.id i.title = data['name'] if 'notes' in data: i.body = data['notes'] if data.get('assignee'): i.assignee = self._make_user(data['assignee']) if data.get('created_by'): # created_by is not documented i.author = self._make_user(data['created_by']) if 'created_at' in data: i.creation = parse_date(data['created_at']) if 'modified_at' in data: i.updated = parse_date(data['modified_at']) if 'due_at' in data: if data['due_at']: i.due = parse_date(data['due_at']) else: i.due = NotAvailable if 'due_on' in data: if data['due_on']: i.due = parse_date(data['due_on']) else: i.due = NotAvailable if data.get('projects'): i.project = self._make_project(data['projects'][0]) if 'completed' in data: i.status = self.STATUS_CLOSED if data[ 'completed'] else self.STATUS_OPEN if 'custom_fields' in data: def get(d): for k in ('string_value', 'number_value', 'enum_value', 'text_value'): if k in d: return d[k] assert False, 'custom type not handled' i.fields = {d['name']: get(d) for d in data['custom_fields']} if 'tags' in data: i.tags = [d['name'] for d in data['tags']] if data.get('memberships') and data['memberships'][0]['section']: i.category = data['memberships'][0]['section']['name'] i.version = NotAvailable i.priority = NotAvailable return i
def _make_issue(self, data): if data['name'].endswith(':'): # section, not task return None i = Issue(str(data['id'])) i.url = 'https://app.asana.com/0/0/%s/f' % i.id i.title = data['name'] if 'notes' in data: i.body = data['notes'] if data.get('assignee'): i.assignee = self._make_user(data['assignee']) if data.get('created_by'): # created_by is not documented i.author = self._make_user(data['created_by']) if 'created_at' in data: i.creation = parse_date(data['created_at']) if 'modified_at' in data: i.updated = parse_date(data['modified_at']) if 'due_at' in data: if data['due_at']: i.due = parse_date(data['due_at']) else: i.due = NotAvailable if 'due_on' in data: if data['due_on']: i.due = parse_date(data['due_on']) else: i.due = NotAvailable if data.get('projects'): i.project = self._make_project(data['projects'][0]) if 'completed' in data: i.status = self.STATUS_CLOSED if data['completed'] else self.STATUS_OPEN if 'custom_fields' in data: def get(d): for k in ('string_value', 'number_value', 'enum_value', 'text_value'): if k in d: return d[k] assert False, 'custom type not handled' i.fields = {d['name']: get(d) for d in data['custom_fields']} if 'tags' in data: i.tags = [d['name'] for d in data['tags']] if data.get('memberships') and data['memberships'][0]['section']: i.category = data['memberships'][0]['section']['name'] i.version = NotAvailable i.priority = NotAvailable return i
def create_issue(self, project_id): issue = Issue(0) issue.project = self.get_project(project_id) return issue
def _make_issue(self, d, project): _id = self._build_issue_id(project.id, d['number']) issue = Issue(_id) issue.url = d['url'] issue.project = project issue.title = d['title'] issue.body = d['body'] issue.creation = d['creation'] issue.updated = d['updated'] issue.author = project.find_user(d['author'], None) if not issue.author: # may duplicate users issue.author = User(d['author'], d['author']) issue.status = STATUSES[d['status']] if d['assignee']: issue.assignee = project.find_user(d['assignee'], None) else: issue.assignee = None if d['version']: issue.version = project.find_version(d['version'], None) else: issue.version = None issue.category = None issue.attachments = [ self._make_attachment(dattach) for dattach in d['attachments'] ] return issue
def iter_issues(self, query): """ Iter issues with optionnal patterns. @param query [Query] @return [iter(Issue)] issues """ # TODO link between text and IDs. kwargs = {'subject': query.title, 'author_id': query.author, 'assigned_to_id': query.assignee, 'fixed_version_id': query.version, 'category_id': query.category, 'status_id': query.status, } r = self.browser.query_issues(query.project, **kwargs) project = self._build_project(r['project']) for issue in r['iter']: obj = Issue(issue['id']) obj.project = project obj.title = issue['subject'] obj.creation = issue['created_on'] obj.updated = issue['updated_on'] if isinstance(issue['author'], tuple): obj.author = project.find_user(*issue['author']) else: obj.author = User(0, issue['author']) if isinstance(issue['assigned_to'], tuple): obj.assignee = project.find_user(*issue['assigned_to']) else: obj.assignee = issue['assigned_to'] obj.category = issue['category'] if issue['fixed_version'] is not None: obj.version = project.find_version(*issue['fixed_version']) else: obj.version = None obj.status = project.find_status(issue['status']) yield obj
def create_issue(self, project): issue = Issue(0) issue._project = project return issue
def _make_issue(self, d, project): _id = self._build_issue_id(project.id, d['number']) issue = Issue(_id) issue.url = d['url'] issue.project = project issue.title = d['title'] issue.body = d['body'] issue.creation = d['creation'] issue.updated = d['updated'] issue.author = project.find_user(d['author'], None) if not issue.author: # may duplicate users issue.author = User(d['author'], d['author']) issue.status = STATUSES[d['status']] if d['assignee']: issue.assignee = project.find_user(d['assignee'], None) else: issue.assignee = None if d['version']: issue.version = project.find_version(d['version'], None) else: issue.version = None issue.category = None issue.attachments = [self._make_attachment(dattach) for dattach in d['attachments']] return issue
def iter_issues(self, query): """ Iter issues with optionnal patterns. @param query [Query] @return [iter(Issue)] issues """ params = self.browser.get_project(query.project) kwargs = {'subject': query.title, 'author_id': self._attr_to_id(params['members'], query.author), 'assigned_to_id': self._attr_to_id(params['members'], query.assignee), 'fixed_version_id': self._attr_to_id(params['versions'], query.version), 'category_id': self._attr_to_id(params['categories'], query.category), 'status_id': self._attr_to_id(params['statuses'], query.status), } r = self.browser.query_issues(query.project, **kwargs) project = self._build_project(r['project']) for issue in r['iter']: obj = Issue(issue['id']) obj.project = project obj.title = issue['subject'] obj.creation = issue['created_on'] obj.updated = issue['updated_on'] obj.start = issue['start_date'] obj.due = issue['due_date'] if isinstance(issue['author'], tuple): obj.author = project.find_user(*issue['author']) else: obj.author = User(0, issue['author']) if isinstance(issue['assigned_to'], tuple): obj.assignee = project.find_user(*issue['assigned_to']) else: obj.assignee = issue['assigned_to'] obj.tracker = issue['tracker'] obj.category = issue['category'] if issue['fixed_version'] is not None: obj.version = project.find_version(*issue['fixed_version']) else: obj.version = None obj.status = project.find_status(issue['status']) obj.priority = issue['priority'] yield obj