{{< details >}}

  1. Tier: 基础版, 专业版, 旗舰版
  2. Offering: 私有化部署

{{< /details >}}

此 API 用于管理基于 Flipper 的 在极狐GitLab 开发中使用的功能标志

所有方法都需要管理员授权。

注意,该 API 仅支持布尔值和时间百分比门值。

列出所有功能

获取所有持久化功能及其门值的列表。

GET /features
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/features"

示例响应:

[
  {
    "name": "experimental_feature",
    "state": "off",
    "gates": [
      {
        "key": "boolean",
        "value": false
      }
    ],
    "definition": null
  },
  {
    "name": "my_user_feature",
    "state": "on",
    "gates": [
      {
        "key": "percentage_of_actors",
        "value": 34
      }
    ],
    "definition": {
      "name": "my_user_feature",
      "introduced_by_url": "https://jihulab.com/gitlab-cn/gitlab/-/merge_requests/40880",
      "rollout_issue_url": "https://jihulab.com/gitlab-cn/gitlab/-/issues/244905",
      "group": "group::ci",
      "type": "development",
      "default_enabled": false
    }
  },
  {
    "name": "new_library",
    "state": "on",
    "gates": [
      {
        "key": "boolean",
        "value": true
      }
    ],
    "definition": null
  }
]

列出所有功能定义

获取所有功能定义的列表。

GET /features/definitions
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/features/definitions"

示例响应:

[
  {
    "name": "geo_pages_deployment_replication",
    "introduced_by_url": "https://jihulab.com/gitlab-cn/gitlab/-/merge_requests/68662",
    "rollout_issue_url": "https://jihulab.com/gitlab-cn/gitlab/-/issues/337676",
    "milestone": "14.3",
    "log_state_changes": null,
    "type": "development",
    "group": "group::geo",
    "default_enabled": true
  }
]

设置或创建一个功能

设置功能的门值。如果具有给定名称的功能尚不存在,则会创建它。该值可以是布尔值,或表示时间百分比的整数。

{{< alert type=”warning” >}}

在启用仍在开发中的功能之前,您应了解 安全性和稳定性风险

{{< /alert >}}

POST /features/:name
属性 类型 必需 描述
name string 要创建或更新的功能名称
value integer/string truefalse 以启用/禁用,或表示时间百分比的整数
key string percentage_of_actorspercentage_of_time(默认)
feature_group string 功能组 名称
user string 极狐GitLab 用户名或以逗号分隔的多个用户名
group string 极狐GitLab 群组路径,例如 gitlab-org,或以逗号分隔的多个群组路径
namespace string 极狐GitLab 群组或用户命名空间的路径,例如 john-doe,或以逗号分隔的多个命名空间路径。在极狐GitLab 15.0 中引入。
project string 项目路径,例如 gitlab-org/gitlab-foss,或以逗号分隔的多个项目路径
repository string 仓库路径,例如 gitlab-org/gitlab-test.gitgitlab-org/gitlab-test.wiki.gitsnippets/21.git 等。使用逗号分隔多个仓库路径
force boolean 跳过功能标志验证检查,例如 YAML 定义

您可以在单个 API 调用中为 feature_groupusergroupnamespaceprojectrepository 启用或禁用功能。

curl --data "value=30" --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/features/new_library"

示例响应:

{
  "name": "new_library",
  "state": "conditional",
  "gates": [
    {
      "key": "boolean",
      "value": false
    },
    {
      "key": "percentage_of_time",
      "value": 30
    }
  ],
  "definition": {
    "name": "my_user_feature",
    "introduced_by_url": "https://jihulab.com/gitlab-cn/gitlab/-/merge_requests/40880",
    "rollout_issue_url": "https://jihulab.com/gitlab-cn/gitlab/-/issues/244905",
    "group": "group::ci",
    "type": "development",
    "default_enabled": false
  }
}

设置演员百分比推出

推出给一定百分比的演员。

POST https://gitlab.example.com/api/v4/features/my_user_feature?private_token=<your_access_token>
Content-Type: application/x-www-form-urlencoded
value=42&key=percentage_of_actors&

示例响应:

{
  "name": "my_user_feature",
  "state": "conditional",
  "gates": [
    {
      "key": "boolean",
      "value": false
    },
    {
      "key": "percentage_of_actors",
      "value": 42
    }
  ],
  "definition": {
    "name": "my_user_feature",
    "introduced_by_url": "https://jihulab.com/gitlab-cn/gitlab/-/merge_requests/40880",
    "rollout_issue_url": "https://jihulab.com/gitlab-cn/gitlab/-/issues/244905",
    "group": "group::ci",
    "type": "development",
    "default_enabled": false
  }
}

my_user_feature 推出给 42% 的演员。

删除一个功能

移除功能门。响应在门存在或不存在时相同。

DELETE /features/:name