def sync(self, tracker):
     server = ServerProxy(tracker.config, allow_none=True,
                          use_datetime=datetime)
     last_update = DateTime(time.mktime(tracker.last_update.timetuple()))
     users = self._get_users(server)
     ids = map(int, server.filter('issue', None, {'activity':
                                                  str(last_update)}))
     for issue_id in ids:
         data = server.display('issue%d' % issue_id, 'title', 'creation',
                               'creator', 'assignedto', 'activity',
                               'messages', 'status')
         issue = Issue.by_tracker_id(tracker.id, issue_id)
         issue.no = issue_id
         issue.set_title(data.get('title', ''))
         issue.set_description(self._get_description(
             server, data.get('messages', [])))
         issue.reporter = users[int(data['creator'])]
         issue.owner = users[int(data['assignedto'])]
         issue.last_change = _roundup_date_to_datetime(data.get('activity'))
         status = int(data.get('status', -1))
         issue.active = status in ACTIVE_STATUS
         issue.tracker = tracker
         if not issue.id:
             issue.created = datetime.now()
         issue.updated = datetime.now()
         issue.save()
         post_issue_sync.send(sender=self, issue=issue)
         self._update_user_data(server, data, issue, users)
     tracker.last_update = datetime.now() - timedelta(days=1)
     tracker.save()
     post_tracker_sync.send(sender=self, tracker=tracker)
     return True
Beispiel #2
0
 def sync(self, tracker):
     server = ServerProxy(tracker.config,
                          allow_none=True,
                          use_datetime=datetime)
     last_update = DateTime(time.mktime(tracker.last_update.timetuple()))
     users = self._get_users(server)
     ids = map(int,
               server.filter('issue', None, {'activity': str(last_update)}))
     for issue_id in ids:
         data = server.display('issue%d' % issue_id, 'title', 'creation',
                               'creator', 'assignedto', 'activity',
                               'messages', 'status')
         issue = Issue.by_tracker_id(tracker.id, issue_id)
         issue.no = issue_id
         issue.set_title(data.get('title', ''))
         issue.set_description(
             self._get_description(server, data.get('messages', [])))
         issue.reporter = users[int(data['creator'])]
         issue.owner = users[int(data['assignedto'])]
         issue.last_change = _roundup_date_to_datetime(data.get('activity'))
         status = int(data.get('status', -1))
         issue.active = status in ACTIVE_STATUS
         issue.tracker = tracker
         if not issue.id:
             issue.created = datetime.now()
         issue.updated = datetime.now()
         issue.save()
         post_issue_sync.send(sender=self, issue=issue)
         self._update_user_data(server, data, issue, users)
     tracker.last_update = datetime.now() - timedelta(days=1)
     tracker.save()
     post_tracker_sync.send(sender=self, tracker=tracker)
     return True
