6 changed files with 142 additions and 17 deletions
-
21lib/data.js
-
65lib/http.js
-
22lib/tray.js
-
25lib/web/main.js
-
14main.js
-
10res/post-commit
@ -1,14 +1,61 @@ |
|||
|
|||
const { Notification } = require('electron') |
|||
|
|||
var http = require("http"); |
|||
var querystring = require("querystring"); |
|||
var url = require("url"); |
|||
const path = require('path') |
|||
const libdata = require(path.join(__dirname, 'data.js')); |
|||
exports.start = function () { |
|||
http.createServer(function (request, response) { |
|||
let body = []; |
|||
request.on('data', (chunk) => { |
|||
body.push(chunk); |
|||
}).on('end', () => { |
|||
body = Buffer.concat(body).toString(); |
|||
// at this point, `body` has the entire request body stored in it as a string
|
|||
|
|||
console.log("body is " + body); |
|||
}); |
|||
|
|||
var pathname = url.parse(request.url).pathname; |
|||
if (HttpMap[pathname]) { |
|||
HttpMap[pathname](request, response) |
|||
} else { |
|||
response.end("请求未定义"); |
|||
} |
|||
}).listen(37188); |
|||
} |
|||
|
|||
HttpMap = { |
|||
"/commit": function (request, response) { |
|||
let query = querystring.parse(url.parse(request.url).query); |
|||
let branch = query["branch"]; |
|||
let commit = query["commit"]; |
|||
if (!branch || !commit) { |
|||
console.log([branch, commit]); |
|||
response.end("error"); |
|||
return; |
|||
} |
|||
let branchSplit = branch.split("-"); |
|||
let commitSplit = commit.split(" "); |
|||
if (branchSplit.length < 2 || commitSplit.length < 2) { |
|||
console.log([branch, commit, "error"]); |
|||
response.end("error"); |
|||
return; |
|||
} |
|||
let id = branchSplit[0]; |
|||
let hash = commitSplit.shift(); |
|||
commit = commitSplit.join(" "); |
|||
if (commit[0] == '-' || commit[0] == '#') { |
|||
console.log([branch, commit, "skip commit"]); |
|||
(new Notification({ |
|||
title: "有一条新的提交被忽略", |
|||
body: `分支:${branch} 提交内容:${commit}` |
|||
})).show() |
|||
|
|||
response.end("skip commit"); |
|||
return; |
|||
} |
|||
libdata.AddCommitToQueue({ |
|||
id: id, |
|||
branch: branch, |
|||
hash: hash, |
|||
commit: commit, |
|||
}); |
|||
|
|||
console.log([branch, commit, "success"]); |
|||
response.end("success"); |
|||
} |
|||
} |
@ -0,0 +1,10 @@ |
|||
#!/bin/sh |
|||
|
|||
branch=`git symbolic-ref --short -q HEAD` |
|||
commit=`git log -1 --oneline $branch` |
|||
|
|||
branchencode=`echo -n "$branch" | xxd -ps | tr -d '\n' | sed -r 's/(..)/%\1/g'` |
|||
commitencode=`echo -n "$commit" | xxd -ps | tr -d '\n' | sed -r 's/(..)/%\1/g'` |
|||
curl "http://127.0.0.1:37188/commit?branch=${branchencode}&commit=${commitencode}" |
|||
echo 分支[$branch][$commit] |
|||
exit 0 |
Write
Preview
Loading…
Cancel
Save
Reference in new issue