查询单个问题详情和上下文代码 - GetSingleDefect
功能介绍
根据MergeKey查询某个问题的详细信息及上下文代码。
调用方法
请参见如何调用API。
授权信息
账号根用户具备所有API的调用权限,如果使用账号下的IAM用户调用当前API,该IAM用户需具备如下身份策略权限,更多的权限说明请参见权限和授权项。
|
授权项 |
访问级别 |
资源类型(*为必须) |
条件键 |
别名 |
依赖的授权项 |
|---|---|---|---|---|---|
|
codeartscheck:task:getReport |
Read |
task * |
- |
- |
- |
|
- |
codeartscheck:ProjectId |
URI
GET /v1/defect
|
参数 |
是否必选 |
参数类型 |
描述 |
|---|---|---|---|
|
task_id |
是 |
String |
参数解释: 任务ID,即新建检查任务接口的返回值,每个代码检查任务及其下的分支任务、通过API创建的增量任务都有唯一的任务ID。即查询任务列表接口响应中的id字段。 约束限制: 不涉及。 取值范围: 长度为[1~32]个字符。 默认取值: 不涉及。 |
|
merge_id |
否 |
String |
参数解释: 合并请求ID或Commit ID,主要用于查询门禁级任务。 约束限制: 不涉及。 取值范围: 不涉及。 默认取值: 不涉及。 |
|
job_id |
否 |
String |
参数解释: 执行记录ID,即每一次执行版本级或门禁级扫描的唯一ID,主要用于查询门禁级任务。 约束限制: 不涉及。 取值范围: 不涉及。 默认取值: 不涉及。 |
|
merge_key |
是 |
String |
参数解释: MergeKey,问题ID。 约束限制: 不涉及。 取值范围: 不涉及。 默认取值: 不涉及。 |
请求参数
响应参数
状态码:200
|
参数 |
参数类型 |
描述 |
|---|---|---|
|
status |
String |
参数解释: 响应状态。 取值范围: |
|
result |
SingleDefectAndContext object |
参数解释: 问题的详细信息及上下文代码。 |
|
参数 |
参数类型 |
描述 |
|---|---|---|
|
approver |
String |
参数解释: 问题忽略的审核人用户名。 取值范围: 不涉及。 |
|
language |
String |
参数解释: 编程语言。 取值范围: |
|
filePath |
String |
参数解释: 文件路径。 取值范围: 不涉及。 |
|
line |
Integer |
参数解释: 问题所在行号。 取值范围: 不涉及。 |
|
functionName |
String |
参数解释: 问题所在函数名。 取值范围: 不涉及。 |
|
checkerName |
String |
参数解释: 工具名称。 取值范围: 不涉及。 |
|
checkerVersion |
String |
参数解释: 工具版本。 取值范围: 不涉及。 |
|
ruleName |
String |
参数解释: 工具规则名称。 取值范围: 不涉及。 |
|
defectLevel |
String |
参数解释: 问题级别。 取值范围: |
|
createdAt |
String |
参数解释: 问题发现时间,使用UTC时间,格式为yyyy-MM-ddTHH:mm:ssZ。例如:2020-09-25T12:05:00Z。 取值范围: 不涉及。 |
|
criterionName |
String |
参数解释: 规则名称。 取值范围: 不涉及。 |
|
defectStatus |
String |
参数解释: 问题状态。 取值范围: |
|
occursInfo |
OccursInfo object |
参数解释: 代码片段信息。 |
|
nickName |
String |
参数解释: 问题责任人。 取值范围: 不涉及。 |
|
statusComment |
Array of Comment objects |
参数解释: 问题操作历史。 |
|
ruleId |
String |
参数解释: 规则ID。 取值范围: 不涉及。 |
|
参数 |
参数类型 |
描述 |
|---|---|---|
|
occurId |
String |
参数解释: 问题代码片段ID。 取值范围: 不涉及。 |
|
occurDescription |
String |
参数解释: 问题描述。 取值范围: 不涉及。 |
|
engine |
String |
参数解释: 工具名称。 取值范围: 不涉及。 |
|
sourceCodeUrl |
String |
参数解释: 源码文件URL。 取值范围: 不涉及。 |
|
events |
Array of Events objects |
参数解释: 调用链信息。 |
|
参数 |
参数类型 |
描述 |
|---|---|---|
|
description |
String |
参数解释: 问题详细描述。 取值范围: 不涉及。 |
|
fixSuggestions |
Array of strings |
参数解释: 修复建议。 |
|
line |
Integer |
参数解释: 问题所在文件行号。 取值范围: 不涉及。 |
|
startLine |
Integer |
参数解释: 废弃字段。 取值范围: 不涉及。 |
|
endLine |
Integer |
参数解释: 废弃字段。 取值范围: 不涉及。 |
|
main |
Boolean |
参数解释: 废弃字段。 取值范围: 不涉及。 |
|
path |
String |
参数解释: 文件路径。 取值范围: 不涉及。 |
|
tag |
String |
参数解释: 废弃字段。 取值范围: 不涉及。 |
|
mainBuggyCode |
String |
参数解释: 问题主事件对应的代码片段内容。 取值范围: 不涉及。 |
|
codeContext |
String |
参数解释: 废弃字段。 取值范围: 不涉及。 |
|
codeContextStartLine |
Integer |
参数解释: 代码上下文起始行号。 取值范围: 不涉及。 |
|
codePassage |
Array of CodeLine objects |
参数解释: 代码上下文。 |
|
events |
Array of DefectEvents objects |
参数解释: 调用链信息。 |
|
参数 |
参数类型 |
描述 |
|---|---|---|
|
lineNumber |
Integer |
参数解释: 行号。 取值范围: 不涉及。 |
|
lineContent |
String |
参数解释: 代码内容。 取值范围: 不涉及。 |
|
参数 |
参数类型 |
描述 |
|---|---|---|
|
events |
Array of DefectEvents objects |
参数解释: 调用链信息。 |
|
description |
String |
参数解释: 问题详细描述。 取值范围: 不涉及。 |
|
fix_suggestions |
Array of strings |
参数解释: 修复建议。 |
|
line |
Integer |
参数解释: 问题所在文件行号。 取值范围: 不涉及。 |
|
end_line |
Integer |
参数解释: 废弃字段。 取值范围: 不涉及。 |
|
main |
Boolean |
参数解释: 废弃字段。 取值范围: 不涉及。 |
|
path |
String |
参数解释: 文件路径。 取值范围: 不涉及。 |
|
tag |
String |
参数解释: 废弃字段。 取值范围: 不涉及。 |
|
main_buggy_code |
String |
参数解释: 问题主事件对应的代码片段内容。 取值范围: 不涉及。 |
|
code_context |
String |
参数解释: 代码上下文。 取值范围: 不涉及。 |
|
code_context_start_line |
Integer |
参数解释: 代码上下文起始行号。 取值范围: 不涉及。 |
|
参数 |
参数类型 |
描述 |
|---|---|---|
|
id |
Integer |
参数解释: 操作历史ID。 取值范围: 不涉及。 |
|
comments |
String |
参数解释: 备注。 取值范围: 长度为[1~256]个字符。 |
|
mergeKey |
String |
参数解释: MergeKey,问题ID。 取值范围: 长度为[1~32]个字符。 |
|
createTime |
String |
参数解释: 发生时间,使用UTC时间,格式为yyyy-MM-ddTHH:mm:ssZ。例如:2020-09-25T12:05:00Z。 取值范围: 不涉及。 |
|
applicant |
String |
参数解释: 操作人。 取值范围: 不涉及。 |
|
statusFrom |
String |
参数解释: 问题起始状态。 取值范围: 不涉及。 |
|
statusTo |
String |
参数解释: 问题目标状态。 取值范围: 不涉及。 |
状态码:400
|
参数 |
参数类型 |
描述 |
|---|---|---|
|
error_code |
String |
参数解释: 错误码。 取值范围: 不涉及。 |
|
error_msg |
String |
参数解释: 错误描述。 取值范围: 不涉及。 |
状态码:401
|
参数 |
参数类型 |
描述 |
|---|---|---|
|
error_code |
String |
参数解释: 错误码。 取值范围: 不涉及。 |
|
error_msg |
String |
参数解释: 错误描述。 取值范围: 不涉及。 |
请求示例
查询ID为897acf5exxx48a5013cd的版本级任务下,MergeKey为08abe0dcxxx817d18e189的问题的详情及上下文。
GET https://{endpoint}/v1/defects?task_id=897acf5exxx48a5013cd&merge_key=08abe0dcxxx817d18e189
响应示例
状态码:200
查询单个问题详情和上下文代码响应体
{
"status" : "success",
"result" : {
"approver" : "devcloud_codecheck_xxxxxx_01",
"language" : "JAVA",
"filePath" : "code/BoolParser.java",
"line" : 255,
"functionName" : "equalityExpression()",
"checkerName" : "sonarqube",
"checkerVersion" : "202406",
"ruleName" : "java:S134",
"defectLevel" : "1",
"createdAt" : "2024-02-04T04:02:07Z",
"criterionName" : "控制流语句\"if\", \"for\", \"while\", \"switch\" and \"try\"不应该嵌套的太深",
"defectStatus" : "5",
"occursInfo" : [ {
"occurId" : "d46c0c8c-8a56-xxx-adc4-xxx63d26",
"occurDescription" : "Refactor this code to not nest more than 3 if/for/while/switch/try statements.",
"ruleUrl" : "",
"engine" : "Sonarqube",
"sourceCodeUrl" : "codehub/2111708128/home?ref=master&isFile=true&filePath=code%2FBoolParser.java",
"events" : [ {
"description" : "Assigning: \"x\" = \"0\".",
"line" : 13,
"path" : "code/BoolParser.java",
"tag" : "",
"mainBuggyCode" : "",
"codeContext" : "",
"codeContextStartLine" : 0,
"codePassage" : [ {
"lineNumber" : 1,
"lineContent" : "// $ANTLR 2.7.7 (20060906): \"src/test/resources/test04.g\" -> \"BoolParser.java\"$"
}, {
"lineNumber" : 2,
"lineContent" : ""
}, {
"lineNumber" : 3,
"lineContent" : "package com.bulain.antlr.bool.ast;"
}, {
"lineNumber" : 4,
"lineContent" : ""
}, {
"lineNumber" : 5,
"lineContent" : "import java.math.*;"
}, {
"lineNumber" : 6,
"lineContent" : "import com.bulain.antlr.util.*;"
}, {
"lineNumber" : 7,
"lineContent" : ""
}, {
"lineNumber" : 8,
"lineContent" : ""
}, {
"lineNumber" : 9,
"lineContent" : "import antlr.TokenBuffer;"
}, {
"lineNumber" : 10,
"lineContent" : "import antlr.TokenStreamException;"
}, {
"lineNumber" : 11,
"lineContent" : "import antlr.TokenStreamIOException;"
}, {
"lineNumber" : 12,
"lineContent" : "import antlr.ANTLRException;"
}, {
"lineNumber" : 13,
"lineContent" : "import antlr.LLkParser;"
}, {
"lineNumber" : 14,
"lineContent" : "import antlr.Token;"
}, {
"lineNumber" : 15,
"lineContent" : "import antlr.TokenStream;"
}, {
"lineNumber" : 16,
"lineContent" : "import antlr.RecognitionException;"
}, {
"lineNumber" : 17,
"lineContent" : "import antlr.NoViableAltException;"
}, {
"lineNumber" : 18,
"lineContent" : "import antlr.MismatchedTokenException;"
}, {
"lineNumber" : 19,
"lineContent" : "import antlr.SemanticException;"
}, {
"lineNumber" : 20,
"lineContent" : "import antlr.ParserSharedInputState;"
}, {
"lineNumber" : 21,
"lineContent" : "import antlr.collections.impl.BitSet;"
}, {
"lineNumber" : 22,
"lineContent" : "import antlr.collections.AST;"
}, {
"lineNumber" : 23,
"lineContent" : "import java.util.Hashtable;"
}, {
"lineNumber" : 24,
"lineContent" : "import antlr.ASTFactory;"
}, {
"lineNumber" : 25,
"lineContent" : "import antlr.ASTPair;"
}, {
"lineNumber" : 26,
"lineContent" : "import antlr.collections.impl.ASTArray;"
}, {
"lineNumber" : 27,
"lineContent" : ""
}, {
"lineNumber" : 28,
"lineContent" : "public class BoolParser extends antlr.LLkParser implements BoolParserTokenTypes"
} ],
"isContextShow" : false,
"startReadParam" : 1,
"endReadParam" : 28
}, {
"description" : "Condition \"cond01(p1)\", taking false branch.",
"line" : 14,
"path" : "code/BoolParser.java",
"tag" : "",
"mainBuggyCode" : "",
"codeContext" : "",
"codeContextStartLine" : 0,
"codePassage" : [ {
"lineNumber" : 1,
"lineContent" : "// $ANTLR 2.7.7 (20060906): \"src/test/resources/test04.g\" -> \"BoolParser.java\"$"
}, {
"lineNumber" : 2,
"lineContent" : ""
}, {
"lineNumber" : 3,
"lineContent" : "package com.bulain.antlr.bool.ast;"
}, {
"lineNumber" : 4,
"lineContent" : ""
}, {
"lineNumber" : 5,
"lineContent" : "import java.math.*;"
}, {
"lineNumber" : 6,
"lineContent" : "import com.bulain.antlr.util.*;"
}, {
"lineNumber" : 7,
"lineContent" : ""
}, {
"lineNumber" : 8,
"lineContent" : ""
}, {
"lineNumber" : 9,
"lineContent" : "import antlr.TokenBuffer;"
}, {
"lineNumber" : 10,
"lineContent" : "import antlr.TokenStreamException;"
}, {
"lineNumber" : 11,
"lineContent" : "import antlr.TokenStreamIOException;"
}, {
"lineNumber" : 12,
"lineContent" : "import antlr.ANTLRException;"
}, {
"lineNumber" : 13,
"lineContent" : "import antlr.LLkParser;"
}, {
"lineNumber" : 14,
"lineContent" : "import antlr.Token;"
}, {
"lineNumber" : 15,
"lineContent" : "import antlr.TokenStream;"
}, {
"lineNumber" : 16,
"lineContent" : "import antlr.RecognitionException;"
}, {
"lineNumber" : 17,
"lineContent" : "import antlr.NoViableAltException;"
}, {
"lineNumber" : 18,
"lineContent" : "import antlr.MismatchedTokenException;"
}, {
"lineNumber" : 19,
"lineContent" : "import antlr.SemanticException;"
}, {
"lineNumber" : 20,
"lineContent" : "import antlr.ParserSharedInputState;"
}, {
"lineNumber" : 21,
"lineContent" : "import antlr.collections.impl.BitSet;"
}, {
"lineNumber" : 22,
"lineContent" : "import antlr.collections.AST;"
}, {
"lineNumber" : 23,
"lineContent" : "import java.util.Hashtable;"
}, {
"lineNumber" : 24,
"lineContent" : "import antlr.ASTFactory;"
}, {
"lineNumber" : 25,
"lineContent" : "import antlr.ASTPair;"
}, {
"lineNumber" : 26,
"lineContent" : "import antlr.collections.impl.ASTArray;"
}, {
"lineNumber" : 27,
"lineContent" : ""
}, {
"lineNumber" : 28,
"lineContent" : "public class BoolParser extends antlr.LLkParser implements BoolParserTokenTypes"
}, {
"lineNumber" : 29,
"lineContent" : " {"
} ],
"isContextShow" : false,
"startReadParam" : 1,
"endReadParam" : 29
}, {
"description" : "In expression \"1 / x\", division by expression \"x\" which may be zero has undefined behavior.",
"line" : 87,
"main" : true,
"path" : "code/BoolParser.java",
"tag" : "",
"mainBuggyCode" : "",
"codeContext" : " // POTENTIAL FLAW: 除零错误\n // POTENTIAL FLAW: 除零错误\n // POTENTIAL FLAW: 除零错误\n // POTENTIAL FLAW: 除零错误\n // POTENTIAL FLAW: 除零错误\n return 1 / x;",
"codeContextStartLine" : 82,
"codePassage" : [ {
"lineNumber" : 72,
"lineContent" : "\t\treturnAST = null;"
}, {
"lineNumber" : 73,
"lineContent" : "\t\tASTPair currentAST = new ASTPair();"
}, {
"lineNumber" : 74,
"lineContent" : "\t\tAST logicalExpression_AST = null;"
}, {
"lineNumber" : 75,
"lineContent" : "\t\t"
}, {
"lineNumber" : 76,
"lineContent" : "\t\ttry { // for error handling"
}, {
"lineNumber" : 77,
"lineContent" : "\t\t\texpression();"
}, {
"lineNumber" : 78,
"lineContent" : "\t\t\tastFactory.addASTChild(currentAST, returnAST);"
}, {
"lineNumber" : 79,
"lineContent" : "\t\t\tlogicalExpression_AST = (AST)currentAST.root;"
}, {
"lineNumber" : 80,
"lineContent" : "\t\t}"
}, {
"lineNumber" : 81,
"lineContent" : "\t\tcatch (RecognitionException ex) {"
}, {
"lineNumber" : 82,
"lineContent" : "\t\t\treportError(ex);"
}, {
"lineNumber" : 83,
"lineContent" : "\t\t\trecover(ex,_tokenSet_0);"
}, {
"lineNumber" : 84,
"lineContent" : "\t\t}"
}, {
"lineNumber" : 85,
"lineContent" : "\t\treturnAST = logicalExpression_AST;"
}, {
"lineNumber" : 86,
"lineContent" : "\t}"
}, {
"lineNumber" : 87,
"lineContent" : "\t"
}, {
"lineNumber" : 88,
"lineContent" : "\tpublic final void expression() throws RecognitionException, TokenStreamException {"
}, {
"lineNumber" : 89,
"lineContent" : "\t\t"
}, {
"lineNumber" : 90,
"lineContent" : "\t\treturnAST = null;"
}, {
"lineNumber" : 91,
"lineContent" : "\t\tASTPair currentAST = new ASTPair();"
}, {
"lineNumber" : 92,
"lineContent" : "\t\tAST expression_AST = null;"
}, {
"lineNumber" : 93,
"lineContent" : "\t\t"
}, {
"lineNumber" : 94,
"lineContent" : "\t\ttry { // for error handling"
}, {
"lineNumber" : 95,
"lineContent" : "\t\t\tlogicalOrExpression();"
}, {
"lineNumber" : 96,
"lineContent" : "\t\t\tastFactory.addASTChild(currentAST, returnAST);"
}, {
"lineNumber" : 97,
"lineContent" : "\t\t\texpression_AST = (AST)currentAST.root;"
}, {
"lineNumber" : 98,
"lineContent" : "\t\t}"
}, {
"lineNumber" : 99,
"lineContent" : "\t\tcatch (RecognitionException ex) {"
}, {
"lineNumber" : 100,
"lineContent" : "\t\t\treportError(ex);"
}, {
"lineNumber" : 101,
"lineContent" : "\t\t\trecover(ex,_tokenSet_1);"
}, {
"lineNumber" : 102,
"lineContent" : "\t\t}"
} ],
"startReadParam" : 72,
"endReadParam" : 102
} ]
} ],
"nickName" : "devcloud_codecheck_xxxxxx_01",
"statusComment" : [ {
"id" : 10636330,
"comments" : "ds",
"mergeKey" : "08abe0xxxxd18e189",
"createTime" : "2024-09-26T03:34:23Z",
"applicant" : "devcloud_codecheck_xxxxxx_01",
"statusFrom" : "4",
"statusTo" : "5"
} ]
}
}
状态码:400
Bad Request
{
"error_code" : "CC.xxxxxxxx.400",
"error_msg" : "请求参数校验失败,请检查请求参数是否正确"
}
状态码:401
Unauthorized
{
"error_code" : "CC.00000003",
"error_msg" : "认证信息过期"
}
状态码
|
状态码 |
描述 |
|---|---|
|
200 |
查询单个问题详情和上下文代码响应体 |
|
400 |
Bad Request |
|
401 |
Unauthorized |
错误码
请参见错误码。