Updated on 2024-12-12 GMT+08:00

Configuring Project-Level 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.

Configuring Project-Level Commit Rules

On the CodeArts Repo homepage, go to the project homepage, choose Settings > Policy Settings > Commit Rules, and click Create Commit Rule. For details, see Table 1.

Table 1 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 committed information must contain the work item number to implement E2E code tracing with max. 500 characters.
  • Commit Message Negative Match: This parameter is empty by default. If left blank, all messages can be committed. Every commit message that matches the regex provided in it, will be rejected with max. 500 characters.
  • 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)$
  • Each File Size (MB): The default value is 50, indicating that the push is rejected if the size of the added or updated file exceeds 50 MB.
NOTE:

When a repository is created, the max. size of a single file in the default commit rule is 50 MB for recommendation. The max. file size is 200 MB.

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.

Common Regular Expression Examples

Common regular expression examples are listed below.

Table 2 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 other than 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 character

\S

Arabic numeral character

\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