コード例 #1
0
def upsert_change_request(repository: Repository,
                          provider: str,
                          external_id: str,
                          data: dict = None) -> Response:
    lock_key = "hook:cr:{repo_id}:{provider}:{cr_xid}".format(
        repo_id=repository.id, provider=provider, cr_xid=external_id)
    with redis.lock(lock_key):
        json = data.copy() if data else {}
        json["external_id"] = external_id
        json["provider"] = provider

        cr = ChangeRequest.query.filter(
            ChangeRequest.repository_id == repository.id,
            ChangeRequest.provider == provider,
            ChangeRequest.external_id == external_id,
        ).first()

        if cr:
            return client.put(
                "/repos/{}/change-requests/{}".format(
                    repository.get_full_name(), cr.number),
                json=json,
            )

        return client.post("/repos/{}/change-requests".format(
            repository.get_full_name()),
                           json=json)
コード例 #2
0
ファイル: upserts.py プロジェクト: keegancsmith/zeus
def upsert_build(repository: Repository,
                 provider: str,
                 external_id: str,
                 data: dict = None) -> Response:
    lock_key = 'hook:build:{repo_id}:{provider}:{build_xid}'.format(
        repo_id=repository.id,
        provider=provider,
        build_xid=external_id,
    )
    with redis.lock(lock_key):
        json = data.copy() if data else {}
        json['external_id'] = external_id
        json['provider'] = provider

        build = Build.query.filter(
            Build.provider == provider,
            Build.external_id == external_id,
        ).first()

        if build:
            return client.put('/repos/{}/builds/{}'.format(
                repository.get_full_name(),
                build.number,
            ),
                              json=json)
        return client.post('/repos/{}/builds'.format(
            repository.get_full_name(), ),
                           json=json)
コード例 #3
0
    def get(self, repo: Repository):
        """
        Return a tree of testcases for the given repository.
        """
        latest_build = Build.query.join(
            Source,
            Source.id == Build.source_id,
        ).filter(
            Source.patch_id == None,  # NOQA
            Build.repository_id == repo.id,
            Build.result == Result.passed,
            Build.status == Status.finished,
        ).order_by(Build.date_created.desc(), ).first()

        if not latest_build:
            current_app.logger.info(
                'no successful builds found for repository')
            return self.respond({'entries': [], 'trail': []})

        path = '/repos/{}/builds/{}/file-coverage-tree'.format(
            repo.get_full_name(),
            latest_build.number,
        )

        response = api_client.get(path, request=request)
        data = json.loads(response.data)
        data['build'] = build_schema.dump(latest_build).data
        return self.respond(data)