class TicketSearchCriteriaSchema(Schema): boards = fields.List( fields.String( validate=validate.OneOf(JiraService.supported_board_keys())), metadata=dict(description='boards to fetch tickets from'), ) categories = fields.List( fields.String( validate=validate.OneOf(JiraService.supported_categories())), metadata=dict(description='categories the tickets belongs to'), ) reporter = fields.Email(metadata=dict(description='ticket reporter email')) assignee = fields.Email(metadata=dict( description='user whose ticket is assigned to')) status = fields.String(metadata=dict( description='name of the current ticket status')) watcher = fields.Email(metadata=dict( description='tickets user has subscribed to')) q = fields.String(metadata=dict(description='search for text occurrences')) fields_ = fields.List( fields.String(validate=validate.OneOf(JiraService.supported_fields())), data_key='fields', metadata=dict( description='additional fields to include in the results')) limit = fields.Integer( load_default=20, metadata=dict(description='tickets user has subscribed to')) sort = fields.String( validate=validate.OneOf(['created']), load_default='created', metadata=dict(description='sort tickets by'), )
def get(self): """ Get service tickets based on search criteria """ # read params and set defaults params = request.args.copy() filters = { 'boards': params.poplist('boards') or JiraService.supported_board_keys(), 'categories': params.poplist('categories') or JiraService.supported_categories(), 'fields': params.poplist('fields'), 'limit': params.get('limit', 20), 'sort': params.get('sort', 'created'), **params } # validate parameters errors = TicketSearchCriteriaSchema().validate(filters) if errors: abort(400, status=400, message=errors) # consider default values tickets = TicketService.find_by(**filters) return IssueSchema(many=True).dump(tickets)
def get(self): """ Lists currently supported categories --- tags: - tickets responses: 200: description: Ok content: application/json: schema: type: array items: type: string """ return jsonify(JiraService.supported_categories())
def get(self, key): """ Get a ticket given its identifier """ # search for ticket across supported boards and categories result = next( iter( TicketService.find_by( key=key, boards=JiraService.supported_board_keys(), categories=JiraService.supported_categories(), limit=1)), None) if not result: abort(404, status=404, message='Ticket not found') else: return IssueSchema().dump(result)
class CreateTicketSchema(Schema): title = fields.String(required=True, metadata=dict( description='an intuitive title for the ticket', example=''), validate=validate.Length(min=5)) body = fields.String(required=True, metadata=dict(description='the content of the ticket', example=''), validate=validate.Length(min=5)) reporter = fields.Email(required=True, metadata=dict(description='ticket reporter email', example='')) board = fields.String( required=True, metadata=dict(description='boards to fetch tickets from', default=Board.default().key), validate=validate.OneOf(JiraService.supported_board_keys())) category = fields.String( required=True, metadata=dict( description='category the ticket belongs to', default=current_app.config['JIRA_TICKET_LABEL_DEFAULT_CATEGORY']), validate=validate.OneOf(JiraService.supported_categories())) watchers = fields.List(fields.Email(), allow_none=False, load_default=[], metadata=dict( description='users to be watching the ticket', example=[])) priority = fields.String( validate=validate.OneOf(['low', 'high']), allow_none=True, load_default=None, metadata=dict(description='define a higher or lower ticket priority', example=None))