Querying Code Metrics
Function
This API is used to query the code metrics based on a check task ID. The metrics include the number of code lines and cyclomatic complexity.
Calling Method
For details, see Calling APIs.
Authorization Information
Each account root user has all the permissions required to call all APIs, but IAM users must be assigned the following required identity policy-based permissions. For details about the required permissions, see Permissions Policies and Supported Actions.
|
Action |
Access Level |
Resource Type (*: required) |
Condition Key |
Alias |
Dependencies |
|---|---|---|---|---|---|
|
codeartscheck:task:getReport |
Read |
task * |
- |
- |
- |
|
- |
codeartscheck:ProjectId |
URI
GET /v2/{project_id}/tasks/{task_id}/metrics-summary
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
task_id |
Yes |
String |
Definition : Task ID, returned by the API for creating a check task. Each code check task, branch task, or incremental task generated through an API has a unique ID. Obtain the ID by calling the API used to . id indicates the task ID. Constraints: N/A Value range: N/A Default value: N/A |
|
project_id |
Yes |
String |
Definition : 32-character project UUID. Obtain it by calling the API used to query the project list. Constraints: N/A Value range: 1 to 32 characters. Default value: N/A |
Request Parameters
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
X-Auth-Token |
Yes |
String |
Definition : User token. Obtain one by calling the IAM API Obtaining a User Token. The value of X-Subject-Token in the response header is a token. Constraints: N/A Value range: 1–100,000 characters. Default value: N/A |
Response Parameters
Status code: 200
|
Parameter |
Type |
Description |
|---|---|---|
|
task_id |
String |
Definition: ID of a task of the old version. Value range: N/A |
|
task_name |
String |
Definition Task name. Range N/A |
|
creator_id |
String |
Definition User ID of the task creator. Range N/A |
|
git_url |
String |
Definition Code repository address. Range N/A |
|
git_branch |
String |
Definition Code repository branch. Range N/A |
|
last_check_time |
String |
Definition: Last check time. Use UTC time in format "yyyy-MM-ddTHH:mm:ssZ". For example, 2020-09-25T12:05:00Z. Value range: N/A |
|
last_exec_time |
String |
Definition: Last check time. Use UTC time in format "yyyy-MM-ddTHH:mm:ssZ". For example, 2020-09-25T12:05:00Z. Value range: N/A |
|
last_check_finish_time |
String |
Definition: End time of the last execution. Use UTC time in format "yyyy-MM-ddTHH:mm:ssZ". For example, 2020-09-25T12:05:00Z. Value range: N/A |
|
check_type |
String |
Definition Check type. Range N/A |
|
created_at |
String |
Definition: Task creation time. Use UTC time in format "yyyy-MM-ddTHH:mm:ssZ". For example, 2020-09-25T12:05:00Z. Value range: N/A |
|
metric_info |
MetricInfo object |
Definition: Metrics. |
|
Parameter |
Type |
Description |
|---|---|---|
|
code_size |
String |
Definition Valid code lines, excluding blank and comment lines. Range N/A |
|
raw_lines |
String |
Definition Original code lines, including blank and comment lines. Range N/A |
|
methods_total |
String |
Definition Total number of functions. Range N/A |
|
cyclomatic_complexity_total |
String |
Definition Total cyclomatic complexity. Range N/A |
|
cyclomatic_complexity_per_method |
String |
Definition Average cyclomatic complexity. Range N/A |
|
maximum_cyclomatic_complexity |
String |
Definition Maximum cyclomatic complexity. Range N/A |
|
huge_cyclomatic_complexity_total |
String |
Definition Total number of functions with huge cyclomatic complexity. Range N/A |
|
huge_cyclomatic_complexity_ratio |
String |
Definition Percentage of functions with huge cyclomatic complexity. Range N/A |
|
cca_cyclomatic_complexity_total |
String |
Definition Total cyclomatic complexity adequacy (CCA). Range N/A |
|
cca_cyclomatic_complexity_per_method |
String |
Definition Average CCA. Range N/A |
|
maximum_cca_cyclomatic_complexity |
String |
Definition Maximum CCA. Range N/A |
|
huge_cca_cyclomatic_complexity_total |
String |
Definition Total number of functions with huge CCA. Range N/A |
|
cyclomatic_complexity_adequacy |
String |
Definition Cyclomatic complexity adequacy (CCA). Range N/A |
|
maximum_depth |
String |
Definition Maximum depth. Range N/A |
|
huge_depth_total |
String |
Definition Number of functions with huge depth. Range N/A |
|
huge_depth_ratio |
String |
Definition Percentage of functions with huge depth. Range N/A |
|
method_lines |
String |
Definition Total number of function lines. Range N/A |
|
lines_per_method |
String |
Definition Average lines per function. Range N/A |
|
huge_method_total |
String |
Definition Number of functions with excessive lines. Range N/A |
|
huge_method_ratio |
String |
Definition Percentage of functions with excessive lines. Range N/A |
|
files_total |
String |
Definition Total number of files. Range N/A |
|
folders_total |
String |
Definition Total number of directories. Range N/A |
|
lines_per_file |
String |
Definition Average lines per file. Range N/A |
|
huge_headerfile_total |
String |
Definition Number of huge header files. Range N/A |
|
huge_headerfile_ratio |
String |
Definition Percentage of huge header files. Range N/A |
|
huge_non_headerfile_total |
String |
Definition Number of huge source files. Range N/A |
|
huge_non_headerfile_ratio |
String |
Definition Percentage of huge source files. Range N/A |
|
huge_folder_total |
String |
Definition Number of huge directories. Range N/A |
|
huge_folder_ratio |
String |
Definition Percentage of huge directories. Range N/A |
|
file_duplication_total |
String |
Definition Number of duplicate files. Range N/A |
|
file_duplication_ratio |
String |
Definition File duplication rate. Range N/A |
|
non_hfile_duplication_total |
String |
Definition Number of duplicate source files. Range N/A |
|
non_hfile_duplication_ratio |
String |
Definition Source file duplication rate. Range N/A |
|
code_duplication_total |
String |
Definition Number of duplicate code blocks. Range N/A |
|
code_duplication_ratio |
String |
Definition Duplication rate. Range N/A |
|
non_hfile_code_duplication_total |
String |
Definition Number of duplicate code blocks in source files. Range N/A |
|
non_hfile_code_duplication_ratio |
String |
Definition Source file code duplication rate. Range N/A |
|
unsafe_functions_total |
String |
Definition Total number of unsafe functions. Range N/A |
|
unsafe_functions_kloc |
String |
Definition Density of unsafe functions. Range N/A |
|
redundant_code_total |
String |
Definition Number of redundant code blocks. Range N/A |
|
redundant_code_kloc |
String |
Definition Density of redundant code blocks. Range N/A |
|
warning_suppression_total |
String |
Definition Number of suppressed alarms. Range N/A |
|
warning_suppression_kloc |
String |
Definition Density of suppressed alarms. Range N/A |
Status code: 400
|
Parameter |
Type |
Description |
|---|---|---|
|
error_code |
String |
Definition: Error code. Value range: N/A |
|
error_msg |
String |
Definition: Error message. Value range: N/A |
Status code: 401
|
Parameter |
Type |
Description |
|---|---|---|
|
error_code |
String |
Definition: Error code. Value range: N/A |
|
error_msg |
String |
Definition: Error message. Value range: N/A |
Example Requests
Query the code metrics of task ID 2b31ed520xxxxxxebedb6e57xxxxxxxx under project ID e04b357xxxxx5ed832xxxxxx.
GET https://{endpoint}/v2/e04b357xxxxx5ed832xxxxxx/tasks/2b31ed520xxxxxxebedb6e57xxxxxxxx/metrics-summary
Example Responses
Status code: 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"
}
}
Status code: 400
Bad Request
{
"error_code" : "CC.xxxxxxxx.400",
"error_msg" : "Verify request parameter failed. Check whether the request parameters are correct."
}
Status code: 401
Unauthorized
{
"error_code" : "CC.00000003",
"error_msg" : "Authentication information expired."
}
SDK Sample Code
The SDK sample code is as follows.
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) } } |
For SDK sample code of more programming languages, see the Sample Code tab in API Explorer. SDK sample code can be automatically generated.
Status Codes
|
Status Code |
Description |
|---|---|
|
200 |
Request succeeded! |
|
400 |
Bad Request |
|
401 |
Unauthorized |
Error Codes
See Error Codes.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot