|
1 |
| -# Merge Request Linter |
| 1 | +<h1 align="center">MR Linter - merge/pull request validator</h1> |
2 | 2 |
|
3 | 3 | 
|
4 | 4 | [](https://codecov.io/gh/ArtARTs36/php-merge-request-linter)
|
|
7 | 7 | 
|
8 | 8 | 
|
9 | 9 |
|
10 |
| -This package provides tools for validating merge requests |
| 10 | +This project provides tools for validating merge/pull requests. |
11 | 11 |
|
12 |
| -[Show validation rules](docs/rules.md) |
| 12 | +Supported CI Systems: **GitHub Actions**, **Gitlab CI**. |
13 | 13 |
|
14 |
| -[Creating custom rule](docs/custom_rule.md) |
| 14 | +## Documentation |
15 | 15 |
|
16 |
| -[Docker Image](https://hub.docker.com/repository/docker/artarts36/merge-request-linter) |
17 |
| - |
18 |
| -## Installation |
19 |
| - |
20 |
| -Add config file with name `.mr-linter.yml` or `.mr-linter.json`. |
21 |
| -Examples: |
22 |
| -* https://github.com/ArtARTs36/php-merge-request-linter/blob/master/stubs/.mr-linter.yaml |
23 |
| -* https://github.com/ArtARTs36/php-merge-request-linter/blob/master/stubs/.mr-linter.json |
24 |
| - |
25 |
| -## ➜ Usage with GitHub Actions |
26 |
| - |
27 |
| -[View on Marketplace](https://github.com/marketplace/actions/merge-request-linter) |
28 |
| - |
29 |
| -Implementation example: https://github.com/ArtARTs36/ShellCommand/pull/11 |
30 |
| - |
31 |
| -1. Generate token on [page](https://github.com/settings/tokens/new) |
32 |
| -2. Open https://github.com/{owner}/{repo}/settings/secrets/actions/new. Add new secret "MR_LINTER_GITHUB_HTTP_TOKEN" with your personal access token |
33 |
| -3. Add new workflow file **.github/workflows/review.yml**: |
34 |
| -```yml |
35 |
| -name: PR Review |
36 |
| - |
37 |
| -on: |
38 |
| -pull_request: |
39 |
| -branches: [ master ] |
40 |
| - |
41 |
| -jobs: |
42 |
| -build: |
43 |
| - |
44 |
| - runs-on: ubuntu-latest |
45 |
| - |
46 |
| - steps: |
47 |
| - - uses: actions/checkout@v2 |
48 |
| - |
49 |
| - - name: Lint Pull Request |
50 |
| - |
51 |
| - env: |
52 |
| - MR_LINTER_GITHUB_TOKEN: ${{ secrets.MR_LINTER_GITHUB_HTTP_TOKEN }} |
53 |
| -``` |
54 |
| -
|
55 |
| -## ➜ Usage with Gitlab CI |
56 |
| -
|
57 |
| -[See example](https://gitlab.com/artem_ukrainsky/mr-linter-testing/) |
58 |
| -
|
59 |
| -1. Generate token on `https://{gitlab-host}/-/profile/personal_access_tokens` |
60 |
| -2. Open `https://{gitlab-host}/group/project/-/settings/ci_cd`. Add new variable "MR_LINTER_GITLAB_HTTP_TOKEN" with your personal access token |
61 |
| -3. Add new step into **.gitlab-ci.yml** |
62 |
| - ```yaml |
63 |
| - mr-lint: |
64 |
| - image: artarts36/merge-request-linter:0.8.0 |
65 |
| - stage: test |
66 |
| - only: |
67 |
| - - merge_requests |
68 |
| - script: |
69 |
| - - mr-linter lint |
70 |
| - ``` |
71 |
| - |
72 |
| -## Run in Docker |
73 |
| - |
74 |
| -Simple bash: |
75 |
| -```shell |
76 |
| -docker run \ |
77 |
| - -it \ |
78 |
| - -e GITHUB_ACTIONS=1 \ |
79 |
| - -e GITHUB_REPOSITORY=artarts36/php-merge-request-linter \ |
80 |
| - -e GITHUB_GRAPHQL_URL=https://api.github.com/graphql \ |
81 |
| - -e GITHUB_REF_NAME=${MR_ID}/merge \ |
82 |
| - -e MR_LINTER_GITHUB_HTTP_TOKEN=${TOKEN} \ |
83 |
| - -v "${PWD}/.mr-linter.json:/app/.mr-linter.json:ro" \ |
84 |
| - artarts36/merge-request-linter:${MR_LINTER_VERSION} lint |
85 |
| -``` |
86 |
| - |
87 |
| -## Available Commands |
88 |
| - |
89 |
| -| Command | Description | |
90 |
| -|----------------------------------------------|---------------------------------------------------------------| |
91 |
| -| ./vendor/bin/mr-linter install | Install this tool (copy configuration file to work directory) | |
92 |
| -| ./vendor/bin/mr-linter install --format=yaml | Install this tool (copy configuration file to work directory) | |
93 |
| -| ./vendor/bin/mr-linter dump | Print current rules | |
94 |
| -| ./vendor/bin/mr-linter lint | Run lint to current merge request | |
95 |
| -| ./vendor/bin/mr-linter info | Print info about MR Linter | |
96 |
| - |
97 |
| - |
98 |
| -## JSON Config |
99 |
| - |
100 |
| -[See JsonSchema](mr-linter-config-schema.json) |
101 |
| - |
102 |
| -```json |
103 |
| -{ |
104 |
| - "rules": { |
105 |
| - "@mr-linter/changed_files_limit": { |
106 |
| - "limit": 20 |
107 |
| - }, |
108 |
| - "@mr-linter/jira/has_issue_link": { |
109 |
| - "domain": "jira.com", |
110 |
| - "projectCode": "MYPROJECT", |
111 |
| - "when": { |
112 |
| - "title": { |
113 |
| - "starts": "WIP-REQUEST" |
114 |
| - } |
115 |
| - } |
116 |
| - }, |
117 |
| - "@mr-linter/description_not_empty": { |
118 |
| - "when": { |
119 |
| - "targetBranch": { |
120 |
| - "equals": "master" |
121 |
| - } |
122 |
| - } |
123 |
| - } |
124 |
| - }, |
125 |
| - "credentials": { |
126 |
| - "github_actions": "env(MR_LINTER_GITHUB_HTTP_TOKEN)" |
127 |
| - } |
128 |
| -} |
129 |
| -``` |
130 |
| - |
131 |
| -## YAML Config |
132 |
| - |
133 |
| -[See JsonSchema](mr-linter-config-schema.json) |
134 |
| - |
135 |
| -```yaml |
136 |
| -rules: |
137 |
| - "@mr-linter/changed_files_limit": |
138 |
| - limit: 20 |
139 |
| -
|
140 |
| - "@mr-linter/jira/has_issue_link": |
141 |
| - domain: "jira.com" |
142 |
| - projectCode: "MYPROJECT" |
143 |
| - when: |
144 |
| - title: |
145 |
| - starts: "WIP-REQUEST" |
146 |
| -
|
147 |
| - "@mr-linter/description_not_empty": |
148 |
| - when: |
149 |
| - targetBranch: |
150 |
| - equals: "master" |
151 |
| - |
152 |
| - custom: |
153 |
| - - definition: "Title must include 'BUG'" |
154 |
| - rules: |
155 |
| - title: |
156 |
| - match: "/BUG/i" |
157 |
| - when: |
158 |
| - targetBranch: |
159 |
| - equals: master |
160 |
| -
|
161 |
| -credentials: |
162 |
| - github_actions: "env(MR_LINTER_GITHUB_HTTP_TOKEN)" |
163 |
| -``` |
164 |
| - |
165 |
| -## Development Commands |
166 |
| - |
167 |
| -| Command | Description | |
168 |
| -|--------------------------|------------------------------------------------------| |
169 |
| -| composer test | Run tests (via PHPUnit) | |
170 |
| -| composer lint | Run lint (via PHPCsFixer) | |
171 |
| -| composer deptrac | Run deptrac | |
172 |
| -| make deps-check | Check composer requires (via ComposerRequireChecker) | |
173 |
| -| make check | Run test, lint, stat-analyse, deptrac | |
174 |
| -| make docs | Build docs (rule page, Config JSON Schema) | |
175 |
| -| make env | Add .env file | |
176 |
| -| make try MR_ID=10 | Run MR-Linter on really pull request | |
177 |
| -| make try-gitlab MR_ID=10 | Run MR-Linter on really merge request | |
| 16 | +* [Getting Started](docs/getting-started.md) |
| 17 | +* [Examples of usage](docs/examples.md) |
| 18 | +* [Show validation rules](docs/rules.md) |
| 19 | +* [Conditions](docs/conditions.md) |
| 20 | +* [Creating custom rule](docs/custom-rule.md) |
| 21 | +* [Docker Image](https://hub.docker.com/repository/docker/artarts36/merge-request-linter) |
| 22 | +* [Config JSON Schema](mr-linter-config-schema.json) |
| 23 | +* [Notifications](docs/notifications.md) |
| 24 | +* [Run in Docker](docs/run-in-docker.md) |
| 25 | +* [Development](docs/development.md) |
178 | 26 |
|
179 | 27 | ## Console output example
|
180 | 28 |
|
|
0 commit comments