Esempio n. 1
0
 def test_understand_repo_info(self):
     responses.add(
         responses.GET, 'https://api.github.com/repos/kkamkou/gitmostwanted.com', status=200,
         body=json.dumps(self._body_repo_info()), content_type='application/json'
     )
     self.assertTupleEqual(
         api.repo_info('kkamkou/gitmostwanted.com'), (self._body_repo_info(), 200)
     )
     responses.add(
         responses.GET, 'https://api.github.com/repos/nobody/nothing', status=404,
         body=json.dumps(self._body_not_found()), content_type='application/json'
     )
     self.assertTupleEqual(api.repo_info('nobody/nothing'), (None, 404))
def most_starred_sync(model_name: str, query: str):
    service = bigquery.instance(app)
    model = getattr(report, model_name)

    db.session.query(model).delete()

    for row in job_results(Job(service, query)):
        info, code = repo_info(row[1])
        if not info:
            continue

        db.session.merge(
            model(
                id=row[0],
                cnt_watch=row[2],
                repo=Repo(
                    id=info['id'],
                    name=info['name'],
                    language=info['language'],
                    full_name=info['full_name'],
                    description=info['description'],
                    html_url=info['html_url'],
                    homepage=info['homepage'],
                    created_at=datetime.strptime(info['created_at'], '%Y-%m-%dT%H:%M:%SZ')
                )
            )
        )

    db.session.commit()
Esempio n. 3
0
def metadata_refresh(num_days):
    repos = Repo.query\
        .filter(
            Repo.checked_at.is_(None) |
            (Repo.checked_at <= datetime.now() + timedelta(days=num_days * -1))
        )\
        .yield_per(15)\
        .limit(300)  # GitHub allows only 3000 calls per day within a token
    for repo in repos:
        repo.checked_at = datetime.now()

        details, code = api.repo_info(repo.full_name)
        if not details:
            if 400 <= code < 500:
                repo.worth -= 1
                app.logger.info(
                    '{0} is not found, the "worth" has been decreased by 1'.format(repo.full_name)
                )
            continue

        for key in ['description', 'language', 'homepage']:
            if getattr(repo, key) != details[key]:
                setattr(repo, key, details[key])

        db.session.commit()
    return repos.count()
Esempio n. 4
0
def most_starred_sync(body, model_name):
    response = fetch(body)
    model = getattr(report, model_name)

    db.session.query(model).delete()

    for row in response:
        info = repo_info(row[1])
        if not info:
            continue

        db.session.merge(
            model(
                id=row[0],
                cnt_watch=row[2],
                repo=Repo(
                    id=info['id'],
                    name=info['name'],
                    language=info['language'],
                    full_name=info['full_name'],
                    description=info['description'],
                    html_url=info['html_url']
                )
            )
        )

    db.session.commit()