/plugins/bugzilla.lua

https://gitlab.com/yeah568/telegram-bot · Lua · 105 lines · 69 code · 16 blank · 20 comment · 10 complexity · 39aea91e806f9d60d8201b161489fe4c MD5 · raw file

  1. do
  2. local BASE_URL = "https://bugzilla.mozilla.org/rest/"
  3. local function bugzilla_login()
  4. local url = BASE_URL.."login?login=" .. _config.bugzilla.username .. "&password=" .. _config.bugzilla.password
  5. print("accessing " .. url)
  6. local res,code = https.request( url )
  7. local data = json:decode(res)
  8. return data
  9. end
  10. local function bugzilla_check(id)
  11. -- data = bugzilla_login()
  12. local url = BASE_URL.."bug/" .. id .. "?api_key=" .. _config.bugzilla.apikey
  13. -- print(url)
  14. local res,code = https.request( url )
  15. local data = json:decode(res)
  16. return data
  17. end
  18. local function bugzilla_listopened(email)
  19. local url = BASE_URL.."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
  20. local res,code = https.request( url )
  21. print(res)
  22. local data = json:decode(res)
  23. return data
  24. end
  25. local function run(msg, matches)
  26. local response = ""
  27. if matches[1] == "status" then
  28. local data = bugzilla_check(matches[2])
  29. vardump(data)
  30. if data.error == true then
  31. return "Sorry, API failed with message: " .. data.message
  32. else
  33. response = "Bug #"..matches[1]..":\nReporter: "..data.bugs[1].creator
  34. response = response .. "\n Last update: "..data.bugs[1].last_change_time
  35. response = response .. "\n Status: "..data.bugs[1].status.." "..data.bugs[1].resolution
  36. response = response .. "\n Whiteboard: "..data.bugs[1].whiteboard
  37. response = response .. "\n Access: https://bugzilla.mozilla.org/show_bug.cgi?id=" .. matches[1]
  38. print(response)
  39. end
  40. elseif matches[1] == "list" then
  41. local data = bugzilla_listopened(matches[2])
  42. vardump(data)
  43. if data.error == true then
  44. return "Sorry, API failed with message: " .. data.message
  45. else
  46. -- response = "Bug #"..matches[1]..":\nReporter: "..data.bugs[1].creator
  47. -- response = response .. "\n Last update: "..data.bugs[1].last_change_time
  48. -- response = response .. "\n Status: "..data.bugs[1].status.." "..data.bugs[1].resolution
  49. -- response = response .. "\n Whiteboard: "..data.bugs[1].whiteboard
  50. -- response = response .. "\n Access: https://bugzilla.mozilla.org/show_bug.cgi?id=" .. matches[1]
  51. local total = table.map_length(data.bugs)
  52. print("total bugs: " .. total)
  53. local response = "There are " .. total .. " number of bug(s) assigned/reported by " .. matches[2]
  54. if total > 0 then
  55. response = response .. ": "
  56. for tableKey, bug in pairs(data.bugs) do
  57. response = response .. "\n #" .. bug.id
  58. response = response .. "\n Status: " .. bug.status .. " " .. bug.resolution
  59. response = response .. "\n Whiteboard: " .. bug.whiteboard
  60. response = response .. "\n Summary: " .. bug.summary
  61. end
  62. end
  63. end
  64. end
  65. return response
  66. end
  67. -- (table)
  68. -- [bugs] = (table)
  69. -- [1] = (table)
  70. -- [status] = (string) ASSIGNED
  71. -- [id] = (number) 927704
  72. -- [whiteboard] = (string) [approved][full processed]
  73. -- [summary] = (string) Budget Request - Arief Bayu Purwanto - https://reps.mozilla.org/e/mozilla-summit-2013/
  74. -- [2] = (table)
  75. -- [status] = (string) ASSIGNED
  76. -- [id] = (number) 1049337
  77. -- [whiteboard] = (string) [approved][full processed][waiting receipts][waiting report and photos]
  78. -- [summary] = (string) Budget Request - Arief Bayu Purwanto - https://reps.mozilla.org/e/workshop-firefox-os-pada-workshop-media-sosial-untuk-perubahan-1/
  79. -- total bugs: 2
  80. return {
  81. description = "Lookup bugzilla status update",
  82. usage = "/bot bugzilla [bug number]",
  83. patterns = {
  84. "^/bugzilla (status) (.*)$",
  85. "^/bugzilla (list) (.*)$"
  86. },
  87. run = run
  88. }
  89. end