@PLUGIN@ - REST API

This page describes the code owners REST endpoints that are added by the @PLUGIN@ plugin.

Please also take note of the general information on the REST API.

Project Endpoints

Get Code Owner Project Config

‘GET /projects/{project-name}/code_owners.project_config’

Gets the code owner project configuration.

As a response a CodeOwnerProjectConfigInfo entity is returned that describes the code owner project configuration.

Request

  GET /projects/foo%2Fbar/code_owners.project_config HTTP/1.0

Response

  HTTP/1.1 200 OK
  Content-Disposition: attachment
  Content-Type: application/json; charset=UTF-8

  )]}'
  {
    "backend": {
      "id": "find-owners",
      "ids_by_branch": {
        "refs/heads/experimental": "proto"
      }
    },
    "required_approval": {
      "label": "Code-Review",
      "value": 1
    },
    "override_approval": {
      "label": "Owners-Override",
      "value": 1
    }
  }

Branch Endpoints

[EXPERIMENTAL] Get Code Owner Config

‘GET /projects/{project-name}/branches/{branch-id}/code_owners.config/{path}

Gets a code owner config for a path in a branch.

The code owner config is returned as CodeOwnerConfigInfo entity

This REST endpoint is experimental which means that the response format is likely still going to be changed. It is only available if experimental REST endpoints are enabled in gerrit.config.

Request

  GET /projects/foo%2Fbar/branches/master/code_owners.config/%2Fdocs%2Fconfig HTTP/1.0

Response

  HTTP/1.1 200 OK
  Content-Disposition: attachment
  Content-Type: application/json; charset=UTF-8

  )]}'
  {
    "code_sets": [
      "code_owners" [
        {
          "email": "jane.roe@example.com"
        },
        {
          "email": "john.doe@example.com"
        }
      ]
    ]
  }

If the path does not exist or if no code owner config exists for the path ‘204 No Content’ is returned.

List Code Owners for path in branch

‘GET /projects/{project-name}/branches/{branch-id}/code_owners/{path}

Lists the accounts that are code owners of a file or folder in a branch.

The code owners are computed from the owner configuration at the tip of the specified branch.

Code owners that are

  • not visible to the calling user (according to accounts.visibility setting),
  • are referenced by non-visible secondary emails
  • not resolvable (emails for which no Gerrit account exists) or
  • ambiguous (the same email is assigned to multiple accounts)

are omitted from the result.

The following request parameters can be specified:

Field NameDescription
ooptionalAccount option that controls which fields in the returned accounts should be populated. Can be specified multiple times. If not given, only the _account_id field for the account ID is populated.
OoptionalAccount option in hex. For the explanation see o parameter.
limit|noptionalLimit defining how many code owners should be returned at most. By default 10.
revisionoptionalRevision from which the code owner configs should be read as commit SHA1. Can be used to read historic code owners. If not specified the code owner configs are read from the HEAD revision of the branch. Not supported for getting code owners for a path in a change.

As a response a list of CodeOwnerInfo entities is returned. The returned code owners are sorted by an internal score that expresses how good the code owners are considered as reviewers/approvers for the path. Code owners with higher scores are returned first. If code owners have the same score the order is random.

Request

  GET /projects/foo%2Fbar/branches/master/code_owners/docs%2Findex.md HTTP/1.0

Response

  HTTP/1.1 200 OK
  Content-Disposition: attachment
  Content-Type: application/json; charset=UTF-8

  )]}'
  [
    {
      "account": {
        "_account_id": 1000096
      }
    },
    {
      "account": {
        "_account_id": 1001439
      },
    }
  ]

Change Endpoints

Get Code Owner Status

‘GET /changes/{change-id}/code_owners.status’

Gets the code owner statuses for the files in a change.

The code owner statuses are always listed for the files in the current revision of the change (latest patch set).

The code owner statuses are returned as a CodeOwnerStatusInfo entity.

Request

  GET /changes/275378/code_owners.status HTTP/1.0

Response

  HTTP/1.1 200 OK
  Content-Disposition: attachment
  Content-Type: application/json; charset=UTF-8

  )]}'
  {
    "patch_set_number": 2,
    "file_code_owner_statuses": [
      {
        "change_type": "ADDED",
        "new_path_status" {
          "path": "docs/readme.md",
          "status": "APPROVED"
        }
      },
      {
        "change_type": "DELETED",
        "old_path_status" {
          "path": "docs/todo.txt",
          "status": "PENDING"
        }
      },
      {
        "change_type": "RENAMED",
        "old_path_status" {
          "path": "user-introduction.txt",
          "status": "INSUFFICIENT_REVIEWERS"
        },
        "new_path_status" {
          "path": "docs/user-intro.md",
          "status": "APPROVED"
        }
      }
    ]
  }

Revision Endpoints

List Code Owners for path in change

