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

# 更新 Devin Review 触发器

> 通过一次原子性 API 调用，为组织创建、替换和删除 Devin Review auto-review 规则及排除规则。

以单个原子批次创建、替换和删除 [Devin Review auto-review](https://docs.devinenterprise.com/zh/work-with-devin/devin-review.md#auto-review) 规则及排除规则。如需查看现有触发器，请使用[列出 Review 触发器](https://docs.devinenterprise.com/zh/api-reference/v3/review-triggers/list-review-triggers.md)；如需查找可作为目标的代码仓库，请使用[列出 Review 触发器作用域](https://docs.devinenterprise.com/zh/api-reference/v3/review-triggers/list-review-trigger-scopes.md)。

## 权限

需要使用在组织中具有 `ManageReview` 权限的[服务用户](https://docs.devinenterprise.com/zh/api-reference/v3/service-users/members-service-users.md)或[个人访问令牌](https://docs.devinenterprise.com/zh/api-reference/personal-access-tokens.md)。个人访问令牌以其所属用户的身份执行操作。账户级 `ManageReview` 权限允许调用方管理所有作用域；组织级 `ManageReview` 权限仅适用于该组织可访问的代码仓库。

## 行为

* `upserts` 中不带 `entity_id` 的条目会创建一个触发器。带有 `entity_id` 的条目会替换对应的触发器，且必须包含 `expected_version_id`，即最近一次读取到的 `version_id`。省略的字段将保留其已存储的值。
* `kind` 为 `rule` (自动运行 Review) 或 `exclusion` (跳过匹配的拉取请求) 。
* `scope` 为 `account` (Review 可访问的所有代码仓库) 、`repository` (需同时提供 `repository`，在 github.com 上格式为 `owner/repo`，其他平台为 `host/path`) 或 `user` (需同时提供 `user_id`，适用于该成员本人的拉取请求) 。
* 对于规则，`start` 为 `pr_open` 或 `pr_ready` (默认) ，`cadence` 为 `once` 或 `every_push` (默认) ，`effort` 为 `default`、`normal` 或 `ultra`。
* `conditions` 用于将触发器限定于匹配的拉取请求；创建时省略该字段，即匹配作用域内的所有拉取请求。替换时省略该字段会保留已存储的条件；传入 `null` 可清除条件。
* `deletes` 中的条目通过 `entity_id` 和 `expected_version_id` 指定要删除的触发器。
* 批量操作具有原子性：要么全部成功，要么全部失败。批次为空时返回 `400`；任一条目指向调用方无权管理的作用域时返回 `403`；`expected_version_id` 已过期时返回 `409`。遇到最后一种情况时，请重新读取触发器后重试。
* 如果组织未启用 Review 触发器，则返回 `404`。

## 示例

```bash theme={null}
curl -X PATCH "https://api.devin.ai/v3beta1/organizations/$ORG_ID/review-settings/default-reviewer/triggers" \
  -H "Authorization: Bearer $DEVIN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "upserts": [
      {
        "kind": "rule",
        "scope": "repository",
        "repository": "acme/web",
        "start": "pr_ready",
        "cadence": "every_push"
      }
    ]
  }'
```


## OpenAPI

````yaml zh/v3-openapi.yaml PATCH /v3beta1/organizations/{org_id}/review-settings/default-reviewer/triggers
openapi: 3.1.0
info:
  description: 采用 Service User 身份验证和 RBAC 的 Devin v3 API
  title: Devin API v3
  version: 3.0.0
servers: []
security:
  - bearerAuth: []
paths:
  /v3beta1/organizations/{org_id}/review-settings/default-reviewer/triggers:
    patch:
      tags:
        - review-settings
      summary: 创建、替换或删除默认审查者触发器
      description: 以原子方式批量应用默认审查者触发器的更改。
      operationId: >-
        handle_update_review_triggers_v3beta1_organizations__org_id__review_settings_default_reviewer_triggers_patch
      parameters:
        - description: 组织 ID（前缀：org-）
          in: path
          name: org_id
          required: true
          schema:
            example: org-abc123def456
            title: Org Id
            type: string
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ReviewTriggersUpdateRequest'
        required: true
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ReviewTriggersUpdateResponse'
          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: 冲突
        '410':
          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:
    ReviewTriggersUpdateRequest:
      properties:
        deletes:
          items:
            $ref: '#/components/schemas/ReviewTriggerDeleteRequest'
          maxItems: 100
          title: Deletes
          type: array
        upserts:
          items:
            $ref: '#/components/schemas/ReviewTriggerUpsertRequest'
          maxItems: 100
          title: Upserts
          type: array
      title: ReviewTriggersUpdateRequest
      type: object
    ReviewTriggersUpdateResponse:
      properties:
        deleted_entity_ids:
          items:
            type: string
          title: Deleted Entity Ids
          type: array
        upserted:
          items:
            $ref: '#/components/schemas/ReviewTriggerResponse'
          title: Upserted
          type: array
      required:
        - upserted
        - deleted_entity_ids
      title: ReviewTriggersUpdateResponse
      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
        error_code:
          anyOf:
            - type: string
            - type: 'null'
          description: 因操作被阻止而拒绝请求时返回的机器可读代码（例如 "user_frozen"、"migrated_session"）。
          title: Error Code
        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
    ReviewTriggerDeleteRequest:
      properties:
        entity_id:
          title: Entity Id
          type: string
        expected_version_id:
          title: Expected Version Id
          type: string
      required:
        - entity_id
        - expected_version_id
      title: ReviewTriggerDeleteRequest
      type: object
    ReviewTriggerUpsertRequest:
      properties:
        cadence:
          anyOf:
            - enum:
                - once
                - every_push
              type: string
            - type: 'null'
          description: 仅适用于规则。默认使用已存储的值；若无，则为 'every_push'。
          title: Cadence
        conditions:
          anyOf:
            - $ref: '#/components/schemas/ReviewTriggerConditions-Input'
            - type: 'null'
          description: >-
            以审查设置编辑器保存的形式，通过 AND（'all'）或 OR（'any'）连接的子句；null 匹配所有 pull
            request。更新时默认使用已存储的条件。
        effort:
          anyOf:
            - enum:
                - default
                - normal
                - ultra
              type: string
            - type: 'null'
          description: 仅适用于规则。默认使用已存储的值；若无，则为 'default'。
          title: Effort
        entity_id:
          anyOf:
            - type: string
            - type: 'null'
          description: 省略此字段可创建触发器；传入现有触发器的 id 可将其替换。
          title: Entity Id
        expected_version_id:
          anyOf:
            - type: string
            - type: 'null'
          description: 提供 entity_id 时必填：上次读取的 version_id。版本过期时返回 409。
          title: Expected Version Id
        kind:
          anyOf:
            - enum:
                - rule
                - exclusion
              type: string
            - type: 'null'
          description: '''rule'' 自动运行审查，''exclusion'' 阻止匹配的拉取请求接受审查。创建时默认为 ''rule''，更新时默认使用已存储的类型。'
          title: Kind
        repository:
          anyOf:
            - maxLength: 512
              type: string
            - type: 'null'
          description: >-
            代码仓库名称，采用作用域目标所用的格式：github.com 上为 'owner/repo'，其他平台为 'host/path'。也接受
            URL 或带有 'github.com/' 前缀的名称。除 Gerrit 外，均不区分大小写。必须是调用方有权附加触发器的代码仓库（参见
            trigger-scopes）。
          title: Repository
        scope:
          anyOf:
            - enum:
                - account
                - repository
                - user
              type: string
            - type: 'null'
          description: >-
            'account' 涵盖审查功能可见的所有代码仓库；'repository' 要求提供 `repository`；'user' 要求提供
            `user_id`，并审查该成员自己的拉取请求。更新时默认使用已存储的作用域。
          title: Scope
        start:
          anyOf:
            - enum:
                - pr_open
                - pr_ready
              type: string
            - type: 'null'
          description: 仅适用于规则。默认使用已存储的值；若无，则为 'pr_ready'。
          title: Start
        user_id:
          anyOf:
            - maxLength: 128
              type: string
            - type: 'null'
          description: 作用域为 'user' 时：指定账户成员（参见 members）。为他人设置触发器需要 account-wide 管理审查权限。
          title: User Id
      title: ReviewTriggerUpsertRequest
      type: object
    ReviewTriggerResponse:
      properties:
        cadence:
          anyOf:
            - enum:
                - once
                - every_push
              type: string
            - type: 'null'
          description: 规则：仅审查一次，或每次推送时重新审查。排除规则下为 Null。
          title: Cadence
        conditions:
          anyOf:
            - $ref: '#/components/schemas/ReviewTriggerConditions-Output'
            - type: 'null'
          description: 按审查设置编辑器保存的形式，通过 AND（'all'）或 OR（'any'）连接的子句；null 匹配所有 pull request。
        created_at:
          title: Created At
          type: integer
        effort:
          anyOf:
            - enum:
                - default
                - normal
                - ultra
              type: string
            - type: 'null'
          description: 仅适用于规则。
          title: Effort
        entity_id:
          title: Entity Id
          type: string
        kind:
          enum:
            - rule
            - exclusion
          title: Kind
          type: string
        modified_by_user_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Modified By User Id
        readonly:
          title: Readonly
          type: boolean
        removable:
          title: Removable
          type: boolean
        scope:
          $ref: '#/components/schemas/ReviewScopeResponse'
        start:
          anyOf:
            - enum:
                - pr_open
                - pr_ready
                - check_passed
                - pre_pr
                - with_review
              type: string
            - type: 'null'
          description: >-
            规则：指定首次审查的运行时机，即在创建 PR 时或 PR
            准备好接受审查时。在审查设置中保存的规则还可以在检查通过时（'check_passed'）、PR
            创建前（'pre_pr'）或仅随其他审查一起（'with_review'）触发。排除规则的此值为 null。
          title: Start
        version_id:
          description: 每次保存时都会更改；将其作为 expected_version_id 传回。
          title: Version Id
          type: string
      required:
        - entity_id
        - version_id
        - kind
        - scope
        - conditions
        - start
        - cadence
        - effort
        - readonly
        - removable
        - modified_by_user_id
        - created_at
      title: ReviewTriggerResponse
      type: object
    ReviewTriggerConditions-Input:
      additionalProperties: false
      properties:
        clauses:
          items:
            discriminator:
              mapping:
                author: '#/components/schemas/ReviewTriggerUserClause'
                author_type: '#/components/schemas/ReviewTriggerAuthorTypeClause'
                changed_file: '#/components/schemas/ReviewTriggerPatternClause'
                label: '#/components/schemas/ReviewTriggerLabelClause'
                line_diff: '#/components/schemas/ReviewTriggerLineDiffClause'
                originated_by: '#/components/schemas/ReviewTriggerOriginatedByClause'
                repo_visibility: '#/components/schemas/ReviewTriggerRepoVisibilityClause'
                repository: '#/components/schemas/ReviewTriggerRepositoryClause'
                reviewer: '#/components/schemas/ReviewTriggerUserClause'
                source_branch: '#/components/schemas/ReviewTriggerPatternClause'
                target_branch: '#/components/schemas/ReviewTriggerPatternClause'
                title: '#/components/schemas/ReviewTriggerPatternClause'
              propertyName: kind
            oneOf:
              - $ref: '#/components/schemas/ReviewTriggerUserClause'
              - $ref: '#/components/schemas/ReviewTriggerLabelClause'
              - $ref: '#/components/schemas/ReviewTriggerPatternClause'
              - $ref: '#/components/schemas/ReviewTriggerRepositoryClause'
              - $ref: '#/components/schemas/ReviewTriggerAuthorTypeClause'
              - $ref: '#/components/schemas/ReviewTriggerOriginatedByClause'
              - $ref: '#/components/schemas/ReviewTriggerRepoVisibilityClause'
              - $ref: '#/components/schemas/ReviewTriggerLineDiffClause'
          maxItems: 50
          minItems: 1
          title: Clauses
          type: array
        match:
          description: '`all`：必须匹配所有子句；`any`：必须至少匹配一个子句。'
          enum:
            - all
            - any
          title: Match
          type: string
      required:
        - match
        - clauses
      title: ReviewTriggerConditions
      type: object
    ReviewTriggerConditions-Output:
      additionalProperties: false
      properties:
        clauses:
          items:
            discriminator:
              mapping:
                author: '#/components/schemas/ReviewTriggerUserClause'
                author_type: '#/components/schemas/ReviewTriggerAuthorTypeClause'
                changed_file: '#/components/schemas/ReviewTriggerPatternClause'
                label: '#/components/schemas/ReviewTriggerLabelClause'
                line_diff: '#/components/schemas/ReviewTriggerLineDiffClause'
                originated_by: '#/components/schemas/ReviewTriggerOriginatedByClause'
                repo_visibility: '#/components/schemas/ReviewTriggerRepoVisibilityClause'
                repository: '#/components/schemas/ReviewTriggerRepositoryClause'
                reviewer: '#/components/schemas/ReviewTriggerUserClause'
                source_branch: '#/components/schemas/ReviewTriggerPatternClause'
                target_branch: '#/components/schemas/ReviewTriggerPatternClause'
                title: '#/components/schemas/ReviewTriggerPatternClause'
              propertyName: kind
            oneOf:
              - $ref: '#/components/schemas/ReviewTriggerUserClause'
              - $ref: '#/components/schemas/ReviewTriggerLabelClause'
              - $ref: '#/components/schemas/ReviewTriggerPatternClause'
              - $ref: '#/components/schemas/ReviewTriggerRepositoryClause'
              - $ref: '#/components/schemas/ReviewTriggerAuthorTypeClause'
              - $ref: '#/components/schemas/ReviewTriggerOriginatedByClause'
              - $ref: '#/components/schemas/ReviewTriggerRepoVisibilityClause'
              - $ref: '#/components/schemas/ReviewTriggerLineDiffClause'
          maxItems: 50
          minItems: 1
          title: Clauses
          type: array
        match:
          description: '`all`：必须匹配所有子句；`any`：必须至少匹配一个子句。'
          enum:
            - all
            - any
          title: Match
          type: string
      required:
        - match
        - clauses
      title: ReviewTriggerConditions
      type: object
    ReviewScopeResponse:
      properties:
        kind:
          enum:
            - account
            - user
            - git_organization
            - git_repository
          title: Kind
          type: string
        target:
          anyOf:
            - type: string
            - type: 'null'
          description: >-
            git_repository：代码仓库名称，在 github.com 上为 'owner/repo'，在其他主机上为
            'host/path'（'gitlab.example.com/group/sub/repo'），每个路径段均采用百分号编码。git_organization：格式相同的命名空间，以
            '/' 结尾。账户和用户作用域下为 Null。
          title: Target
        user_id:
          anyOf:
            - type: string
            - type: 'null'
          title: User Id
      required:
        - kind
        - target
      title: ReviewScopeResponse
      type: object
    ReviewTriggerUserClause:
      additionalProperties: false
      properties:
        kind:
          description: pull request 的作者或受邀的审查者。
          enum:
            - author
            - reviewer
          title: Kind
          type: string
        negate:
          default: false
          description: 匹配不符合该子句的拉取请求。
          title: Negate
          type: boolean
        users:
          description: 目标用户为这些用户中的任意一位时即匹配。
          items:
            $ref: '#/components/schemas/ReviewTriggerUser'
          minItems: 1
          title: Users
          type: array
      required:
        - kind
        - users
      title: ReviewTriggerUserClause
      type: object
    ReviewTriggerAuthorTypeClause:
      additionalProperties: false
      properties:
        kind:
          const: author_type
          title: Kind
          type: string
        negate:
          default: false
          description: 匹配不符合该子句的拉取请求。
          title: Negate
          type: boolean
        value:
          items:
            enum:
              - user
              - bot
              - devin
            type: string
          minItems: 1
          title: Value
          type: array
      required:
        - kind
        - value
      title: ReviewTriggerAuthorTypeClause
      type: object
    ReviewTriggerPatternClause:
      additionalProperties: false
      properties:
        kind:
          enum:
            - title
            - source_branch
            - target_branch
            - changed_file
          title: Kind
          type: string
        match:
          default: glob
          enum:
            - glob
            - exact
          title: Match
          type: string
        negate:
          default: false
          description: 匹配不符合该子句的拉取请求。
          title: Negate
          type: boolean
        value:
          items:
            type: string
          minItems: 1
          title: Value
          type: array
      required:
        - kind
        - value
      title: ReviewTriggerPatternClause
      type: object
    ReviewTriggerLabelClause:
      additionalProperties: false
      properties:
        kind:
          const: label
          title: Kind
          type: string
        negate:
          default: false
          description: 匹配不符合该子句的拉取请求。
          title: Negate
          type: boolean
        value:
          items:
            type: string
          minItems: 1
          title: Value
          type: array
      required:
        - kind
        - value
      title: ReviewTriggerLabelClause
      type: object
    ReviewTriggerLineDiffClause:
      additionalProperties: false
      properties:
        kind:
          const: line_diff
          description: 新增行数与删除行数之和。
          title: Kind
          type: string
        negate:
          default: false
          description: 匹配不符合该子句的拉取请求。
          title: Negate
          type: boolean
        operator:
          enum:
            - lt
            - lte
            - gt
            - gte
          title: Operator
          type: string
        value:
          minimum: 0
          title: Value
          type: integer
      required:
        - kind
        - operator
        - value
      title: ReviewTriggerLineDiffClause
      type: object
    ReviewTriggerOriginatedByClause:
      additionalProperties: false
      properties:
        kind:
          const: originated_by
          description: 该 pull request 由 Devin 会话创建或接管。
          title: Kind
          type: string
        negate:
          default: false
          description: 匹配不符合该子句的拉取请求。
          title: Negate
          type: boolean
        value:
          items:
            const: devin
            type: string
          minItems: 1
          title: Value
          type: array
      required:
        - kind
        - value
      title: ReviewTriggerOriginatedByClause
      type: object
    ReviewTriggerRepoVisibilityClause:
      additionalProperties: false
      properties:
        kind:
          const: repo_visibility
          description: 代码仓库是公开还是私有。仅适用于 Git 组织或前缀作用域。
          title: Kind
          type: string
        negate:
          default: false
          description: 匹配不符合该子句的拉取请求。
          title: Negate
          type: boolean
        value:
          items:
            enum:
              - public
              - private
            type: string
          minItems: 1
          title: Value
          type: array
      required:
        - kind
        - value
      title: ReviewTriggerRepoVisibilityClause
      type: object
    ReviewTriggerRepositoryClause:
      additionalProperties: false
      properties:
        kind:
          const: repository
          title: Kind
          type: string
        match:
          default: glob
          enum:
            - glob
            - exact
          title: Match
          type: string
        negate:
          default: false
          description: 匹配不符合该子句的拉取请求。
          title: Negate
          type: boolean
        value:
          description: '''owner/repo'' 格式的名称或 glob 模式。'
          items:
            type: string
          minItems: 1
          title: Value
          type: array
      required:
        - kind
        - value
      title: ReviewTriggerRepositoryClause
      type: object
    ReviewTriggerUser:
      additionalProperties: false
      properties:
        kind:
          description: '`devin`：通过用户 ID 指定的账户成员，使用其已关联的 git 登录名进行匹配；`scm`：git 登录名。'
          enum:
            - devin
            - scm
          title: Kind
          type: string
        value:
          minLength: 1
          title: Value
          type: string
      required:
        - kind
        - value
      title: ReviewTriggerUser
      type: object
  securitySchemes:
    bearerAuth:
      description: 服务用户凭据（前缀：cog_）
      scheme: bearer
      type: http

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.