From ea67edfa992259717c97c3a591fa1bd9482625d1 Mon Sep 17 00:00:00 2001 From: Arief Bayu Purwanto Date: Wed, 18 Feb 2015 11:59:35 +0700 Subject: [PATCH 1/4] introduce "debug" config. Value is true/false (boolean) --- bot/utils.lua | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/bot/utils.lua b/bot/utils.lua index ec3ab82..3ad714e 100644 --- a/bot/utils.lua +++ b/bot/utils.lua @@ -84,6 +84,14 @@ function vardump(value, depth, key) local linePrefix = "" local spaces = "" + -- print("++++++++++ --> " .. _config.debug) + + if _config.debug ~= nil then + if _config.debug == false then + return "" + end + end + if key ~= nil then linePrefix = "["..key.."] = " end From 225a340a820b61d73717e3af34d83a61bb8b09ec Mon Sep 17 00:00:00 2001 From: Arief Bayu Purwanto Date: Wed, 18 Feb 2015 12:01:00 +0700 Subject: [PATCH 2/4] introduce table.map_length to count array size I can't seems to work with table.getn() :(. This is used primarily in plugins/bugzilla.lua --- bot/utils.lua | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/bot/utils.lua b/bot/utils.lua index 3ad714e..c5e9863 100644 --- a/bot/utils.lua +++ b/bot/utils.lua @@ -313,4 +313,15 @@ function send_document_from_url(receiver, url, cb_function, cb_extra) local file_path = download_to_file(url, false) print("File path: "..file_path) _send_document(receiver, file_path, cb_function, cb_extra) -end \ No newline at end of file +end + +-- http://stackoverflow.com/a/14377694/156869 +-- get length of an array +function table.map_length(t) + local c = 0 + for k,v in pairs(t) do + c = c+1 + end + return c +end + From ee6b91da14d46ccf66bf88892683acb681b8bff6 Mon Sep 17 00:00:00 2001 From: Arief Bayu Purwanto Date: Wed, 18 Feb 2015 12:01:47 +0700 Subject: [PATCH 3/4] initial bugzilla specific bot command --- plugins/bugzilla.lua | 117 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 plugins/bugzilla.lua diff --git a/plugins/bugzilla.lua b/plugins/bugzilla.lua new file mode 100644 index 0000000..fe023b0 --- /dev/null +++ b/plugins/bugzilla.lua @@ -0,0 +1,117 @@ +function bugzilla_login() + url = "https://bugzilla.mozilla.org/rest/login?login=" .. _config.bugzilla.username .. "&password=" .. _config.bugzilla.password + + print("accessing " .. url) + + local res,code = https.request( url ) + + data = json:decode(res) + + return data +end +function bugzilla_check(id) + -- data = bugzilla_login() + + vardump(data) + url = "https://bugzilla.mozilla.org/rest/bug/" .. id .. "?api_key=" .. _config.bugzilla.apikey + -- print(url) + local res,code = https.request( url ) + + data = json:decode(res) + + return data + +end + +function bugzilla_listopened(email) + + url = "https://bugzilla.mozilla.org/rest/bug?include_fields=id,summary,status,whiteboard,resolution&email1=" .. email .. "&email2=" .. email .. "&emailassigned_to2=1&emailreporter1=1&emailtype1=substring&emailtype2=substring&f1=bug_status&f2=bug_status&n1=1&n2=1&o1=equals&o2=equals&resolution=---&v1=closed&v2=resolved&api_key=" .. _config.bugzilla.apikey + + local res,code = https.request( url ) + + print(res) + + data = json:decode(res) + + return data +end + +function run(msg, matches) + + local response = "" + + if matches[1] == "status" then + data = bugzilla_check(matches[2]) + + vardump(data) + + if data.error == true then + return "Sorry, API failed with message: " .. data.message + else + response = "Bug #"..matches[1]..":\nReporter: "..data.bugs[1].creator + response = response .. "\n Last update: "..data.bugs[1].last_change_time + response = response .. "\n Status: "..data.bugs[1].status.." "..data.bugs[1].resolution + response = response .. "\n Whiteboard: "..data.bugs[1].whiteboard + response = response .. "\n Access: https://bugzilla.mozilla.org/show_bug.cgi?id=" .. matches[1] + print(response) + end + elseif matches[1] == "list" then + data = bugzilla_listopened(matches[2]) + + vardump(data) + + if data.error == true then + return "Sorry, API failed with message: " .. data.message + else + + -- response = "Bug #"..matches[1]..":\nReporter: "..data.bugs[1].creator + -- response = response .. "\n Last update: "..data.bugs[1].last_change_time + -- response = response .. "\n Status: "..data.bugs[1].status.." "..data.bugs[1].resolution + -- response = response .. "\n Whiteboard: "..data.bugs[1].whiteboard + -- response = response .. "\n Access: https://bugzilla.mozilla.org/show_bug.cgi?id=" .. matches[1] + local total = table.map_length(data.bugs) + + print("total bugs: " .. total) + + response = "There are " .. total .. " number of bug(s) assigned/reported by " .. matches[2] + + if total > 0 then + response = response .. ": " + + for tableKey, bug in pairs(data.bugs) do + response = response .. "\n #" .. bug.id + response = response .. "\n Status: " .. bug.status .. " " .. bug.resolution + response = response .. "\n Whiteboard: " .. bug.whiteboard + response = response .. "\n Summary: " .. bug.summary + end + end + end + + end + + return response +end + +-- (table) +-- [bugs] = (table) +-- [1] = (table) +-- [status] = (string) ASSIGNED +-- [id] = (number) 927704 +-- [whiteboard] = (string) [approved][full processed] +-- [summary] = (string) Budget Request - Arief Bayu Purwanto - https://reps.mozilla.org/e/mozilla-summit-2013/ +-- [2] = (table) +-- [status] = (string) ASSIGNED +-- [id] = (number) 1049337 +-- [whiteboard] = (string) [approved][full processed][waiting receipts][waiting report and photos] +-- [summary] = (string) Budget Request - Arief Bayu Purwanto - https://reps.mozilla.org/e/workshop-firefox-os-pada-workshop-media-sosial-untuk-perubahan-1/ +-- total bugs: 2 + +return { + description = "Lookup bugzilla status update", + usage = "/bot bugzilla [bug number]", + patterns = { + "^/bugzilla (status) (.*)$", + "^/bugzilla (list) (.*)$" + }, + run = run +} \ No newline at end of file From a553b8c428742b72e063c5c1cd6049611543530c Mon Sep 17 00:00:00 2001 From: yago Date: Thu, 19 Feb 2015 22:03:22 +0100 Subject: [PATCH 4/4] Removed _config.debug and table.map_length --- bot/utils.lua | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/bot/utils.lua b/bot/utils.lua index c5e9863..ec3ab82 100644 --- a/bot/utils.lua +++ b/bot/utils.lua @@ -84,14 +84,6 @@ function vardump(value, depth, key) local linePrefix = "" local spaces = "" - -- print("++++++++++ --> " .. _config.debug) - - if _config.debug ~= nil then - if _config.debug == false then - return "" - end - end - if key ~= nil then linePrefix = "["..key.."] = " end @@ -313,15 +305,4 @@ function send_document_from_url(receiver, url, cb_function, cb_extra) local file_path = download_to_file(url, false) print("File path: "..file_path) _send_document(receiver, file_path, cb_function, cb_extra) -end - --- http://stackoverflow.com/a/14377694/156869 --- get length of an array -function table.map_length(t) - local c = 0 - for k,v in pairs(t) do - c = c+1 - end - return c -end - +end \ No newline at end of file