Beispiel #1
0
    def put(self, branch_id, branch):
        """Modify this branch.

        :param branch_id: An ID of the branch.
        :param branch: A branch within the request body.
        """

        branch_dict = branch.as_dict(omit_unset=True)

        if "expiration_date" in six.iterkeys(branch_dict):
            abort(400, _("Can't change expiration date."))

        if "expired" in six.iterkeys(branch_dict):
            if branch_dict["expired"]:
                branch_dict["expiration_date"] = datetime.now(tz=pytz.utc)
            else:
                branch_dict["expiration_date"] = None

        if branch.project_id:
            original_branch = branches_api.branch_get(branch_id)

            if not original_branch:
                raise exc.NotFound(_("Branch %s not found") % branch_id)

            if branch.project_id != original_branch.project_id:
                abort(400, _("You can't associate branch %s "
                             "with another project.") % branch_id)

        result = branches_api.branch_update(branch_id, branch_dict)

        if result:
            return wmodels.Branch.from_db_model(result)
        else:
            raise exc.NotFound(_("Branch %s not found") % branch_id)
Beispiel #2
0
    def get_one(self, branch_id):
        """Retrieve information about the given branch.

        :param branch_id: Branch ID.
        """

        branch = branches_api.branch_get(branch_id)

        if branch:
            return wmodels.Branch.from_db_model(branch)
        else:
            raise exc.NotFound(_("Branch %s not found") % branch_id)
Beispiel #3
0
    def get_one(self, branch_id):
        """Retrieve information about the given branch.

        :param branch_id: Branch ID.
        """

        branch = branches_api.branch_get(branch_id)

        if branch:
            return wmodels.Branch.from_db_model(branch)
        else:
            raise exc.NotFound(_("Branch %s not found") % branch_id)
Beispiel #4
0
    def get_all(self,
                marker=None,
                limit=None,
                name=None,
                project_id=None,
                project_group_id=None,
                sort_field='id',
                sort_dir='asc'):
        """Retrieve a list of branches.

        Example::

          curl https://my.example.org/api/v1/branches

        :param marker: The resource id where the page should begin.
        :param limit: The number of branches to retrieve.
        :param name: Filter branches based on name.
        :param project_id: Filter branches based on project.
        :param project_group_id: Filter branches based on project group.
        :param sort_field: The name of the field to sort on.
        :param sort_dir: Sort direction for results (asc, desc).
        """
        # Boundary check on limit.
        if limit is not None:
            limit = max(0, limit)

        # Resolve the marker record.
        marker_branch = branches_api.branch_get(marker)

        branches = \
            branches_api.branch_get_all(marker=marker_branch,
                                        limit=limit,
                                        name=name,
                                        project_id=project_id,
                                        project_group_id=project_group_id,
                                        sort_field=sort_field,
                                        sort_dir=sort_dir)
        branches_count = \
            branches_api.branch_get_count(name=name,
                                          project_id=project_id,
                                          project_group_id=project_group_id)

        # Apply the query response headers.
        if limit:
            response.headers['X-Limit'] = str(limit)
        response.headers['X-Total'] = str(branches_count)
        if marker_branch:
            response.headers['X-Marker'] = str(marker_branch.id)

        return [wmodels.Branch.from_db_model(b) for b in branches]
Beispiel #5
0
    def get_one(self, branch_id):
        """Retrieve information about the given branch.

        Example::

          curl https://my.example.org/api/v1/branches/42

        :param branch_id: Branch ID.
        """

        branch = branches_api.branch_get(branch_id)

        if branch:
            return wmodels.Branch.from_db_model(branch)
        else:
            raise exc.NotFound(_("Branch %s not found") % branch_id)
Beispiel #6
0
    def get_one(self, branch_id):
        """Retrieve information about the given branch.

        Example::

          curl https://my.example.org/api/v1/branches/42

        :param branch_id: Branch ID.
        """

        branch = branches_api.branch_get(branch_id)

        if branch:
            return wmodels.Branch.from_db_model(branch)
        else:
            raise exc.NotFound(_("Branch %s not found") % branch_id)
Beispiel #7
0
    def get_all(self, marker=None, limit=None, name=None, project_id=None,
                project_group_id=None, sort_field='id', sort_dir='asc'):
        """Retrieve a list of branches.

        Example::

          curl https://my.example.org/api/v1/branches

        :param marker: The resource id where the page should begin.
        :param limit: The number of branches to retrieve.
        :param name: Filter branches based on name.
        :param project_id: Filter branches based on project.
        :param project_group_id: Filter branches based on project group.
        :param sort_field: The name of the field to sort on.
        :param sort_dir: Sort direction for results (asc, desc).
        """
        # Boundary check on limit.
        if limit is not None:
            limit = max(0, limit)

        # Resolve the marker record.
        marker_branch = branches_api.branch_get(marker)

        branches = \
            branches_api.branch_get_all(marker=marker_branch,
                                        limit=limit,
                                        name=name,
                                        project_id=project_id,
                                        project_group_id=project_group_id,
                                        sort_field=sort_field,
                                        sort_dir=sort_dir)
        branches_count = \
            branches_api.branch_get_count(name=name,
                                          project_id=project_id,
                                          project_group_id=project_group_id)

        # Apply the query response headers.
        if limit:
            response.headers['X-Limit'] = str(limit)
        response.headers['X-Total'] = str(branches_count)
        if marker_branch:
            response.headers['X-Marker'] = str(marker_branch.id)

        return [wmodels.Branch.from_db_model(b) for b in branches]
Beispiel #8
0
def branch_is_valid(task):
    """Check that branch exists, branch and task associated with the same
    project and branch is not expired.
    """

    branch = branches_api.branch_get(task.branch_id)

    if not branch:
        raise exc.NotFound(_("Branch %s not found.") % task.branch_id)

    if branch.project_id != task.project_id:
        abort(400, _("Branch %(b_id)s doesn't associate with "
                     "project %(p_id)s.")
              % {'b_id': branch.id, 'p_id': task.project_id})

    if branch["expired"]:
        abort(400, _("You can't associate task with expired branch %s.") %
              task.branch_id)

    return branch
Beispiel #9
0
    def put(self, branch_id, branch):
        """Modify this branch.

        Example::

          TODO

        :param branch_id: An ID of the branch.
        :param branch: A branch within the request body.
        """

        branch_dict = branch.as_dict(omit_unset=True)

        if "expiration_date" in six.iterkeys(branch_dict):
            abort(400, _("Can't change expiration date."))

        if "expired" in six.iterkeys(branch_dict):
            if branch_dict["expired"]:
                branch_dict["expiration_date"] = datetime.now(tz=pytz.utc)
            else:
                branch_dict["expiration_date"] = None

        if branch.project_id:
            original_branch = branches_api.branch_get(branch_id)

            if not original_branch:
                raise exc.NotFound(_("Branch %s not found") % branch_id)

            if branch.project_id != original_branch.project_id:
                abort(
                    400,
                    _("You can't associate branch %s "
                      "with another project.") % branch_id)

        result = branches_api.branch_update(branch_id, branch_dict)

        if result:
            return wmodels.Branch.from_db_model(result)
        else:
            raise exc.NotFound(_("Branch %s not found") % branch_id)