Example #1
0
 def setup_class(cls):
     cls.payload = PullRequestPayload() \
         .add_title(cls.title) \
         .add_source_branch_name(cls.source_repository_name) \
         .add_source_repository_full_name(
             cls.source_repository_full_name) \
         .add_destination_branch_name(cls.destination_branch_name)
     cls.expected = json.loads(cls.resource_data(
         'PullRequestPayload.minimal'))
Example #2
0
class PullRequestPayloadFixture(PullRequestFixture):
    builder = PullRequestPayload()

    # GIVEN: a class under test
    class_under_test = 'PullRequestPayload'

    # GIVEN: An example object created from example data
    @classmethod
    def example_object(cls):
        return PullRequestPayload(json.loads(cls.resource_data()))
Example #3
0
 def setup_class(cls):
     cls.payload = PullRequestPayload() \
         .add_title('REQUIRED title') \
         .add_source_branch_name('REQUIRED name') \
         .add_source_repository_full_name('owner/repo_slug') \
         .add_destination_branch_name('name') \
         .add_destination_commit_by_hash('name') \
         .add_close_source_branch(True) \
         .add_description('description') \
         .add_reviewer_by_username('accountname')
     cls.expected = json.loads(cls.resource_data(
         'PullRequestPayload.full'))
Example #4
0
def create_pr(pr_title, source_branch, dest_branch, source_repo_name, dest_repo_name, reviewers=[]):
    bitbucket = bitbucket_login()

    # https://github.com/wbrefvem/python-bitbucket/blob/b5002a97f0dd9d02dfc60f81b3a13d966abad9aa/tests/test_pullrequest.py#L222
    pr_payload = PullRequestPayload() \
            .add_title(pr_title) \
            .add_source_branch_name(source_branch) \
            .add_source_repository_full_name(source_repo_name) \
            .add_destination_branch_name(dest_branch) \
            .add_destination_repository_full_name(dest_repo_name) \
            .add_reviewers_from_usernames(reviewers)

    response = PullRequest.create(pr_payload, client=bitbucket)
    return response
Example #5
0
 def test_response_is_a_pullrequest(self):
     httpretty.register_uri(
         httpretty.POST,
         self.url,
         content_type='application/json',
         body=self.resource_data(),
         status=200)
     payload = PullRequestPayload() \
         .add_title(self.title) \
         .add_source_branch_name(self.source_branch_name) \
         .add_source_repository_full_name(
             self.source_repository_full_name) \
         .add_destination_branch_name(self.destination_branch_name) \
         .add_destination_repository_full_name(
             self.destination_repository_full_name)
     response = PullRequest.create(payload, client=self.test_client)
     assert 'application/json' == \
         httpretty.last_request().headers.get('Content-Type')
     assert isinstance(response, PullRequest)
Example #6
0
    def request_create(self, onto_user, onto_repo, from_branch, onto_branch, title=None, description=None, auto_slug=False, edit=None):
        try:
            onto_project = self.get_repository(onto_user, onto_repo)

            from_reposlug = self.guess_repo_slug(self.repository, self, resolve_targets=['{service}'])
            if from_reposlug:
                from_user, from_repo = from_reposlug.split('/')
                if (onto_user, onto_repo) == (from_user, from_repo):
                    from_project = onto_project
                else:
                    from_project = self.get_repository(from_user, from_repo)
            else:
                from_project = None

            # when no repo slug has been given to `git-repo X request create`
            # then chances are current project is a fork of the target
            # project we want to push to
            if auto_slug and onto_project.fork:
                onto_user = onto_project.parent.owner.login
                onto_repo = onto_project.parent.name
                onto_project = self.repository(onto_user, onto_repo)

            # if no onto branch has been defined, take the default one
            # with a fallback on master
            if not from_branch:
                from_branch = self.repository.active_branch.name

            # if no from branch has been defined, chances are we want to push
            # the branch we're currently working on
            if not onto_branch:
                onto_branch = self.get_project_default_branch(onto_project)

            from_target = '{}:{}'.format(from_user, from_branch)
            onto_target = '{}/{}:{}'.format(onto_user, onto_project, onto_branch)

            # translate from github username to git remote name
            if not title and not description and edit:
                title, description = edit(self.repository, from_branch, onto_target)
                if not title and not description:
                    raise ArgumentError('Missing message for request creation')

            request = PullRequest.create(
                        PullRequestPayload(
                            payload=dict(
                                title=title,
                                description=description or '',
                                destination=dict(
                                    branch=dict(name=onto_branch)
                                ),
                                source=dict(
                                    repository=dict(full_name='/'.join([from_user, from_repo])),
                                    branch=dict(name=from_branch)
                                )
                            )
                        ),
                        repository_name=onto_repo,
                        owner=onto_user,
                        client=self.bb.client
                    )

            yield '{}'
            yield ['Successfully created request of `{local}` onto `{project}:{remote}, with id `{ref}'.format(
                local=from_branch,
                project='/'.join([onto_user, onto_repo]),
                remote=onto_branch,
                ref=request.id
            )]
            yield ['available at {}'.format(request.links['html']['href'])]

        except HTTPError as err:
            status_code = hasattr(err, 'code') and err.code or err.response.status_code
            if 404 == status_code:
                raise ResourceNotFoundError("Couldn't create request, project not found: {}".format(onto_repo)) from err
            elif 400 == status_code and 'branch not found' in err.format_message():
                raise ResourceNotFoundError("Couldn't create request, branch not found: {}".format(from_branch)) from err
            raise ResourceError("Couldn't create request: {}".format(err)) from err
Example #7
0
 def example_object(cls):
     return PullRequestPayload(json.loads(cls.resource_data()))