Skip to content

Commit

Permalink
use http module & fix circular dependency & extend queue function
Browse files Browse the repository at this point in the history
  • Loading branch information
saqqdy committed Dec 2, 2021
1 parent d84511b commit 3ee7d7e
Show file tree
Hide file tree
Showing 13 changed files with 71 additions and 93 deletions.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
<div id="box"></div>

<script nomodule>!function(){var e=document,t=e.createElement("script");if(!("noModule"in t)&&"onbeforeload"in t){var n=!1;e.addEventListener("beforeload",(function(e){if(e.target===t)n=!0;else if(!e.target.hasAttribute("nomodule")||!n)return;e.preventDefault()}),!0),t.type="module",t.src=".",e.head.appendChild(t),t.remove()}}();</script>
<script nomodule id="vite-legacy-polyfill" src="/assets/polyfills-legacy.f1bc0338.js"></script>
<script nomodule id="vite-legacy-polyfill" src="/assets/polyfills-legacy.6b731a58.js"></script>
<script nomodule id="vite-legacy-entry" data-src="/assets/index-legacy.c00d1262.js">System.import(document.getElementById('vite-legacy-entry').getAttribute('data-src'))</script>
</body>
</html>
34 changes: 16 additions & 18 deletions bin/core/build/runJenkins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,24 +65,22 @@ async function runJenkins({
app
}
)
await request
.post(
{
url
},
{
username: buildConfig.username,
password: buildConfig.password
}
)
.then(() => {
sh.echo(success('成功调起Jenkins构建'))
})
// sh.exec(
// `curl -u ${buildConfig.username}:${buildConfig.password} "${url}"`,
// { silent: true }
// )
// sh.echo(success('成功调起Jenkins构建'))
// await request
// .get({
// url: 'http://tdeploy:[email protected]/view/git_bug/job/git_wjweb_bug/buildWithParameters?token=wojiayunbug&build_app=all',
// data: {
// username: buildConfig.username,
// password: buildConfig.password
// }
// })
// .then(() => {
// sh.echo(success('成功调起Jenkins构建'))
// })
sh.exec(
`curl -u ${buildConfig.username}:${buildConfig.password} "${url}"`,
{ silent: true }
)
sh.echo(success('成功调起Jenkins构建'))
}

module.exports = runJenkins
Expand Down
3 changes: 2 additions & 1 deletion bin/core/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ class Request {
}
)
} else {
// console.log(buffer.toString())
resolve(JSON.parse(buffer.toString()))
}
})
Expand Down Expand Up @@ -128,7 +129,7 @@ class Request {
allowDots: true
})
if (postData) {
url += url.indexOf('?') !== -1 ? '?' : '&'
url += url.indexOf('?') === -1 ? '?' : '&'
url += postData
}
return await this.request('GET', url)
Expand Down
36 changes: 18 additions & 18 deletions bin/core/sendGroupMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,24 @@ async function sendGroupMessage(
}
message = message.replace(/\s/g, '')
urls.forEach(async item => {
await request
.post(
{
url: item || config.gitNotificationGroupUrl
},
{
content: message
}
)
.then(() => {
sh.echo(success('发送消息成功'))
})
// sh.exec(
// `curl -i -H "Content-Type: application/json" -X POST -d "{\u005c"content\u005c":\u005c"${message}\u005c"}" "${
// item || config.gitNotificationGroupUrl
// }"`,
// { silent }
// )
// await request
// .post(
// {
// url: item || config.gitNotificationGroupUrl
// },
// {
// content: message
// }
// )
// .then(() => {
// sh.echo(success('发送消息成功'))
// })
sh.exec(
`curl -i -H "Content-Type: application/json" -X POST -d "{\u005c"content\u005c":\u005c"${message}\u005c"}" "${
item || config.gitNotificationGroupUrl
}"`,
{ silent }
)
})
}

Expand Down
42 changes: 21 additions & 21 deletions bin/core/utils/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,27 +80,27 @@ async function sendMessage(
return
}
message = message.replace(/\s/g, '')
if (config.msgUrl) {
await request
.post(
{
url: config.msgUrl
},
{
envParams: {
error_msg: message
}
}
)
.then(() => {
sh.echo(success('发送消息成功'))
})
}
// config.msgUrl &&
// sh.exec(
// `curl -i -H "Content-Type: application/json" -X POST -d '{"envParams":{"error_msg":"'${message}'"}}' "${config.msgUrl}"`,
// { silent }
// )
// if (config.msgUrl) {
// await request
// .post(
// {
// url: config.msgUrl
// },
// {
// envParams: {
// error_msg: message
// }
// }
// )
// .then(() => {
// sh.echo(success('发送消息成功'))
// })
// }
config.msgUrl &&
sh.exec(
`curl -i -H "Content-Type: application/json" -X POST -d '{"envParams":{"error_msg":"'${message}'"}}' "${config.msgUrl}"`,
{ silent }
)
}

