RooTicket.vala
[gitlive] / RooTicket.vala
index 232b918..3b8271f 100644 (file)
@@ -20,6 +20,9 @@ class RooTicket : Object
         return _RooTicket;
     }
        public Gee.ArrayList<RooTicket> tickets; // only available for singletonn.
+       public string username = ""; // only available for singletonn.
+       public string password = ""; // only available for singletonn.
+
 
        public string  id; // not really important that they are numbers..
        public string summary;
@@ -27,6 +30,29 @@ class RooTicket : Object
        public string project_id_name;
 
 
+       public string summaryToBranchName()
+       {
+               // first 5 words of summary..
+               var  regex = new Regex ("[^A-Za-z0-9 ]+");
+               var str = regex.replace(this.summary, this.summary.length, 0);
+               string[] words = Regex.split_simple ("[ \t]+", str);
+               var ret = "";
+               for (var i =0; i< (words.length > 5 ? 5 : words.length); i++) {
+                       ret += ret.length > 0 ? "_" : "";
+                       ret += words[i];
+               }
+               return ret;
+               
+       }
+       public string usernameLocal()
+       {
+               // git username is an email addres... - so this reutrns the local part..
+               //?? assumes that all members are under the same domain... normally the case......
+               return RooTicket.singleton().username.split('@')[0];
+       
+       }
+
+
        public void addTicket(Json.Object t)
        {
                var add = new RooTicket();
@@ -38,6 +64,17 @@ class RooTicket : Object
                GLib.debug("ADD ticket  %s : %s : %s", add.id, add.summary, add.project_id_name);
        }
  
+       public RooTicket? getById(string id)
+       {
+               foreach(var t in this.tickets) {
+                       if (t.id == id) {
+                               return t;
+                       }
+               }
+               return null;
+       }
+
 
        public void loadTickets()
        {
@@ -97,33 +134,38 @@ class RooTicket : Object
                
        }
        
-       public  static void setAuth(Soup.Message message) {
-       
-               string str;
-               var username = "";
-               var password = "";
-               GLib.FileUtils.get_contents(GLib.Environment.get_home_dir() + "/.netrc", out str);
-               var lines = str.split("\n");
-               for(var i=0; i< lines.length; i++) {
-               // assumes one line per entry.. if not we are buggered...
-                               GLib.debug("got %s" , lines[i]);
-               
-                       var bits =  Regex.split_simple ("[ \t]+", lines[i].strip());
-                       if (bits.length < 6 || bits[0] != "machine" || bits[1] != "git.roojs.com") {
-                               continue;
-                       }
-                               GLib.debug("found password?");
-                       // we are gussing.... 
-                       username = bits[3];
-                       password = bits[5];
+       public  static void setAuth(Soup.Message message) 
+       {
+               var rs =  RooTicket.singleton();                
+               if (rs.username.length < 1) {
+                       string str;
+                       GLib.FileUtils.get_contents(GLib.Environment.get_home_dir() + "/.netrc", out str);
+                       var lines = str.split("\n");
+                       for(var i=0; i< lines.length; i++) {
+                       // assumes one line per entry.. if not we are buggered...
+                                       GLib.debug("got %s" , lines[i]);
                        
+                               var bits =  Regex.split_simple ("[ \t]+", lines[i].strip());
+                               if (bits.length < 6 || bits[0] != "machine" || bits[1] != "git.roojs.com") {
+                                       continue;
+                               }
+                                       GLib.debug("found password?");
+                               // we are gussing.... 
+                               username = bits[3];
+                               password = bits[5];
+                               RooTicket.singleton().username  = bits[3];
+                               RooTicket.singleton().password  = bits[5];              
+                       }
                }
 
-               var authCode = Base64.encode ("%s:%s".printf(username, password).data);
+
+               var authCode = Base64.encode ("%s:%s".printf(rs.username, rs.password).data);
                message.request_headers.append("Authorization", "Basic %s".printf(authCode));
        
        
        }
+
+