> ## Documentation Index
> Fetch the complete documentation index at: https://docs.devin.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# 获取代码扫描指标

> 获取企业级代码扫描指标

<div id="permissions">
  ## 权限
</div>

需要具有企业级 `ViewAccountCodeScans` 权限的服务用户。

<div id="time-filters">
  ## 时间过滤器
</div>

此端点要求提供 `time_after` 和 `time_before` 查询参数。

* `time_after` 和 `time_before` 都是**以秒为单位的 Unix 时间戳**，按 UTC 解释。
* `time_after` 必须早于 `time_before`。
* `time_after` 与 `time_before` 之间的时间范围必须**不超过 100 天**。
* 指标仅涵盖在此时间范围内创建的代码扫描。


## OpenAPI

````yaml zh/v3-openapi.yaml GET /v3/enterprise/code-scans/metrics
openapi: 3.1.0
info:
  description: 采用 Service User 身份验证和 RBAC 的 Devin v3 API
  title: Devin API v3
  version: 3.0.0
servers: []
security:
  - bearerAuth: []
paths:
  /v3/enterprise/code-scans/metrics:
    get:
      tags:
        - code-scans
      summary: 获取代码扫描指标
      description: |-
        获取 Enterprise 账户的聚合代码扫描指标。

        返回在指定时间范围内创建的代码扫描的扫描、发现项和修复 PR 指标，
        并可按特定组织进行可选筛选。
      operationId: handle_get_code_scan_metrics_v3_enterprise_code_scans_metrics_get
      parameters:
        - in: query
          name: time_before
          required: true
          schema:
            title: Time Before
            type: integer
        - in: query
          name: time_after
          required: true
          schema:
            title: Time After
            type: integer
        - in: query
          name: org_ids
          required: false
          schema:
            anyOf:
              - items:
                  type: string
                type: array
              - type: 'null'
            title: Org Ids
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CodeScanMetricsResponse'
          description: 成功响应
        '401':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ProblemDetail'
          description: 未授权
        '403':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ProblemDetail'
          description: 禁止访问
        '404':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ProblemDetail'
          description: 未找到
        '409':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ProblemDetail'
          description: 冲突
        '422':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ProblemDetail'
          description: 无法处理的内容
        '429':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ProblemDetail'
          description: 请求过多
components:
  schemas:
    CodeScanMetricsResponse:
      description: |-
        代码扫描指标的响应模型。

        所有指标均限定在指定时间范围内创建的代码扫描：发现项和修复 PR 都归属于生成它们的扫描。
      properties:
        avg_pr_open_duration_seconds:
          anyOf:
            - type: number
            - type: 'null'
          description: >-
            PR 处于开放状态的平均时长（或曾处于开放状态的平均时长），单位为秒：对于已结束的 PR，按从创建到合并/关闭计算；对于仍处于开放状态的
            PR，按从创建到当前计算。若未创建任何 PR，则为 Null。
          title: Avg Pr Open Duration Seconds
        avg_pr_time_to_merge_seconds:
          anyOf:
            - type: number
            - type: 'null'
          description: 从 PR 创建到合并的平均时长，单位为秒。若没有任何已合并的 PR，则为 Null。
          title: Avg Pr Time To Merge Seconds
        open_critical_findings_count:
          description: 严重程度为 critical 的开放发现项数量。
          title: Open Critical Findings Count
          type: integer
        open_high_findings_count:
          description: 严重程度为 high 的开放发现项数量。
          title: Open High Findings Count
          type: integer
        open_low_findings_count:
          description: 严重程度为 low 的开放发现项数量。
          title: Open Low Findings Count
          type: integer
        open_medium_findings_count:
          description: 严重程度为 medium 的开放发现项数量。
          title: Open Medium Findings Count
          type: integer
        prs_closed_count:
          description: 未合并即关闭的修复 PR 数量。
          title: Prs Closed Count
          type: integer
        prs_created_count:
          description: 由扫描的修复会话创建的 PR 数量。
          title: Prs Created Count
          type: integer
        prs_merged_count:
          description: 已合并的修复 PR 数量。
          title: Prs Merged Count
          type: integer
        prs_open_count:
          description: 当前处于开放状态的修复 PR 数量。
          title: Prs Open Count
          type: integer
        repos_scanned_count:
          description: 已扫描的不同代码仓库数量。
          title: Repos Scanned Count
          type: integer
        scans_count:
          description: 在指定时间范围内创建的代码扫描数量。
          title: Scans Count
          type: integer
      required:
        - scans_count
        - repos_scanned_count
        - prs_created_count
        - prs_open_count
        - prs_merged_count
        - prs_closed_count
        - avg_pr_time_to_merge_seconds
        - avg_pr_open_duration_seconds
        - open_critical_findings_count
        - open_high_findings_count
        - open_medium_findings_count
        - open_low_findings_count
      title: CodeScanMetricsResponse
      type: object
    ProblemDetail:
      description: >-
        v3 API 的 RFC 9457 application/problem+json 错误响应体。


        detail 沿用自旧版 {"detail": ...} 响应体，以保持向后兼容；其他成员字段为新增字段。errors
        包含字段级验证失败信息（仅 422）。
      properties:
        detail:
          anyOf:
            - type: string
            - type: 'null'
          description: 针对此次具体情况的、便于人理解的说明。
          title: Detail
        errors:
          anyOf:
            - items:
                additionalProperties: true
                type: object
              type: array
            - type: 'null'
          description: 字段级验证错误（仅适用于 422 响应）。
          title: Errors
        instance:
          anyOf:
            - type: string
            - type: 'null'
          description: 此次出现对应的 URI 引用（请求路径）。
          title: Instance
        status:
          description: HTTP 状态码。
          title: Status
          type: integer
        title:
          description: 对问题类型的简短、便于理解的概述。
          title: Title
          type: string
        type:
          default: about:blank
          description: 用于标识问题类型的 URI 引用。
          title: Type
          type: string
      required:
        - title
        - status
      title: ProblemDetail
      type: object
  securitySchemes:
    bearerAuth:
      description: 服务用户凭据（前缀：cog_）
      scheme: bearer
      type: http

````