From 830b96cdc96d390046d0c2f1e7d4f70051445823 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E5=BF=83=E5=AE=87?= Date: Sat, 7 Jun 2025 15:02:28 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=87=8D=E6=96=B0=E5=88=86?= =?UTF-8?q?=E6=9E=90=E6=8C=89=E9=92=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/forge/Server/api.js | 10 +++- src/forge/Server/quality/detail.scss | 16 ++++++ src/forge/Server/quality/index.jsx | 74 ++++++++++++++++------------ 3 files changed, 68 insertions(+), 32 deletions(-) diff --git a/src/forge/Server/api.js b/src/forge/Server/api.js index 2c894ea76..4ff1ac9ed 100644 --- a/src/forge/Server/api.js +++ b/src/forge/Server/api.js @@ -44,7 +44,7 @@ export function initSonar(open, owner, repo) { } // 开始分析 -export function startAlalyze( branch , owner, repo) { +export function startAnalyze( branch , owner, repo) { return fetch({ url: `/api/v1/${owner}/${repo}/sonarqubes/insert_file.json?branch=${ branch }`, method: 'post', @@ -67,6 +67,14 @@ export function getActionList(owner, repo ) { }); } +// 重新运行分析 +export function reAnalize(owner, repo, branch ) { + return fetch({ + url: `/api/v1/${owner}/${repo}/actions/runs?ref=${ branch }&workflow=SonarScanner.yaml`, + method: 'post', + }); +} + // 获取classes、files地址 export function getAnalizeUrl(owner, repo ) { return fetch({ diff --git a/src/forge/Server/quality/detail.scss b/src/forge/Server/quality/detail.scss index 389ea8db0..0886dd27c 100644 --- a/src/forge/Server/quality/detail.scss +++ b/src/forge/Server/quality/detail.scss @@ -321,6 +321,21 @@ } .issue-total { font-family: 'alibabaReg'; + display: flex; + align-items: center; + flex-direction: column; + .reanalize { + display: inline-block; + color: rgb(255, 255, 255); + background: linear-gradient(89.95deg, rgb(18, 97, 255) 0.01%, rgb(65, 77, 241) 99.99%); + border-radius: 9px; + padding: 4px 14px; + cursor: pointer; + } + .result-box { + margin-top: 20px; + width: 100%; + } .nodata { height: 100%; display: flex; @@ -636,6 +651,7 @@ } .headBox{ + width: 100%; height:60px; line-height: 60px; background-color:#fafcff; diff --git a/src/forge/Server/quality/index.jsx b/src/forge/Server/quality/index.jsx index d848c0da6..ff20e4630 100644 --- a/src/forge/Server/quality/index.jsx +++ b/src/forge/Server/quality/index.jsx @@ -1,5 +1,5 @@ import React, { useState, useEffect, Fragment, useRef } from "react"; -import { getList, getProblemDetail, getProblemData, initSonar, startAlalyze, getActionList, getAnalizeUrl } from "../api"; +import { getList, getProblemDetail, getProblemData, initSonar, startAnalyze, getActionList, getAnalizeUrl, reAnalize } from "../api"; import './detail.scss'; import ProblemDetail from "./component/ProblemDetail"; import { issueType, maintainability, issueTypeIcon, maintainabilityIcon, labelIcon } from "../constants/quality"; @@ -67,10 +67,6 @@ function IssueList(props) { const timeRef = useRef(); useEffect(() => { - console.log(props); - - console.log(projectDetail); - if (projectDetail) { const { author, name } = projectDetail; document.title = `代码质量分析-${author.name}/${name}`; @@ -117,6 +113,31 @@ function IssueList(props) { }; }, [url]); // 如果 URL 改变,重新绑定监听器 + useEffect(() => { + if (pageNum === 1) { + getIssueList() + } else { + setPageNum(1) + } + }, [selectedType, selectedSeverity, selectedTag]); + + useEffect(() => { + if (projectDetail && analysisStatus === actionStatus.success) { + getIssueList() + } + }, [pageNum, pageSize]); + + useEffect(() => { + if (!tagShowMore) { + setTimeout(() => { + setTagShowMoreDelay(tagShowMore) + }, 450); + } else { + setTagShowMoreDelay(tagShowMore) + } + }, [tagShowMore]) + + const clearTimer = () => { if (timeRef.current) { clearTimeout(timeRef.current); @@ -212,30 +233,6 @@ function IssueList(props) { }); }; - useEffect(() => { - if (pageNum === 1) { - getIssueList() - } else { - setPageNum(1) - } - }, [selectedType, selectedSeverity, selectedTag]); - - useEffect(() => { - if (projectDetail && analysisStatus === actionStatus.success) { - getIssueList() - } - }, [pageNum, pageSize]); - - useEffect(() => { - if (!tagShowMore) { - setTimeout(() => { - setTagShowMoreDelay(tagShowMore) - }, 450); - } else { - setTagShowMoreDelay(tagShowMore) - } - }, [tagShowMore]) - const detail = (e) => { setSelectedIssue(e); getProblemDetail(e.rule, owner, projectsId).then(res => { @@ -349,7 +346,7 @@ function IssueList(props) { setLoading(true) initSonar(true, owner, projectsId).then(res => { if (res.status === 0) { - startAlalyze(projectDetail.default_branch, owner, projectsId).then(res1=> { + startAnalyze(projectDetail.default_branch, owner, projectsId).then(res1=> { if (res1.status === 0) { message.success('创建分析成功,请等待分析完成') setAnalysisStatus(actionStatus.waiting) @@ -366,6 +363,20 @@ function IssueList(props) { }) } + const reRunAnalize = () => { + setLoading(true) + reAnalize(owner, projectsId, projectDetail.default_branch).then(res => { + if (res.status === 0) { + message.success('重新分析成功,请等待分析完成') + setAnalysisStatus(actionStatus.waiting) + if (timeRef.current) clearTimer(); + timeRef.current = setTimeout(() => { + getAction() + }, 3000); + } + }) + } + // 开始按钮状态 const getStatusButton = () => { switch (analysisStatus) { @@ -403,6 +414,7 @@ function IssueList(props) { issueDetail={issueInfo} onClose={() => setDetailVisible(false)} /> + { analysisStatus === actionStatus.success && 重新分析 } { analysisStatus !== actionStatus.success &&
sonar代码质量分析工具
@@ -418,7 +430,7 @@ function IssueList(props) {
} { - analysisStatus === actionStatus.success &&
+ analysisStatus === actionStatus.success &&

软件质量统计结果,全方位精准定位问题