Example #1
0
 def get_timeline(self, issue):
     timeline = self._get_timeline_from_db(issue)
     if (timeline is not None and dateutil.parser.parse(issue.updated_at) <=
             dateutil.parser.parse(timeline['date'])):
         print 'HIT CACHE!!!'
         for event in json.loads(timeline['timeline']):
             yield Event.from_json(event)
     else:
         timeline = self._get_timeline_from_internet(issue)
         to_write = json.dumps([x.event for x in timeline])
         print 'REPLACING CACHED ITEM!!!'
         self._insert_or_replace_timeline_in_db(issue, to_write)
         for event in timeline:
             yield Event.from_json(event)
Example #2
0
    def _get_timeline_from_internet(self, issue):
        headers = {'Accept': 'application/vnd.github.mockingbird-preview'}

        url = self._url + '/repos/%s/issues/%d/timeline' % (issue.repo,
                                                            issue.number)
        while url is not None:
            response = requests.get(url, headers=headers, auth=self._auth)
            url = None

            if response.status_code != 200:
                raise Exception(response.json())

            if 'Link' in response.headers:
                url = re.split('<|>', [
                    link for link in response.headers['Link'].split(',')
                    if link[-10:] == 'rel="next"'
                ][0])[1]

            for event in response.json():
                yield Event.from_json(event)