跳转至

Advanced repository settings(高级仓库设置)

Most Code Repositories settings can be found in the Settings tab. Some additional values are configured using the repoSettings.json file at the repository root. If the file does not exist, you can create a file named repoSettings.json at the repository root.

Custom tag name validation

To enforce that all newly created tags in a repository follow a specific naming scheme in addition to the default constraints enforced by Code Repositories, you may configure a custom regular expression and an error message that is displayed to users if the regex is not satisfied. For example:

"tagNameValidation": {
    "regex": "^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(-rc\\d+)?$",
    "errorMessage": "Tag name must have the format x.x.x or x.x.x-rcx"
}

:::callout{theme="neutral"} If you set a value for tagNameValidation, you must configure both a regex and an errorMessage. :::

Pull request description template

To help maintain best practices when opening new pull requests, you can configure a description template that will be used to pre-populate the Description field when creating a pull request:

"prDescriptionTemplate": "First line of the description template\nAnd another line with instructions"

Output dataset path for new transforms

By default, the templates for new transforms files use the file path as the initial output dataset path. For example, for a Python transform /path/to/your/repository/transforms-python/src/myproject/datasets/name_of_file. You can change this to a more convenient location, such as a specific folder in your project, by configuring an outputPathPrefix:

"outputPathPrefix": "/My/Custom/Prefix"

With the above setting, the output dataset path will be set to /My/Custom/Prefix/name_of_file instead.

Pull request validation rules

An example pull request validated against rules stored in repoSettings.json

You can enforce rules for pull requests within a repository by adding prValidation entries to your repoSettings.json file. When a pull request is created, it will be validated against the repoSettings.json file on the base branch.

A pull request validation rule consists of a regular expression, a list of pull request fields to match the expression against, and an error message to render when a field does not comply with the rule.

Example: repoSettings.json

{ 
    "tagNameValidation": {
        "regex": "^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(-rc\\d+)?$",
        "errorMessage": "Tag name must have the format x.x.x or x.x.x-rcx"
    },
    "prDescriptionTemplate": "First line of the description template\nAnd another line with instructions",
    "outputPathPrefix": "/My/Custom/Prefix",
    "prValidation": [
        {
            "regex": "TEST-\\d{3}",
            "fields": ["title", "branchName"],
            "errorMessage": "This field must contain a valid TEST-XXX ticket, such as 'TEST-123'."
        },
        {
            "regex": "This is the description",
            "fields": ["description"],
            "errorMessage": "Please enter 'This is the description' somewhere in the description."
        }
    ]
}

中文翻译


高级仓库设置

大多数代码仓库(Code Repositories)设置可在设置选项卡中找到。部分额外值通过仓库根目录下的 repoSettings.json 文件配置。若该文件不存在,您可在仓库根目录创建名为 repoSettings.json 的文件。

自定义标签名称验证

如需强制要求仓库中所有新建标签在遵循代码仓库(Code Repositories)默认约束的同时,还需符合特定命名规范,可配置自定义正则表达式及未满足正则条件时向用户显示的错误信息。例如:

"tagNameValidation": {
    "regex": "^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(-rc\\d+)?$",
    "errorMessage": "标签名称必须采用 x.x.x 或 x.x.x-rcx 格式"
}

:::callout{theme="neutral"} 若设置 tagNameValidation 的值,则必须同时配置 regexerrorMessage。 :::

拉取请求描述模板

为帮助在创建新拉取请求时保持最佳实践,可配置描述模板,用于预填充创建拉取请求时的描述(Description)字段:

"prDescriptionTemplate": "描述模板的第一行\n以及另一行包含说明的内容"

新转换的输出数据集路径

默认情况下,新转换文件的模板使用文件路径作为初始输出数据集路径。例如,对于Python转换 /path/to/your/repository/transforms-python/src/myproject/datasets/name_of_file。您可通过配置 outputPathPrefix 将其更改为更便捷的位置,例如项目中的特定文件夹:

"outputPathPrefix": "/My/Custom/Prefix"

使用上述设置后,输出数据集路径将变为 /My/Custom/Prefix/name_of_file

拉取请求验证规则

根据 repoSettings.json 中存储的规则验证拉取请求的示例

您可通过在 repoSettings.json 文件中添加 prValidation 条目来强制实施仓库内的拉取请求规则。创建拉取请求时,将根据基础分支上的 repoSettings.json 文件进行验证。

拉取请求验证规则包含一个正则表达式、一个用于匹配该表达式的拉取请求字段列表,以及当字段不符合规则时显示的错误信息。

示例:repoSettings.json

{ 
    "tagNameValidation": {
        "regex": "^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(-rc\\d+)?$",
        "errorMessage": "标签名称必须采用 x.x.x 或 x.x.x-rcx 格式"
    },
    "prDescriptionTemplate": "描述模板的第一行\n以及另一行包含说明的内容",
    "outputPathPrefix": "/My/Custom/Prefix",
    "prValidation": [
        {
            "regex": "TEST-\\d{3}",
            "fields": ["title", "branchName"],
            "errorMessage": "此字段必须包含有效的 TEST-XXX 工单,例如 'TEST-123'。"
        },
        {
            "regex": "这是描述内容",
            "fields": ["description"],
            "errorMessage": "请在描述中的某处输入'这是描述内容'。"
        }
    ]
}