X-Git-Url: http://git.roojs.org/?a=blobdiff_plain;f=RooTicket.vala;h=c30925ddcace3567764f105250616aedc802edea;hb=8d5b5ff019670d4b09db242aadfd24355a9d8ea6;hp=232b918a75d93ba8fcd1228e9472cfcc4d3c7792;hpb=629cbba854e1d1c4e5518e4c179308f9ed8a0918;p=gitlive diff --git a/RooTicket.vala b/RooTicket.vala index 232b918a..c30925dd 100644 --- a/RooTicket.vala +++ b/RooTicket.vala @@ -7,7 +7,7 @@ static RooTicket _RooTicket; -class RooTicket : Object +public class RooTicket : Object { @@ -20,6 +20,9 @@ class RooTicket : Object return _RooTicket; } public Gee.ArrayList 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,28 @@ 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 +63,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 +133,37 @@ 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.... + + 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)); } + +