module.exports = {
Expand Down
2 changes: 1 addition & 1 deletion bin/gitm-permission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ program
.option('--dev', '是否限制dev提交', false)
.option('--release', '是否限制release提交', false)
.action((message: string, opt: GitmBuildOption) => {
console.log('gitm permission is running')
console.info('gitm permission is running')
const current = getCurrentBranch()
const allow = [config.master]
const msg = sh.exec('git show', { silent: true }).stdout
Expand Down
2 changes: 1 addition & 1 deletion docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## 2021.12.01 v2.14.5 更新日志

1. `queue`方法扩展支持promise函数
2. 替换剩余几个`curl`脚本,处理win7不能执行curl的兼容问题
2. 替换创建远程合并请求的`curl`脚本,处理win7不能执行curl的兼容问题
3. 解决脚本队列`continue`缓存保存失败的问题
4. 解决`circular dependency`问题

Expand Down
12 changes: 3 additions & 9 deletions lib/core/build/runJenkins.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const sh = require("shelljs");
const request = require("../request");
require("../request");
const getApolloConfig = require("./getApolloConfig");
const mapTemplate = require("../utils/mapTemplate");
const { error, success } = require("../utils/colors");
Expand Down Expand Up @@ -44,13 +44,7 @@ async function runJenkins({
token: cfg.token,
app
});
await request.post({
url
}, {
username: buildConfig.username,
password: buildConfig.password
}).then(() => {
sh.echo(success("\u6210\u529F\u8C03\u8D77Jenkins\u6784\u5EFA"));
});
sh.exec(`curl -u ${buildConfig.username}:${buildConfig.password} "${url}"`, { silent: true });
sh.echo(success("\u6210\u529F\u8C03\u8D77Jenkins\u6784\u5EFA"));
}
module.exports = runJenkins;
2 changes: 1 addition & 1 deletion lib/core/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class Request {
allowDots: true
});
if (postData) {
url += url.indexOf("?") !== -1 ? "?" : "&";
url += url.indexOf("?") === -1 ? "?" : "&";
url += postData;
}
return await this.request("GET", url);
Expand Down
10 changes: 2 additions & 8 deletions lib/core/sendGroupMessage.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const sh = require("shelljs");
const request = require("./request");
require("./request");
const getApolloConfig = require("./build/getApolloConfig");
const { error, success } = require("./utils/colors");
async function sendGroupMessage(message, cfg = {}) {
Expand All @@ -22,13 +22,7 @@ async function sendGroupMessage(message, cfg = {}) {
}
message = message.replace(/\s/g, "");
urls.forEach(async (item) => {
await request.post({
url: item || config.gitNotificationGroupUrl
}, {
content: message
}).then(() => {
sh.echo(success("\u53D1\u9001\u6D88\u606F\u6210\u529F"));
});
sh.exec(`curl -i -H "Content-Type: application/json" -X POST -d "{\\"content\\":\\"${message}\\"}" "${item || config.gitNotificationGroupUrl}"`, { silent });
});
}
module.exports = sendGroupMessage;
15 changes: 3 additions & 12 deletions lib/core/utils/message.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const sh = require("shelljs");
const request = require("../request");
require("../request");
const { error, success } = require("./colors");
const mapTemplate = require("./mapTemplate");
const getGitConfig = require("../git/getGitConfig");
Expand Down Expand Up @@ -47,22 +47,13 @@ function postMessage(msg = "") {
}
async function sendMessage(message = "", cfg = {}) {
const config = getConfig();
const { silent = true } = cfg;
if (!config.msgUrl) {
sh.echo(error("\u8BF7\u914D\u7F6E\u6D88\u606F\u63A8\u9001\u5730\u5740"));
return;
}
message = message.replace(/\s/g, "");
if (config.msgUrl) {
await request.post({
url: config.msgUrl
}, {
envParams: {
error_msg: message
}
}).then(() => {
sh.echo(success("\u53D1\u9001\u6D88\u606F\u6210\u529F"));
});
}
config.msgUrl && sh.exec(`curl -i -H "Content-Type: application/json" -X POST -d '{"envParams":{"error_msg":"'${message}'"}}' "${config.msgUrl}"`, { silent });
}
module.exports = {
getMessage,
Expand Down
2 changes: 1 addition & 1 deletion lib/gitm-permission.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const { error } = require("./core/utils/index");
const getConfig = require("./core/getConfig");
const config = getConfig();
program.name("gitm permission").usage("[message] [--no-verify] [--dev] [--release]").arguments("[message]").description("\u6821\u9A8C\u63D0\u4EA4\u6743\u9650").option("--no-verify", "\u662F\u5426\u9700\u8981\u8DF3\u8FC7\u6821\u9A8C\u6743\u9650", false).option("--dev", "\u662F\u5426\u9650\u5236dev\u63D0\u4EA4", false).option("--release", "\u662F\u5426\u9650\u5236release\u63D0\u4EA4", false).action((message, opt) => {
console.log("gitm permission is running");
console.info("gitm permission is running");
const current = getCurrentBranch();
const allow = [config.master];
const msg = sh.exec("git show", { silent: true }).stdout;
Expand Down

1 comment on commit 3ee7d7e

@vercel
Copy link

@vercel vercel bot commented on 3ee7d7e Dec 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.