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.
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.
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.
|
Basic Attributes |
Optional.
|
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.
|
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.
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 |
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot