Skip to content
This repository has been archived by the owner on Apr 25, 2022. It is now read-only.

Commit

Permalink
优化推送机器人
Browse files Browse the repository at this point in the history
  • Loading branch information
CodFrm committed Apr 20, 2019
1 parent f54ac8b commit b4f6a60
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cxmooc-tools",
"version": "2.0.7",
"version": "2.0.8",
"description": "> 一个快速学习超星慕课的chrome扩展工具(੧ᐛ੭挂科模式,启动)\r > 初次开发chrome扩展,有兴趣的朋友可以一起来哦",
"main": "mooc.js",
"scripts": {
Expand Down
12 changes: 9 additions & 3 deletions src/tg-bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,20 @@ const tgBot = new TelegramBot(botToken, { polling: false });
let lastTag = '';
if (branch == tag) {
//获取上一个tag
exec('git describe --tags HEAD^', (err, stdout, stderr) => {
lastTag = stdout.toString().match(/([v\.\d]+)-/)[1];
exec('git describe --tags HEAD^^', (err, stdout, stderr) => {
let match = stdout.toString().match(/([v\.\d]+)-/);
lastTag = match[1];
push();
});
} else {
push();
}
function push() {
exec('git log --pretty=format:"%s" ' + (branch == tag ? tag + '..' + lastTag : commit_range) + (commit_range.search('.') < 0 ? ' -1' : ''), (err, stdout, stderr) => {
let range=commit_range;
if (branch == tag) {
range = tag + '...' + lastTag;
}
exec('git log --pretty=format:"%s" ' + range + (range.search('.') < 0 ? ' -1' : ''), (err, stdout, stderr) => {
let sendText = '';
let end = '';
if (branch == tag) {
Expand All @@ -37,6 +42,7 @@ function push() {
sendText += hotUpdate();
}
sendText += "更新了以下内容:\n```\n" + stdout + "\n```\n" + end;
console.log(sendText);
tgBot.sendMessage(chat_id, sendText, { parse_mode: 'Markdown' });
tgBot.sendDocument(chat_id, fs.createReadStream('build/cxmooc-tools.crx'));
});
Expand Down

0 comments on commit b4f6a60

Please sign in to comment.