Beispiel #3
0
class Github(TrackerPlugin):

    id = 'github'
    name = 'Github issue synchronisation'
    api_url = 'http://github.com/api/v2/json/issues'

    def _make_request(self, url):
        req = urllib2.Request(url)
        fo = urllib2.urlopen(req)
        response = fo.read()
        response = simplejson.loads(response)
        fo.close()
        return response

    def _update_user_data(self, config, data, issue):
        names = [data.get('user')]
        url = '%(base_url)s/comments/%(user)s/%(project)s/%(issue)s' % {
            'base_url': self.api_url,
            'user': config.get('user'),
            'project': config.get('project'),
            'issue': issue.no}
        response = self._make_request(url)
        for comment in response.get('comments', []):
            names.append(comment.get('user'))
        names = list(set(names))
        self.update_user_mapping(issue, names)

    def sync(self, tracker):
        m = CONFIG_PATTERN.match(tracker.config)
        if not m:
            raise StandardError('Invalid configuration information.'
                                ' Please use a format like user@project.')
        config = m.groupdict()
        response = {}
        url = '%(base_url)s/list/%(user)s/%(project)s/%%s' % {
            'base_url': self.api_url,
            'user': config.get('user'),
            'project': config.get('project')}
        try:
            response_closed = self._make_request(url % 'closed')
            response_open = self._make_request(url % 'open')
        except urllib2.HTTPError, e:
            self._log.error(str(e))
            return False
        issues = response_closed.get('issues', [])
        issues.extend(response_open.get('issues'))
        for data in issues:
            tid = data.get('number')
            created = _github_date_to_datetime(data.get('created_at'))
            updated = _github_date_to_datetime(data.get('updated_at'))
            if (created >= tracker.last_update
                or updated >= tracker.last_update):
                issue = Issue.by_tracker_id(tracker.id, tid)
                issue.no = tid
                issue.set_title(data.get('title', ''))
                issue.set_description(data.get('body', ''))
                issue.tracker = tracker
                issue.last_change = updated
                issue.owner = data.get('user')
                issue.reporter = data.get('user')
                if data.get('closed_at', None):
                    issue.active = False
                else:
                    issue.active = True
                if not issue.id:
                    issue.created = datetime.now()
                issue.updated = datetime.now()
                issue.save()
                post_issue_sync.send(sender=self, issue=issue)
                # Currently disabled due to API call limitations
                #self._update_user_data(config, data, issue)
            else:
                continue
        tracker.last_update = datetime.now() - timedelta(days=1)
        tracker.save()
        post_tracker_sync.send(sender=self, tracker=tracker)
        return True
        self._log.info('Last update: %s' % d)
        tids = server.ticket.getRecentChanges(d)
        self._log.info('Issue updates: %s' % `tids`)
        for tid in tids:
            issue = Issue.by_tracker_id(tracker.id, tid)
            id_, cr_date, last_change, data = server.ticket.get(tid)
            #if isinstance(cr_date, int):
                #cr_date = datetime.fromtimestamp(cr_date)
                #last_change = datetime.fromtimestamp(last_change)
            issue.no = id_
            issue.set_title(data.get('summary', ''))
            issue.set_description(data.get('description', ''))
            issue.reporter = data.get('reporter')
            issue.owner = data.get('owner')
            issue.last_change = last_change
            issue.tracker = tracker
            # Only default status values are allowed as Trac allows renaming
            # of status values.
            resolution = data.get('resolution')
            issue.active = resolution in ACTIVE_STATUS
            if not issue.id:
                issue.created = datetime.now()
            issue.updated = datetime.now()
            issue.save()
            post_issue_sync.send(sender=self, issue=issue)
            self._update_user_data(server, data, issue)
        tracker.last_update = datetime.now() - timedelta(days=1)
        tracker.save()
        post_tracker_sync.send(sender=self, tracker=tracker)
        return True
Beispiel #5
0
        self._log.info('Last update: %s' % d)
        tids = server.ticket.getRecentChanges(d)
        self._log.info('Issue updates: %s' % ` tids `)
        for tid in tids:
            issue = Issue.by_tracker_id(tracker.id, tid)
            id_, cr_date, last_change, data = server.ticket.get(tid)
            #if isinstance(cr_date, int):
            #cr_date = datetime.fromtimestamp(cr_date)
            #last_change = datetime.fromtimestamp(last_change)
            issue.no = id_
            issue.set_title(data.get('summary', ''))
            issue.set_description(data.get('description', ''))
            issue.reporter = data.get('reporter')
            issue.owner = data.get('owner')
            issue.last_change = last_change
            issue.tracker = tracker
            # Only default status values are allowed as Trac allows renaming
            # of status values.
            resolution = data.get('resolution')
            issue.active = resolution in ACTIVE_STATUS
            if not issue.id:
                issue.created = datetime.now()
            issue.updated = datetime.now()
            issue.save()
            post_issue_sync.send(sender=self, issue=issue)
            self._update_user_data(server, data, issue)
        tracker.last_update = datetime.now() - timedelta(days=1)
        tracker.save()
        post_tracker_sync.send(sender=self, tracker=tracker)
        return True