diff options
Diffstat (limited to 'usr/share/build-errors/save-build-error.lua')
-rw-r--r-- | usr/share/build-errors/save-build-error.lua | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/usr/share/build-errors/save-build-error.lua b/usr/share/build-errors/save-build-error.lua new file mode 100644 index 0000000..80b2040 --- /dev/null +++ b/usr/share/build-errors/save-build-error.lua @@ -0,0 +1,56 @@ +#!/usr/bin/lua + +local db = '/var/spool/build-errors/sqlite/build-errors.db' + +cjson = require "cjson" +sqlite3 = require "lsqlite3" + +local input = io.stdin:read() +-- temporary +-- input = '{"hostname":"build-edge-armhf","pkgname":"msmtp","logurl":"http://build.alpinelinux.org/buildlogs/build-edge-armhf/main/msmtp/msmtp-1.6.3-r0.log"}' + +local function try_decoding_json(json) + return pcall(function () return cjson.decode(json) end) +end + +local function splitOnFirstSpace(str) + local space = str:find(' ') or (#str + 1) + return str:sub(1, space-1), str:sub(space+1) +end + +topic,msg = splitOnFirstSpace(input) +if msg ~= "" then + ok,d = try_decoding_json(msg) +end +if not ok then d = {comment=input} end +if not d.pkgname then d.pkgname = "?" end +if not d.hostname then d.hostname = "?" end +if not d.reponame then d.reponame = "?" end +if not d.logurl then d.logurl = "?" end +if not d.comment then d.comment = "" end + +for k, v in pairs(d) do + d[k] = string.gsub(d[k], "'", "''") +end + +-- for k, v in pairs(d) do print(string.format("%s=%s", tostring(k), tostring(v))) end + +db = sqlite3.open(db) +local query = "\ + insert into build_errors (\ + hostname,\ + pkgname,\ + reponame,\ + logurl,\ + comment\ + )\ + values (\ + '"..d.hostname.."',\ + '"..d.pkgname.."',\ + '"..d.reponame.."',\ + '"..d.logurl.."',\ + '"..d.comment.."'\ + );\ +" +db:exec(query) +db:close() |