‘GET /changes/{change-id}/revisions/{revison-id}/code_owners/{path}

Lists the accounts that are code owners of a file in a change revision.

The code owners are computed from the owner configuration at the tip of the change's destination branch.

This REST endpoint has the exact same request and response format as the REST endpoint to list code owners for a path in a branch.

IDs

{path}

An arbitrary absolute path.

The leading'/' can be omitted.

The path may or may not exist in the branch.

JSON Entities

BackendInfo

The BackendInfo entity describes the code owner backend configuration.

Field NameDescription
idID of the code owner backend that is configured for the project.
ids_by_branchoptionalIDs of the code owner backends that are configured for individual branches as map of full branch names to code owner backend IDs. Only contains entries for branches for which a code owner backend is configured that differs from the backend that is configured for the project (see id field). Configurations for non-existing and non-visible branches are omitted. Not set if no branch specific backend configuration is returned.

CodeOwnerConfigInfo

The CodeOwnerConfigInfo entity contains information about a code owner config for a path.

Field NameDescription
ignore_parent_code_ownersoptional, not set if falseWhether code owners from parent code owner configs (code owner configs in parent folders) should be ignored.
code_owner_setsoptionalA list of code owner sets as CodeOwnerSetInfo entities.

CodeOwnerInfo

The CodeOwnerInfo entity contains information about a code owner.

Field NameDescription
accountoptionalThe account of the code owner as an AccountInfo entity. At the moment the account field is always set, but it's marked as optional as in the future we may also return groups as code owner and then the account field would be unset.

CodeOwnerProjectConfigInfo

The CodeOwnerProjectConfigInfo entity describes the code owner project configuration.

Field NameDescription
statusoptionalThe code owner status configuration as CodeOwnersStatusInfo entity. Contains information about whether the code owners functionality is disabled for the project or for any branch. Not set if the code owners functionality is neither disabled for the project nor for any branch.
backendThe code owner backend configuration as BackendInfo entity.
required_approvalThe approval that is required from code owners to approve the files in a change as RequiredApprovalInfo entity. The required approval defines which approval counts as code owner approval.
override_approvaloptionalThe approval that is required to override the code owners submit check as RequiredApprovalInfo entity. If unset, overriding the code owners submit check is disabled.

CodeOwnerReferenceInfo

The CodeOwnerReferenceInfo entity contains information about a code owner reference in a code owner config.

Field NameDescription
emailThe email of the code owner.

CodeOwnerSetInfo

The CodeOwnerSetInfo entity defines a set of code owners.

Field NameDescription
code_ownersoptionalThe list of code owners as CodeOwnerReferenceInfo entities.

CodeOwnerStatusInfo

The CodeOwnerStatusInfo entity describes the code owner statuses for the files in a change.

Field NameDescription
patch_set_numberThe number of the patch set for which the code owner statuses are returned.
file_code_owner_statusesList of the code owner statuses for the files in the change as FileCodeOwnerStatusInfo entities, sorted by new path, then old path.

CodeOwnersStatusInfo

The CodeOwnersStatusInfo contains information about whether the code owners functionality is disabled for a project or for any branch.

Field NameDescription
disabledoptionalWhether the code owners functionality is disabled for the project. If true the code owners API is disabled and submitting changes doesn't require code owner approvals. Not set if false.
disabled_branchesoptionalBranches for which the code owners functionality is disabled. Configurations for non-existing and non-visible branches are omitted. Not set if the disabled field is true or if no branch specific status configuration is returned.

FileCodeOwnerStatusInfo

The FileCodeOwnerStatusInfo entity describes the code owner statuses for a file in a change.

Field NameDescription
change_typeoptionalThe type of the file modification. Can be ADDED, MODIFIED, DELETED, RENAMED or COPIED. Not set if MODIFIED.
old_path_statusoptionalThe code owner status for the old path as PathCodeOwnerStatusInfo entity. Only set if change_type is DELETED or RENAMED.
new_path_statusoptionalThe code owner status for the new path as PathCodeOwnerStatusInfo entity. Not set if change_type is DELETED.

PathCodeOwnerStatusInfo

The PathCodeOwnerStatusInfo entity describes the code owner status for a path in a change.

Field NameDescription
pathThe path to which the code owner status applies.
statusThe code owner status for the path. Can be ‘INSUFFICIENT_REVIEWERS’ (the path needs a code owner approval, but none of its code owners is currently a reviewer of the change), PENDING (a code owner of this path has been added as reviewer, but no code owner approval for this path has been given yet) or APPROVED (the path has been approved by a code owner or a code owners override is present).

RequiredApprovalInfo

The RequiredApprovalInfo entity describes an approval that is required for an action.

Field NameDescription
labelThe name of label on which an approval is required.
valueThe voting value that is required on the label.

Part of Gerrit Code Review