查询代码度量概要 - ShowTaskCmetrics
功能介绍
根据检查任务ID查询代码度量概要,包含代码行数、圈复杂度等度量指标。
调用方法
请参见如何调用API。
授权信息
账号根用户具备所有API的调用权限,如果使用账号下的IAM用户调用当前API,该IAM用户需具备如下身份策略权限,更多的权限说明请参见权限和授权项。
|
授权项 |
访问级别 |
资源类型(*为必须) |
条件键 |
别名 |
依赖的授权项 |
|---|---|---|---|---|---|
|
codeartscheck:task:getReport |
Read |
task * |
- |
- |
- |
|
- |
codeartscheck:ProjectId |
URI
GET /v2/{project_id}/tasks/{task_id}/metrics-summary
请求参数
|
参数 |
是否必选 |
参数类型 |
描述 |
|---|---|---|---|
|
X-Auth-Token |
是 |
String |
参数解释: 用户Token。 通过调用IAM服务获取用户Token接口获取(响应消息头中X-Subject-Token的值)。 约束限制: 不涉及。 取值范围: 长度为[1~100000]个字符。 默认取值: 不涉及。 |
响应参数
状态码:200
|
参数 |
参数类型 |
描述 |
|---|---|---|
|
task_id |
String |
参数解释: 旧版任务ID。 取值范围: 不涉及。 |
|
task_name |
String |
参数解释: 任务名称。 取值范围: 不涉及。 |
|
creator_id |
String |
参数解释: 任务创建者用户ID。 取值范围: 不涉及。 |
|
git_url |
String |
参数解释: 代码仓地址。 取值范围: 不涉及。 |
|
git_branch |
String |
参数解释: 代码仓分支。 取值范围: 不涉及。 |
|
last_check_time |
String |
参数解释: 上一次检查时间。使用UTC时间,格式为yyyy-MM-ddTHH:mm:ssZ。例如:2020-09-25T12:05:00Z。 取值范围: 不涉及。 |
|
last_exec_time |
String |
参数解释: 上一次检查时间。使用UTC时间,格式为yyyy-MM-ddTHH:mm:ssZ。例如:2020-09-25T12:05:00Z。 取值范围: 不涉及。 |
|
last_check_finish_time |
String |
参数解释: 上次执行结束时间。使用UTC时间,格式为yyyy-MM-ddTHH:mm:ssZ。例如:2020-09-25T12:05:00Z。 取值范围: 不涉及。 |
|
check_type |
String |
参数解释: 检查类型。 取值范围: 不涉及。 |
|
created_at |
String |
参数解释: 任务创建时间。使用UTC时间,格式为yyyy-MM-ddTHH:mm:ssZ。例如:2020-09-25T12:05:00Z。 取值范围: 不涉及。 |
|
metric_info |
MetricInfo object |
参数解释: 度量项。 |
|
参数 |
参数类型 |
描述 |
|---|---|---|
|
code_size |
String |
参数解释: 有效代码行数,不包含空行和注释行。 取值范围: 不涉及。 |
|
raw_lines |
String |
参数解释: 原始代码行数,包含空行和注释行。 取值范围: 不涉及。 |
|
methods_total |
String |
参数解释: 函数总数。 取值范围: 不涉及。 |
|
cyclomatic_complexity_total |
String |
参数解释: 圈复杂度总数。 取值范围: 不涉及。 |
|
cyclomatic_complexity_per_method |
String |
参数解释: 平均圈复杂度。 取值范围: 不涉及。 |
|
maximum_cyclomatic_complexity |
String |
参数解释: 最大圈复杂度。 取值范围: 不涉及。 |
|
huge_cyclomatic_complexity_total |
String |
参数解释: 超大圈复杂度函数总数。 取值范围: 不涉及。 |
|
huge_cyclomatic_complexity_ratio |
String |
参数解释: 超大圈复杂度函数占比。 取值范围: 不涉及。 |
|
cca_cyclomatic_complexity_total |
String |
参数解释: CCA圈复杂度总数。 取值范围: 不涉及。 |
|
cca_cyclomatic_complexity_per_method |
String |
参数解释: CCA平均圈复杂度。 取值范围: 不涉及。 |
|
maximum_cca_cyclomatic_complexity |
String |
参数解释: CCA最大圈复杂度。 取值范围: 不涉及。 |
|
huge_cca_cyclomatic_complexity_total |
String |
参数解释: 超大CCA圈复杂度函数总数。 取值范围: 不涉及。 |
|
cyclomatic_complexity_adequacy |
String |
参数解释: 圈复杂度阈值遵从度。 取值范围: 不涉及。 |
|
maximum_depth |
String |
参数解释: 最大深度。 取值范围: 不涉及。 |
|
huge_depth_total |
String |
参数解释: 超大深度个数。 取值范围: 不涉及。 |
|
huge_depth_ratio |
String |
参数解释: 超大深度占比。 取值范围: 不涉及。 |
|
method_lines |
String |
参数解释: 函数总行数。 取值范围: 不涉及。 |
|
lines_per_method |
String |
参数解释: 平均函数代码行。 取值范围: 不涉及。 |
|
huge_method_total |
String |
参数解释: 超大代码行函数数。 取值范围: 不涉及。 |
|
huge_method_ratio |
String |
参数解释: 超大代码行函数占比。 取值范围: 不涉及。 |
|
files_total |
String |
参数解释: 文件总数。 取值范围: 不涉及。 |
|
folders_total |
String |
参数解释: 目录总数。 取值范围: 不涉及。 |
|
lines_per_file |
String |
参数解释: 平均文件代码行。 取值范围: 不涉及。 |
|
huge_headerfile_total |
String |
参数解释: 超大头文件数。 取值范围: 不涉及。 |
|
huge_headerfile_ratio |
String |
参数解释: 超大头文件占比。 取值范围: 不涉及。 |
|
huge_non_headerfile_total |
String |
参数解释: 超大源文件数。 取值范围: 不涉及。 |
|
huge_non_headerfile_ratio |
String |
参数解释: 超大源文件占比。 取值范围: 不涉及。 |
|
huge_folder_total |
String |
参数解释: 超大目录数。 取值范围: 不涉及。 |
|
huge_folder_ratio |
String |
参数解释: 超大目录占比。 取值范围: 不涉及。 |
|
file_duplication_total |
String |
参数解释: 重复文件数。 取值范围: 不涉及。 |
|
file_duplication_ratio |
String |
参数解释: 文件重复率。 取值范围: 不涉及。 |
|
non_hfile_duplication_total |
String |
参数解释: 重复源文件数。 取值范围: 不涉及。 |
|
non_hfile_duplication_ratio |
String |
参数解释: 源文件重复率。 取值范围: 不涉及。 |
|
code_duplication_total |
String |
参数解释: 代码重复数。 取值范围: 不涉及。 |
|
code_duplication_ratio |
String |
参数解释: 代码重复率。 取值范围: 不涉及。 |
|
non_hfile_code_duplication_total |
String |
参数解释: 源文件代码重复数。 取值范围: 不涉及。 |
|
non_hfile_code_duplication_ratio |
String |
参数解释: 源文件代码重复率。 取值范围: 不涉及。 |
|
unsafe_functions_total |
String |
参数解释: 危险函数总数。 取值范围: 不涉及。 |
|
unsafe_functions_kloc |
String |
参数解释: 危险函数密度。 取值范围: 不涉及。 |
|
redundant_code_total |
String |
参数解释: 冗余代码数。 取值范围: 不涉及。 |
|
redundant_code_kloc |
String |
参数解释: 冗余代码密度。 取值范围: 不涉及。 |
|
warning_suppression_total |
String |
参数解释: 抑制告警数。 取值范围: 不涉及。 |
|
warning_suppression_kloc |
String |
参数解释: 抑制告警密度。 取值范围: 不涉及。 |
状态码:400
|
参数 |
参数类型 |
描述 |
|---|---|---|
|
error_code |
String |
参数解释: 错误码。 取值范围: 不涉及。 |
|
error_msg |
String |
参数解释: 错误描述。 取值范围: 不涉及。 |
状态码:401
|
参数 |
参数类型 |
描述 |
|---|---|---|
|
error_code |
String |
参数解释: 错误码。 取值范围: 不涉及。 |
|
error_msg |
String |
参数解释: 错误描述。 取值范围: 不涉及。 |
请求示例
在ID为e04b357xxxxx5ed832xxxxxx的项目下,查询ID为2b31ed520xxxxxxebedb6e57xxxxxxxx的任务的代码度量概要。
GET https://{endpoint}/v2/e04b357xxxxx5ed832xxxxxx/tasks/2b31ed520xxxxxxebedb6e57xxxxxxxx/metrics-summary
响应示例
状态码:200
Request succeeded!
{
"task_id" : "435b58ecf7f54c45907c1384d01c94a6",
"task_name" : "CSharp_02201119",
"creator_id" : "ecadebb5041146cc96f9780f3d905e20",
"git_url" : "git@****_02201119.git",
"git_branch" : "master",
"last_check_time" : "2020-02-20 11:37:46",
"last_exec_time" : "2020-02-20 11:37:46",
"last_check_finish_time" : "2020-02-20 11:53:46",
"check_type" : "source",
"created_at" : "2020-02-20 11:21:11",
"metric_info" : {
"code_size" : "133426.00",
"raw_lines" : "182082.00",
"methods_total" : "6840.00",
"cyclomatic_complexity_total" : "27435.00",
"cyclomatic_complexity_per_method" : "7.43",
"maximum_cyclomatic_complexity" : "346.00",
"huge_cyclomatic_complexity_total" : "167.00",
"huge_cyclomatic_complexity_ratio" : "4.13",
"cca_cyclomatic_complexity_total" : "26693.00",
"cca_cyclomatic_complexity_per_method" : "7.25",
"maximum_cca_cyclomatic_complexity" : "342.00",
"huge_cca_cyclomatic_complexity_total" : "148.00",
"cyclomatic_complexity_adequacy" : "21.00",
"maximum_depth" : "333.00",
"huge_depth_total" : "8.85",
"huge_depth_ratio" : "91546.00",
"method_lines" : "24.91",
"lines_per_method" : "8.04",
"huge_method_total" : "12300",
"huge_method_ratio" : "12300",
"files_total" : "629.00",
"folders_total" : "426.00",
"lines_per_file" : "12300",
"huge_headerfile_total" : "12300",
"huge_headerfile_ratio" : "12300",
"huge_non_headerfile_total" : "12300",
"huge_non_headerfile_ratio" : "12300",
"huge_folder_total" : "12300",
"huge_folder_ratio" : "12300",
"file_duplication_total" : "12300",
"file_duplication_ratio" : "12300",
"non_hfile_duplication_total" : "12300",
"non_hfile_duplication_ratio" : "12300",
"code_duplication_total" : "3.28",
"code_duplication_ratio" : "11782.00",
"non_hfile_code_duplication_total" : "8.59",
"non_hfile_code_duplication_ratio" : "11782.00",
"unsafe_functions_total" : "17.17",
"unsafe_functions_kloc" : "0.00",
"redundant_code_total" : "0.00",
"redundant_code_kloc" : "674.00",
"warning_suppression_total" : "17.00",
"warning_suppression_kloc" : "0.45"
}
}
状态码:400
Bad Request
{
"error_code" : "CC.xxxxxxxx.400",
"error_msg" : "请求参数校验失败,请检查请求参数是否正确"
}
状态码:401
Unauthorized
{
"error_code" : "CC.00000003",
"error_msg" : "认证信息过期"
}
SDK代码示例
SDK代码示例如下。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
package com.huaweicloud.sdk.test; import com.huaweicloud.sdk.core.auth.ICredential; import com.huaweicloud.sdk.core.auth.BasicCredentials; import com.huaweicloud.sdk.core.exception.ConnectionException; import com.huaweicloud.sdk.core.exception.RequestTimeoutException; import com.huaweicloud.sdk.core.exception.ServiceResponseException; import com.huaweicloud.sdk.codecheck.v2.region.CodeCheckRegion; import com.huaweicloud.sdk.codecheck.v2.*; import com.huaweicloud.sdk.codecheck.v2.model.*; public class ShowTaskCmetricsSolution { public static void main(String[] args) { // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment String ak = System.getenv("CLOUD_SDK_AK"); String sk = System.getenv("CLOUD_SDK_SK"); ICredential auth = new BasicCredentials() .withAk(ak) .withSk(sk); CodeCheckClient client = CodeCheckClient.newBuilder() .withCredential(auth) .withRegion(CodeCheckRegion.valueOf("<YOUR REGION>")) .build(); ShowTaskCmetricsRequest request = new ShowTaskCmetricsRequest(); request.withProjectId("{project_id}"); request.withTaskId("{task_id}"); try { ShowTaskCmetricsResponse response = client.showTaskCmetrics(request); System.out.println(response.toString()); } catch (ConnectionException e) { e.printStackTrace(); } catch (RequestTimeoutException e) { e.printStackTrace(); } catch (ServiceResponseException e) { e.printStackTrace(); System.out.println(e.getHttpStatusCode()); System.out.println(e.getRequestId()); System.out.println(e.getErrorCode()); System.out.println(e.getErrorMsg()); } } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# coding: utf-8 import os from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdkcodecheck.v2.region.codecheck_region import CodeCheckRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkcodecheck.v2 import * if __name__ == "__main__": # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment ak = os.environ["CLOUD_SDK_AK"] sk = os.environ["CLOUD_SDK_SK"] credentials = BasicCredentials(ak, sk) client = CodeCheckClient.new_builder() \ .with_credentials(credentials) \ .with_region(CodeCheckRegion.value_of("<YOUR REGION>")) \ .build() try: request = ShowTaskCmetricsRequest() request.project_id = "{project_id}" request.task_id = "{task_id}" response = client.show_task_cmetrics(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" codecheck "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/codecheck/v2" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/codecheck/v2/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/codecheck/v2/region" ) func main() { // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment ak := os.Getenv("CLOUD_SDK_AK") sk := os.Getenv("CLOUD_SDK_SK") auth := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). Build() client := codecheck.NewCodeCheckClient( codecheck.CodeCheckClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). Build()) request := &model.ShowTaskCmetricsRequest{} request.ProjectId = "{project_id}" request.TaskId = "{task_id}" response, err := client.ShowTaskCmetrics(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } } |
更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。
状态码
|
状态码 |
描述 |
|---|---|
|
200 |
Request succeeded! |
|
400 |
Bad Request |
|
401 |
Unauthorized |
错误码
请参见错误码。