Commits

Henrique Romano committed 82eff3e

Implement apply command, improving try_tickets implementation to reuse on apply_tickets.

Comments (0)

Files changed (1)

djangotriager/main.py

     else:
         return code
 
-def try_ticket(config):
+def _process_tickets(config, func):
     config.ensure_one("ticket", "query")
     config.ensure_all("working_copy")
-
     if config.get("ticket"):
         tickets = [Ticket(config.get("ticket")), ]
     else:
         tickets = Ticket.get_by_query(config, config.get("query"))
 
+    patches_limit = config.get("n_patches")
+    patches_limit = patches_limit and int(patches_limit) or None
+
     for ticket in tickets:
-        ticket.try_patches(config, limit=config.get("n_patches"))
+        func(ticket, patches_limit)
         if not config.get("send_report"):
             print ticket.get_report()
         else:
-            # TODO: send_report
+            # TODO: send report to the ticket's page
             pass
 
+def try_ticket(config):
+    func = lambda ticket, limit: \
+        ticket.try_patches(config, limit=limit)
+    _process_tickets(config, func)
+
+def apply_ticket(config):
+    func = lambda ticket, limit: \
+        ticket.apply_patches(config, limit=limit)
+    _process_tickets(config, func)
+
 ACTIONS_MAP = {
-    'try' : try_ticket,
+    'try': try_ticket,
+    'apply': apply_ticket,
 }