예제 #1
0
파일: mock.py 프로젝트: simudream/changes
def build(project, **kwargs):
    kwargs.setdefault('collection_id', uuid4().hex)
    kwargs.setdefault('label', get_sentences(1)[0][:128])
    kwargs.setdefault('status', Status.finished)
    kwargs.setdefault('result', Result.passed)
    kwargs.setdefault('duration', random.randint(10000, 100000))
    kwargs.setdefault('target', uuid4().hex)

    if 'source' not in kwargs:
        kwargs['source'] = source(project.repository)

    kwargs['project'] = project
    kwargs['project_id'] = kwargs['project'].id
    kwargs['author_id'] = kwargs['author'].id

    build = Build(**kwargs)
    db.session.add(build)

    event = Event(
        type=EventType.green_build,
        item_id=build.id,
        data={'status': 'success'}
    )
    db.session.add(event)

    return build
예제 #2
0
def test_simple():
    build = Build(
        id=UUID(hex='33846695b2774b29a71795a009e8168a'),
        label='Hello world',
        target='D1234',
        message='Foo bar',
        project=Project(
            slug='test', name='test', id=UUID('1e7958a368f44b0eb5a57372a9910d50'),
        ),
        project_id=UUID('1e7958a368f44b0eb5a57372a9910d50'),
        source=Source(
            revision_sha='1e7958a368f44b0eb5a57372a9910d50',
        ),
        date_created=datetime(2013, 9, 19, 22, 15, 22),
        date_started=datetime(2013, 9, 19, 22, 15, 23),
        date_finished=datetime(2013, 9, 19, 22, 15, 33),
    )
    result = serialize(build)
    assert result['name'] == 'Hello world'
    assert result['id'] == '33846695b2774b29a71795a009e8168a'
    assert result['source']['id'] == build.source.id.hex
    assert result['target'] == 'D1234'
    assert result['message'] == 'Foo bar'
    assert result['dateCreated'] == '2013-09-19T22:15:22'
    assert result['dateStarted'] == '2013-09-19T22:15:23'
    assert result['dateFinished'] == '2013-09-19T22:15:33'
    assert result['duration'] == 10000
    assert result['link'] == 'http://example.com/projects/test/builds/{0}/'.format(build.id.hex)
예제 #3
0
    def create_build(self, project, **kwargs):
        if 'source' not in kwargs:
            kwargs['source'] = self.create_source(project)

        kwargs['source_id'] = kwargs['source'].id

        kwargs.setdefault('label', 'Sample')

        build = Build(project_id=project.id, project=project, **kwargs)
        db.session.add(build)
        db.session.commit()

        return build
예제 #4
0
def build(project, **kwargs):
    kwargs.setdefault('label', get_sentences(1)[0][:128])
    kwargs.setdefault('status', Status.finished)
    kwargs.setdefault('result', Result.passed)
    kwargs.setdefault('repository', project.repository)
    kwargs.setdefault('duration', random.randint(10000, 100000))
    kwargs.setdefault('target', uuid4().hex)

    kwargs['project'] = project
    kwargs['repository_id'] = kwargs['repository'].id
    kwargs['project_id'] = kwargs['project'].id
    kwargs['author_id'] = kwargs['author'].id

    build = Build(**kwargs)
    db.session.add(build)

    return build
예제 #5
0
def create_build(project,
                 label,
                 target,
                 message,
                 author,
                 change=None,
                 patch=None,
                 cause=None,
                 source=None,
                 sha=None,
                 source_data=None):
    assert sha or source

    repository = project.repository

    if source is None:
        source, _ = get_or_create(Source,
                                  where={
                                      'repository': repository,
                                      'patch': patch,
                                      'revision_sha': sha,
                                      'data': source_data or {},
                                  })

    build = Build(
        project=project,
        project_id=project.id,
        source=source,
        source_id=source.id if source else None,
        status=Status.queued,
        author=author,
        author_id=author.id if author else None,
        label=label,
        target=target,
        message=message,
        cause=cause,
    )

    db.session.add(build)
    db.session.commit()

    execute_build(build=build)

    return build
