From e543987baa3be2e12dc1372301d794d71afc45ae Mon Sep 17 00:00:00 2001 From: caishi Date: Wed, 17 Nov 2021 16:46:59 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BB=A3=E7=A0=81=E8=B4=A8?= =?UTF-8?q?=E9=87=8F=E5=88=86=E6=9E=90=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/forge/Main/CoderDepot.jsx | 4 +- src/forge/Main/Detail.js | 13 +++- src/forge/Main/sub/DetailBanner.jsx | 6 ++ src/forge/Sonar/Index.jsx | 117 ++++++++++++++++++++++++++++ 4 files changed, 137 insertions(+), 3 deletions(-) create mode 100644 src/forge/Sonar/Index.jsx diff --git a/src/forge/Main/CoderDepot.jsx b/src/forge/Main/CoderDepot.jsx index 7507ae5c..9fdd8f14 100644 --- a/src/forge/Main/CoderDepot.jsx +++ b/src/forge/Main/CoderDepot.jsx @@ -140,7 +140,7 @@ function CoderDepot(props){ if(result && result.data){ const release = { "list":result.data.releases, - "total_count":result.data.releases.length + "total_count":result.data.releases ? result.data.releases.length :0 } setReleaseVersions(release); } @@ -565,7 +565,7 @@ function CoderDepot(props){
-

sonar质量分析

+

质量分析

{ sonar_url ? {sonar_url} diff --git a/src/forge/Main/Detail.js b/src/forge/Main/Detail.js index 96b14b17..02e52b37 100644 --- a/src/forge/Main/Detail.js +++ b/src/forge/Main/Detail.js @@ -69,7 +69,11 @@ const MergeIndexDetail = Loadable({ loader: () => import('../Merge/merge'), loading: Loading, }) - +// 代码质量分析 +const Sonar = Loadable({ + loader: () => import('../Sonar/Index'), + loading: Loading, +}) const CreateMerge = Loadable({ loader: () => import('../Merge/CreateMerge'), loading: Loading, @@ -167,6 +171,8 @@ function checkPathname(projectsId, owner, pathname) { name = "source" } else if (url.indexOf(`/wiki`) > -1) { name = "wiki" + } else if (url.indexOf(`/sonar`) > -1) { + name = "sonar" } } return name; @@ -772,6 +778,11 @@ class Detail extends Component { (props) => () } > + () + } + > () diff --git a/src/forge/Main/sub/DetailBanner.jsx b/src/forge/Main/sub/DetailBanner.jsx index 22a5ce41..91fed5a4 100644 --- a/src/forge/Main/sub/DetailBanner.jsx +++ b/src/forge/Main/sub/DetailBanner.jsx @@ -128,6 +128,12 @@ function DetailBanner({ history,list , owner , projectsId , isManager , url , pa ) }) } +
  • + + + 代码质量分析 + +
  • : diff --git a/src/forge/Sonar/Index.jsx b/src/forge/Sonar/Index.jsx new file mode 100644 index 00000000..7aa0a09c --- /dev/null +++ b/src/forge/Sonar/Index.jsx @@ -0,0 +1,117 @@ +import React , { useEffect , useState } from 'react'; +import { Table , Pagination } from 'antd'; +import { Base64 } from 'js-base64'; +import moment from 'moment' +import axios from 'axios'; +import Nodata from '../Nodata'; + +const limit = 15; + +function Index(props) { + const [ page , setPage ] = useState(1); + const [ total , setTotal ] = useState(0); + const [ data , setData ] = useState(undefined); + const { owner , projectsId } = props.match.params; + + useEffect(()=>{ + getInit(); + },[page]) + + function getInit() { + // MLh8klm46f_ceshi + const url = `http://sonar.learnerhub.net/api/issues/search?componentKeys=${owner}_${projectsId}&s=FILE_LINE&resolved=false&types=BUG&ps=${limit}&facets=owaspTop10%2CsansTop25%2Cseverities%2CsonarsourceSecurity%2Ctypes&additionalFields=_all&timeZone=Asia%2FShanghai&p=${page}` + axios.get(url,{ + headers:{Authorization:`Basic ${Base64.encode('ecae161ce05add6121c6263f843c76d79fcd953c:')}`} + }).then(result=>{ + if(result){ + setData(result.data.issues); + setTotal(result.data.total); + } + }).catch(error=>{}) + } + + const columns = [ + { + title: '文件', + dataIndex: 'component', + key: 'component', + width:"24%", + ellipsis:true, + render:(v,l,i)=>{ + const name = l.component && l.component.split(":")[1]; + return( + {name} + ) + } + }, + { + title: '所在起始行', + dataIndex: 'startLine', + key: 'startLine', + align:"center", + width:"9%", + render:(v,l,i)=>{ + return( + {l.textRange && l.textRange.startLine} + ) + } + }, + { + title: '所在结束行', + dataIndex: 'endLine', + key: 'endLine', + align:"center", + width:"9%", + render:(v,l,i)=>{ + return( + {l.textRange && l.textRange.endLine} + ) + } + }, + // { + // title: '错误类型', + // dataIndex: 'type', + // align:"center", + // key: 'type', + // width:"8%", + // }, + { + title: '问题信息', + dataIndex: 'message', + key: 'message', + width:"25%", + ellipsis:true + }, + { + title: '创建时间', + dataIndex: 'creationDate', + key: 'creationDate', + align:"center", + render:(v,l,i)=>{ + return( + {l.creationDate && moment(l.creationDate).format('YYYY-MM-DD HH:mm:ss')} + ) + } + }, + ]; + return( +
    + { + total > 0 ? +
    +

    一共存在{total}个问题

    + + + : + + } + { + total > limit && +
    + setPage(p)}/> +
    + } + + ) +} +export default Index \ No newline at end of file