diff --git a/.gitattributes b/01.gitattributes similarity index 92% rename from .gitattributes rename to 01.gitattributes index c9ba5bfc403600a8c9418fd4503574bcb69dc87e..a54b7efe2cfd678264b73c624fb1fd0ebae87a02 100644 --- a/.gitattributes +++ b/01.gitattributes @@ -2,3 +2,4 @@ *.[ch] diff=cpp *.dts diff=dts *.dts[io] diff=dts +fffffff \ No newline at end of file diff --git a/ffff/ffff/ffff/js.js b/ffff/ffff/ffff/js.js new file mode 100644 index 0000000000000000000000000000000000000000..7797369026dffcc3bfa8a84690ed99a87dadece4 --- /dev/null +++ b/ffff/ffff/ffff/js.js @@ -0,0 +1,98 @@ +import axios from 'axios'; +import debounce from 'lodash/debounce' +import { makeTrans } from "shared/lib/i18n-trans"; +const apiUrl = `${window.gon.scan_api_host}/iscan/openapi/rest/v2/task/pr/sums`; +const t = makeTrans({ + "zh-CN": { + specification_problem: "规范问题 {styleCount} 个", + defect_problem: "缺陷问题 {bugCount} 个", + }, + "zh-TW": { + specification_problem: "規範問題 {styleCount} 个", + defect_problem: "缺陷問題 {bugCount} 个", + }, + en: { + specification_problem: "{styleCount} normative problems", + defect_problem: "{bugCount} defect problems", + }, +}); +const preLoadMap = new Map(); + +// 批量获取 +const trigger = debounce(async () => { + try { + const curLoadMap = Object.fromEntries(preLoadMap); + preLoadMap.clear(); + + const ids = Object.keys(curLoadMap).slice(0, 100); + + const header = {}; + if (window.gon.enterprise_id) { + header.xly_enterprise_id = window.gon.enterprise_id; + } + if (window.gon.project_id) { + header.xly_repo_id = window.gon.project_id; + } + axios.defaults.withCredentials = true; + + const res = await axios.post(apiUrl, ids, { + headers: header, + }); + + ids.forEach((id) => { + const callback = curLoadMap[id]; + if (callback) { + if (res && res.data && res.data.data) { + const result = res.data.data.find((i) => String(i.prId) === id); + callback(result); + } else { + callback(); + } + } + }); + } catch (e) { + console.log(e); + } +}, 200); + +function batchFetchStatus(prId, callback) { + preLoadMap.set(prId, callback); + trigger(); +} + +class ScanStatusElement extends HTMLElement { + connectedCallback() { + const that = this; + const prId = Number(this.getAttribute("pull-id")); + if (!prId && !Number.isNaN(prId)) return; + + batchFetchStatus(prId, (args) => { + if (!args || (!args.styleCount && !args.bugCount)) return; + let styleCount = args.styleCount; + let bugCount = args.bugCount; + let html = + ''; + if (args.styleCount && args.bugCount) { + html += ` ${t("specification_problem", { styleCount })},${t( + "defect_problem", + { bugCount } + )} `; + } else if (args.styleCount) { + html += ` ${t("specification_problem", { styleCount })} `; + } else if (args.bugCount) { + html += ` ${t("defect_problem", { bugCount })}`; + } + html += ""; + + const wrap = document.createElement("div"); + wrap.className = 'd-inline-block'; + wrap.innerHTML = html; + that.append(wrap); + }); + } +} + +if (!window.customElements.get('scan-status')) { + window.ScanStatusElement = ScanStatusElement; + window.customElements.define('scan-status', ScanStatusElement); +} diff --git a/fffff/fffff/fffff/fffff/fffffffffffffff/fffffffffffffff/fffffffffffffff/fffffffffffffff/fffffff/fffffff/fffffff/fffffff/dd.js b/fffff/fffff/fffff/fffff/fffffffffffffff/fffffffffffffff/fffffffffffffff/fffffffffffffff/fffffff/fffffff/fffffff/fffffff/dd.js index 145d8bc3992e98a819d617a140f0613ad7dfa1d5..8acfb39f6099ea139dfc3fb143cb315af0efce76 100644 --- a/fffff/fffff/fffff/fffff/fffffffffffffff/fffffffffffffff/fffffffffffffff/fffffffffffffff/fffffff/fffffff/fffffff/fffffff/dd.js +++ b/fffff/fffff/fffff/fffff/fffffffffffffff/fffffffffffffff/fffffffffffffff/fffffffffffffff/fffffff/fffffff/fffffff/fffffff/dd.js @@ -1 +1 @@ -ffff1 \ No newline at end of file +ffff14444 \ No newline at end of file