예제 #6
0
def test_simple():
    job = Job(
        id=UUID(hex='33846695b2774b29a71795a009e8168a'),
        label='Hello world',
        project=Project(slug='test', name='test'),
        date_created=datetime(2013, 9, 19, 22, 15, 22),
        date_started=datetime(2013, 9, 19, 22, 15, 23),
        date_finished=datetime(2013, 9, 19, 22, 15, 33),
        build=Build(id=UUID('1e7958a368f44b0eb5a57372a9910d50'), ),
        build_id=UUID('1e7958a368f44b0eb5a57372a9910d50'),
        change=Change(
            id=UUID(hex='2e18a7cbc0c24316b2ef9d41fea191d6'),
            label='Hello world',
        ),
    )
    result = serialize(job)
    assert result['name'] == 'Hello world'
    assert result['id'] == '33846695b2774b29a71795a009e8168a'
    assert result['dateCreated'] == '2013-09-19T22:15:22'
    assert result['dateStarted'] == '2013-09-19T22:15:23'
    assert result['dateFinished'] == '2013-09-19T22:15:33'
    assert result['duration'] == 10000
예제 #7
0
def create_build(project,
                 collection_id,
                 label,
                 target,
                 message,
                 author,
                 change=None,
                 patch=None,
                 cause=None,
                 source=None,
                 sha=None,
                 source_data=None,
                 tag=None,
                 snapshot_id=None,
                 no_snapshot=False):
    assert sha or source

    repository = project.repository

    if source is None:
        if patch:
            source, _ = get_or_create(Source,
                                      where={
                                          'patch': patch,
                                      },
                                      defaults={
                                          'repository': repository,
                                          'revision_sha': sha,
                                          'data': source_data or {},
                                      })

        else:
            source, _ = get_or_create(Source,
                                      where={
                                          'repository': repository,
                                          'patch': None,
                                          'revision_sha': sha,
                                      },
                                      defaults={
                                          'data': source_data or {},
                                      })

    statsreporter.stats().incr('new_api_build')

    build = Build(
        project=project,
        project_id=project.id,
        collection_id=collection_id,
        source=source,
        source_id=source.id if source else None,
        status=Status.queued,
        author=author,
        author_id=author.id if author else None,
        label=label,
        target=target,
        message=message,
        cause=cause,
        tags=[tag] if tag else [],
    )

    db.session.add(build)
    db.session.commit()

    execute_build(build=build,
                  snapshot_id=snapshot_id,
                  no_snapshot=no_snapshot)

    return build
예제 #8
0
    def post(self, project_id):
        """Initiates a new snapshot for this project."""
        project = Project.get(project_id)
        if not project:
            return '', 404

        args = self.post_parser.parse_args()

        repository = project.repository

        try:
            revision = identify_revision(repository, args.sha)
        except MissingRevision:
            # if the default fails, we absolutely can't continue and the
            # client should send a valid revision
            return '{"error": "Unable to find a matching revision."}', 400

        if revision:
            sha = revision.sha
        else:
            sha = args.sha

        plan_list = get_snapshottable_plans(project)

        if not plan_list:
            return '{"error": "No snapshottable plans associated with project."}', 400

        source, _ = get_or_create(Source,
                                  where={
                                      'repository': repository,
                                      'revision_sha': sha,
                                      'patch_id': None,
                                  })

        build = Build(
            source_id=source.id,
            source=source,
            project_id=project.id,
            project=project,
            label='Create Snapshot',
            status=Status.queued,
            cause=Cause.snapshot,
            target=sha[:12],
        )
        db.session.add(build)

        # TODO(dcramer): this needs to update with the build result
        snapshot = Snapshot(
            project_id=project.id,
            source_id=source.id,
            build_id=build.id,
            status=SnapshotStatus.pending,
        )
        db.session.add(snapshot)

        jobs = []
        for plan in plan_list:
            job = Job(
                build=build,
                build_id=build.id,
                project=project,
                project_id=project.id,
                source=build.source,
                source_id=build.source_id,
                status=build.status,
                label='Create Snapshot: %s' % (plan.label, ),
            )
            db.session.add(job)

            jobplan = JobPlan.build_jobplan(plan, job)
            db.session.add(jobplan)

            image = SnapshotImage(
                job=job,
                snapshot=snapshot,
                plan=plan,
            )
            db.session.add(image)

            jobs.append(job)

        db.session.commit()

        for job in jobs:
            create_job.delay(
                job_id=job.id.hex,
                task_id=job.id.hex,
                parent_task_id=job.build_id.hex,
            )

        db.session.commit()

        sync_build.delay(
            build_id=build.id.hex,
            task_id=build.id.hex,
        )

        return self.respond(snapshot)