infly-libs
Version:
工具组件库
53 lines (50 loc) • 1.75 kB
JavaScript
function postVersionFileAndMsg(publishText, extraParams = {}) {
const {
projectName,
newFileName,
gitInfo,
webhookUrl = "", // 启用企业微信推送
webhookAtUser = [],
webhookExtraText = ""
} = extraParams || {};
const { branch, commitMsg } = gitInfo || {};
const GITPATH = `https://gitee.com/gdinfly_1/${projectName}/blob/${branch}/${newFileName}`;
const UPLOADURL = `https://qyapi.weixin.qq.com/cgi-bin/webhook/upload_media?key=08ea37af-c6f5-47dc-8fab-0833707c70b8&type=file`;
/* const data = {
msgtype: "markdown",
markdown: {
content: `${publishText}\n构建文件:[点击下载](${GITPATH})`,
},
};
if (Array.isArray(webhookAtUser) && webhookAtUser.length > 0) {
webhookAtUser.forEach((item, index) => {
data.markdown.content = `${data.markdown.content}\n<@${item}>`;
});
} */
const data = {
msgtype: "text",
text: {
content: `${publishText}\n构建文件下载地址:${GITPATH}\n${webhookExtraText}\n`,
mentioned_mobile_list: webhookAtUser
},
};
try {
const axios = require("axios");
if (axios) {
axios
.post(webhookUrl, data, {
headers: {
"Content-Type": "application/json",
},
})
.catch((e) => {
console.error("请求出错:", e);
});
}
} catch (error) {
console.error("axios is not available, please install it.");
}
}
module.exports = {
postVersionFileAndMsg,
};