Updated on 2025-05-26 GMT+08:00

Configuring Commit Rules

Overview of Commit Rules

CodeArts Repo supports verification and restriction rules for high-quality code commits.

The following describes how to configure project-level commit rules and use common regular expressions.

Constraints

Project manager or project administrator can set project-level webhooks.

Configuring Project-Level Commit Rules

On the CodeArts Repo homepage, go to a project, and choose Settings > Policy Settings > Commit Rules.

If you want to set the same commit rules for all repositories in a project, set parameters based on Table 1 and select Force inherit.

Table 1 Commit rules description

Parameter

Description

Reject non-signed-off-by commits

Only signed-off-by commits are pushed to the repository.

CodeArts Repo signature mode:

When performing online commit in the CodeArts Repo, use the following format to compile and commit information:

commit message             # Enter the customized commit information.
                           # This is a blank line.
Signed-off-by: User-defined signature   # Enter the user-defined signature after Signed-off-by:

Git client signature mode:

When running the commit command on the Git client, you need to add the -s parameter.

git commit -s -m "<your_commit_message>"

You need to configure the signature and email address on the client in advance.

Reject commits not signed by GPG

Only GPG-signed commits are pushed to the repository.

Configure a GPG key:

git config --global user.signingkey "your GPG private key"

Git client signature mode:

When running the commit command on the Git client, you need to add the -S parameter.

git commit -s -m "your commit message"

When running the tag command on the Git client, you need to add the -s parameter.

git tag -s -m "your tag message"

You need to configure the signature and email address on the client in advance.

Tags cannot be deleted

After this option is selected, tags cannot be deleted on the page or by running commands on the client.

Prevent committing secrets

Example: id_rsa and id_dsa files.

Prevent git push -f

Indicates whether users can run the git push -f command on the client to commit code.

git push -f indicates that the current local code repository is pushed to and overwrites the code in CodeArts Repo.

In general cases, you are not advised using this command.

If you want to set commit rules for a specified branch of a repository in a project, click Create Commit Rule. For details about the parameters, see Table 2.

Table 2 Parameters for project-level commit rules

Parameter

Description

Rule Name

Mandatory. Custom rule name.

Branch

Enter a complete rule name or create a regular expression. This parameter is mandatory. The input needs to be verified, including the branch name and regular expression.

Commit Rule

Optional.

  • Commit Message Match: This parameter is empty by default. If left blank, all messages can be committed. Every commit message that matches the regex can be committed. You can also set that the commit message (max. 500 characters) must contain the work item number to implement E2E code tracing.
  • Commit Message Negative Match: This parameter is empty by default. If left blank, all messages can be committed. Every commit message (max. 500 characters) that matches the regex provided in it, will be rejected.
  • Commit Author: This parameter is left empty by default, indicating that the commit author is not verified, and any parameter can be committed. This field supports a maximum of 200 characters.

    The commit author can run the git config -l command to view the value of user.name and run the git config --global user.name command to set the value of user.name.

    Example:

    Rules for setting the commit author: ([a-z][A-Z]{3})([0-9]{1,9})
  • Commit Author's Email: This parameter is left empty by default, indicating that the commit author email is not verified, and any parameter can be committed. This field supports a maximum of 200 characters.

    The commit author can run the git config -l command to view the value of user.email and run the git config --global user.email command to set the email address.

    Example:

    Commit author's email: @my-company.com$

Basic Attributes

Optional.

  • File Name That Cannot Be Changed: This parameter is left empty by default, indicating that a file with any name can be committed. You are advised to use standard regular expressions to match the file name. By default, the file path is verified based on the file name rule. This field supports a maximum of 2,000 characters.

    Example:

    File name that cannot be changed: (\.jar|\.exe)$
  • Single File Size (MB): If the size of the added or updated file exceeds the default value, the push will be rejected. You can change the default value.

Binary Rules

Optional.

This is not selected by default. Do not allow new binary files (privileged users excepted) is selected by default. After Allow changes to binary files is selected, binary files in the modify state will not be intercepted and can be directly uploaded. Binary files can be deleted without binary check.

  • Do not allow new binary files (privileged users excepted)
  • Allow changes to binary files (privileged users excepted)
  • Repo File Whitelist (files that can be directly imported to the database. This field supports a maximum of 2,000 characters.)
  • Privileged Users (Max. 50 privileged users.)
    NOTE:

    If the privileged user is not a repository member, the system displays a message indicating that the privileged user fails to be verified when you click Save. In this case, remove the privileged user to save the information.

Effective Date

Optional.

Before being committed, all commits created after the effective date must match the hook settings. If this parameter is left empty, all commits are checked regardless of the commit date.

Examples of Common Regular Expression

Common regular expression examples are listed below.

Table 3 Examples

Rule

Example

Single a, b, or c

[abc]

Characters other than a, b, or c

[^abc]

Lowercase letters ranging from a to z

[a-z]

Characters outside the range of a to z

[^a-z]

Uppercase and lowercase letters in the range of a to z or A to Z

[a-zA-Z]

Any single character

.

Either a or b

a|b

Any blank character

\s

Non-blank characters

\S

Arabic numeral characters

\d

Non-Arabic numeral characters

\D

Letters, digits, or underscores (_)

\w

Characters other than letters, digits, or underscores (_)

\W

Match the content in parentheses (not capture)

(?:...)

Match and capture the content in parentheses

(...)

No or one a

a?

No or more a's

a*

One or more a's

a+

Three a's

a{3}

More than three a's

a{3,}

3 to 6 a's

a{3,6}

Beginning of text

^

End of text

$

Word boundary

\b

Non-word boundary

\B

Line breaker

\n

Carriage return character

\r

Tab key

\t

Null string

\0

Managing Commit Rules

Click in the row where the target commit rule is located to view details, as shown in the following figure. Click to modify the rule and save it again. Click to delete the commit rule.

Figure 1 Commit rule details
OSZAR »