sync
authorAlan Knowles <alan@roojs.com>
Mon, 5 Nov 2018 05:47:28 +0000 (13:47 +0800)
committerAlan Knowles <alan@roojs.com>
Mon, 5 Nov 2018 05:47:28 +0000 (13:47 +0800)
GitRepo.vala
MergeBranch.bjs
MergeBranch.vala
RooTicket.vala

index 6232296..d2f41a6 100644 (file)
@@ -230,14 +230,37 @@ public class GitRepo : Object
     //RooTicket? ticket = null;
     
     
-    public void doMerge(string action, string ticket_id, string commit_message)
+    public static void doMerges(string action, string ticket_id, string commit_message)
+    {
+       var commitrevs = "";
+       var sucess = true;
+       foreach(var  repo in GitRepo.singleton().cache.values) {
+               if (repo.activeTicket != null && repo.activeTicket.id == ticket_id) {
+                       var res = repo.doMerge(action,ticket_id, commit_message);
+                       if (!res) {
+                               sucess = false;
+                               continue;
+                       }
+                       commitrevs += commitrevs.length > 0 ? " " : "";
+                       commitrevs += repo.currentBranch.lastrev;
+               }
+       }
+       if (sucess && action == "CLOSE") {
+               RooTicket.singleton().getById(ticket_id).close(commitrevs);
+       }
+    }
+    
+    
+    public bool doMerge(string action, string ticket_id, string commit_message)
     {
        // in theory we should check to see if other repo's have got the same branch and merge all them at the same time.
        // also need to decide which branch we will merge into?
+       var ret = "";
        if (action == "CLOSE" || action == "LEAVE") {
                        
-                       var ret = "";
                        try {
+                               var oldbranch = this.currentBranch.name;
                        string[] cmd = { "checkout",   "master"  };
                        this.git( cmd );
                        cmd = { "merge",   "--squash",  this.currentBranch.name };
@@ -246,39 +269,72 @@ public class GitRepo : Object
                        this.git( cmd );
                        this.loadBranches();
                        
+                       var notification = new Notify.Notification(
+                                       "Merged branch %s to master".printf(oldbranch),
+                                       "",
+                                        "dialog-information"
+                                       
+                               );
+       
+                               notification.set_timeout(5);
+                               notification.show();   
+                       
                        // close ticket..
-                       if (action == "CLOSE") {
-                               RooTicket.singleton().getById(ticket_id).close();
-                       }
+                       return true; 
                        
                    } catch (Error e) {
-                       ret += e.message  + "\n";
+
+                       GitMonitor.gitmonitor.pauseError(e.message);
+                       return false;
                    }
                    // error~?? -- show the error dialog...
-                   return;
+                   return false;
        }
        if (action == "MASTER") {
                // merge master into ours..
                        try {
                        string[] cmd = { "merge",  "master" };
                        this.git( cmd );
+                       var notification = new Notify.Notification(
+                                       "Merged code from master to %s".printf(this.currentBranch.name),
+                                       "",
+                                        "dialog-information"
+                                       
+                               );
+                               notification.set_timeout(5);
+                               notification.show();   
+                       
+                       return true;
                        } catch (Error e) {
-                       ret += e.message  + "\n";
+                       GitMonitor.gitmonitor.pauseError(e.message);
+                       return false;
                    }
-                   return;
            }
        if (action == "EXIT") {
-       try {
+                       try {
+                       var oldbranch  = this.currentBranch.name;
                        string[] cmd = { "checkout",   "master"  };
                        this.git( cmd );
                        this.loadBranches();
+                       var notification = new Notify.Notification(
+                                       "Left branch %s".printf(oldbranch),
+                                       "",
+                                        "dialog-information"
+                                       
+                               );
+                               notification.set_timeout(5);
+                               notification.show();   
                        
+                       return true;
                    } catch (Error e) {
-                       ret += e.message  + "\n";
+                       GitMonitor.gitmonitor.pauseError(e.message);
+
+                       return false;                   
                    }
                    // error~?? -- show the error dialog...
-                   return;
+
        }
+       return false;
     }
     
     
index 2ac34a0..dd7f7da 100644 (file)
@@ -10,7 +10,7 @@
   {
    "listeners" : {
     "delete_event" : "(self, event) => {\n    this.el.hide();\n    return true; \n    //test  \n}\n ",
-    "response" : " (self, response_id) =>  { \n  \n\tGLib.debug(\"got %d\", (int) response_id);\n\tif (response_id == 0) {\n\t    _this.el.hide();\t\n\t    this.running = false; \n\t \treturn;\n\t}\n\t /*\n\t// have they selected a ticket..\n\t// make that the current active ticket?\n\t// we really need to store locally what ticket is being worked on..\n\t// in theory we could be working on multiple project and not merging..\n\t// -- each repo would have their active ticket (only one per repo)\n\t// -- so we could just store that in there\n\t// -- initial load can check the contents of the ticket files on first scan.\n\tvar ticket_id = _this.ticketsel.selectedTicketId();\n\t\n    if (this.repo != null) {\n    \tvar bn = _this.name.el.get_text();\n    \tif (ticket_id != \"\" ) {\n\t\t\tthis.repo.setActiveTicket( RooTicket.singleton().getById(ticket_id), bn);\n\t\t} else {\n\t\t\tthis.repo.createBranchNamed(bn);\n\t\t}\n    }\n\t*/\n\t\n\trepo.doMerge(_this.actionsel.selectedAction(), \n\t\t\t\t_this.ticketsel.selectedTicketId(),\n\t\t\t\t_this.name.el.get_text()\n\t\t);\n\t\n\tthis.running = false; \n\n\t \n\t_this.el.hide();\t\n \n\n\t \n}",
+    "response" : " (self, response_id) =>  { \n  \n\tGLib.debug(\"got %d\", (int) response_id);\n\tif (response_id == 0) {\n\t    _this.el.hide();\t\n\t    this.running = false; \n\t \treturn;\n\t}\n\t /*\n\t// have they selected a ticket..\n\t// make that the current active ticket?\n\t// we really need to store locally what ticket is being worked on..\n\t// in theory we could be working on multiple project and not merging..\n\t// -- each repo would have their active ticket (only one per repo)\n\t// -- so we could just store that in there\n\t// -- initial load can check the contents of the ticket files on first scan.\n\tvar ticket_id = _this.ticketsel.selectedTicketId();\n\t\n    if (this.repo != null) {\n    \tvar bn = _this.name.el.get_text();\n    \tif (ticket_id != \"\" ) {\n\t\t\tthis.repo.setActiveTicket( RooTicket.singleton().getById(ticket_id), bn);\n\t\t} else {\n\t\t\tthis.repo.createBranchNamed(bn);\n\t\t}\n    }\n\t*/\n\t\n\tGitRepo.doMerges(\n\t\t_this.actionsel.selectedAction(), \n\t\t_this.ticketsel.selectedTicketId(),\n\t\t_this.name.el.get_text()\n\t);\n\t\n\tthis.running = false; \n\n\t \n\t_this.el.hide();\t\n \n\n\t \n}",
     "show" : "(self)  => {\n \n\n  //test\n}"
    },
    "default_width" : 500,
         {
          "id" : "name",
          "$ visible" : true,
-         "| void updateText" : "() {\n\tvar ticket_id = _this.ticketsel.selectedTicketId();\n\t\n\tRooTicket ticket = null\n\tif (ticket_id.length > 0){\n\t\tticket = RooTicket.singleton().getById(ticket_id);\n\t}\n\t\n\tvar name = RooTicket.singleton().usernameLocal();\n\tvar action = _this.actionsel.selectedAction();\n\tthis.el.set_editable(true); \n \tswitch (action) {\n \t\tcase \"CLOSE\": // merge changes and close..\n\t \t\tthis.el.set_text(\"Fix #%s - %s\".printf(ticket_id, ticket != null ? ticket.summary : \"\"));\n\t \t\tbreak;\n\t \tcase \"LEAVE\": // partial fix\t\n\t \t\tthis.el.set_text(\"Partial Fix #%s - %s\".printf(ticket_id,   ticket != null ? ticket.summary : \"\"));\n\t \t\tbreak;\n \t\tcase \"MASTER\": // merge master\n \t\tcase \"EXIT\": // just switch back... \t\t\n \t\t\tthis.el.set_editable(false);\n\t \t\tthis.el.set_text(\"\"); // not relivant.. \t\t\t\n\t\t\tbreak;\n \t\tdefault:\n \t\t\n \t\t\tbreak; /// don't fix the text value.\n\t}\n   \n}\n",
+         "| void updateText" : "() {\n\tvar ticket_id = _this.ticketsel.selectedTicketId();\n\t\n\tRooTicket ticket = null;\n\tif (ticket_id.length > 0){\n\t\tticket = RooTicket.singleton().getById(ticket_id);\n\t}\n\t\n\tvar name = RooTicket.singleton().usernameLocal();\n\tvar action = _this.actionsel.selectedAction();\n\tthis.el.set_editable(true); \n \tswitch (action) {\n \t\tcase \"CLOSE\": // merge changes and close..\n\t \t\tthis.el.set_text(\"Fix #%s - %s\".printf(ticket_id, ticket != null ? ticket.summary : \"\"));\n\t \t\tbreak;\n\t \tcase \"LEAVE\": // partial fix\t\n\t \t\tthis.el.set_text(\"Partial Fix #%s - %s\".printf(ticket_id,   ticket != null ? ticket.summary : \"\"));\n\t \t\tbreak;\n \t\tcase \"MASTER\": // merge master\n \t\tcase \"EXIT\": // just switch back... \t\t\n \t\t\tthis.el.set_editable(false);\n\t \t\tthis.el.set_text(\"\"); // not relivant.. \t\t\t\n\t\t\tbreak;\n \t\tdefault:\n \t\t\n \t\t\tbreak; /// don't fix the text value.\n\t}\n   \n}\n",
          "xtype" : "Entry",
          "* pack" : "attach_defaults,1,2,2,3",
          "$ xns" : "Gtk"
index f1f974b..0ca2922 100644 (file)
@@ -84,10 +84,11 @@ public class MergeBranch : Object
             }
                */
                
-               repo.doMerge(_this.actionsel.selectedAction(), 
-                                       _this.ticketsel.selectedTicketId(),
-                                       _this.name.el.get_text()
-                       );
+               GitRepo.doMerges(
+                       _this.actionsel.selectedAction(), 
+                       _this.ticketsel.selectedTicketId(),
+                       _this.name.el.get_text()
+               );
                
                this.running = false; 
         
@@ -569,7 +570,7 @@ public class MergeBranch : Object
         public void updateText () {
                var ticket_id = _this.ticketsel.selectedTicketId();
                
-               RooTicket ticket = null
+               RooTicket ticket = null;
                if (ticket_id.length > 0){
                        ticket = RooTicket.singleton().getById(ticket_id);
                }
index 7c0ba27..d530b6f 100644 (file)
@@ -10,6 +10,7 @@ static RooTicket  _RooTicket;
 public class RooTicket : Object
 {
        
+       const string baseurl = "https://roojs.com/admin.php/Roo/mtrack_ticket"; 
        
        public static RooTicket singleton()
     {
@@ -116,7 +117,7 @@ public class RooTicket : Object
                }
        }
        
-       const string baseurl = "https://roojs.com/admin.php/Roo/mtrack_ticket";
+
 
        public void loadTickets()
        {
@@ -200,7 +201,48 @@ public class RooTicket : Object
        
        
        }
+       public void close(string commits)
+       {
+               var table = new GLib.HashTable<string, string>(str_hash, str_equal);
+               table.insert("id",id);
+               table.insert("status_name","resolved");
+               table.insert("reason","fixed by Commits: %s".printf(commits));  
+               var params = Soup.Form.encode_hash(table);              
+
+               GLib.debug("request POST %s / %s", baseurl, id);
+               
+               var session = new Soup.Session ();
+               session.timeout = 0;
+               var message = new Soup.Message ("POST", baseurl);
+               RooTicket.setAuth(message);
+                
+               message.set_request ("application/x-www-form-urlencoded", Soup.MemoryUse.STATIC, params.data);
+               session.send_message (message);
+               
+               
+               var data = (string) message.response_body.flatten().data;
+               GLib.debug("got %s", data);
+               try {
+                       var parser = new Json.Parser ();
+                       parser.load_from_data (data, -1);
 
+                       var response = parser.get_root().get_object();
+                       var status = response.get_boolean_member("success");
+               
+                       if(!status){
+                               GLib.error(response.get_string_member("errorMsg"));
+                               return ;
+                       }
+                        
+                       
+                        
+               
+               } catch (Error e) {
+                       GLib.error(e.message);
+                       return ;
+               }
+       
+       }