Skip to content

Commit 4093668

Browse files
committed
Add repository filtering docs for organization-level rules
1 parent e7c964d commit 4093668

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

docs/cm-file.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,65 @@ By utilizing the following techniques, you can effectively combine and manage gl
7979
2. To exclude or run only on specific repositories from a global rule, you can use `triggers.include.repository` and `triggers.exclude.repository` in the `cm` file and add a list of the unwanted or wanted repositories respectfully.
8080
3. To override a global rule for specific automation in a repository, you can duplicate the rule (both the file and automation name) and place it in the desired repository. The locally defined rule will then take precedence over the global rule for that specific repository.
8181

82+
### Controlling Organization-Level Rules per Repository
83+
84+
The `triggers` section in organization-level rules allows you to precisely control which repositories will run specific automations. This is particularly useful for implementing standardized rules across most repositories while exempting specific ones, or for creating specialized automations that only apply to certain repository types.
85+
86+
#### Repository Inclusion and Exclusion
87+
88+
You can use `triggers.include.repository` and `triggers.exclude.repository` to define which repositories should or should not run particular automations:
89+
90+
```yaml+jinja
91+
# In your organization's 'cm' repository
92+
manifest:
93+
version: 1.0
94+
95+
# This automation will run on all repositories EXCEPT those containing 'legacy' in their name
96+
triggers:
97+
exclude:
98+
repository:
99+
- r/legacy/
100+
101+
automations:
102+
enforce_pr_title_format:
103+
if:
104+
- {{ not (pr.title | includes(term="fix:|feat:|docs:|style:|refactor:|test:|chore:")) }}
105+
run:
106+
- action: add-comment@v1
107+
args:
108+
comment: |
109+
Please format your PR title according to our [Conventional Commits](https://www.conventionalcommits.org/) standard.
110+
Example: `feat: implement new login flow`
111+
```
112+
113+
#### Creating Repository-Type Specific Rules
114+
115+
You can also create separate CM files for different types of repositories:
116+
117+
```yaml+jinja
118+
# backend-rules.cm in your organization's 'cm' repository
119+
manifest:
120+
version: 1.0
121+
122+
# This file's automations will ONLY run on repositories with 'api' or 'service' in their name
123+
triggers:
124+
include:
125+
repository:
126+
- r/api|service/
127+
128+
automations:
129+
require_api_docs:
130+
if:
131+
- {{ files | match(regex=r/\/api\/.*\.js|ts$/) | some }}
132+
run:
133+
- action: request-changes@v1
134+
args:
135+
comment: |
136+
API changes detected. Please ensure you've updated the corresponding documentation.
137+
```
138+
139+
This approach allows you to create specialized rule sets for different repository types (frontend, backend, infrastructure, etc.) while maintaining them all in a centralized location.
140+
82141

83142
## The .cm automation file
84143
### Schema

0 commit comments

Comments
 (0)