Skip to content

Commit 410ce83

Browse files
authored
Add pre-commit config and a new workflow to run the pre-commit hooks on any PR (#503)
* properly configure lint scripts * add flake8 as a dev requirements * add pre-commit config * add pre-commit workflow * properly configure path of misconfigured lint-fix in cli/ * lint fix all files after adding pre-commit * bump up pre-commit * run node 18 dependencies before 16, so node 16 can do linting for both cli and webserver * lint fix we rebase * docs update for pre-commit * docs update and add autoflake * add eslint in the contributing guidelines * grammatical correction and remove eslint-next for cli
1 parent 9d5d161 commit 410ce83

File tree

105 files changed

+589
-260
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+589
-260
lines changed

.flake8

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[flake8]
2+
max-line-length = 110

.github/ISSUE_TEMPLATE/bug.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ labels: bug
2727
<!-- Feel Free to Remove this section if you are a user and don't have the exact server details -->
2828
<!-- Additional Information which may be useful. Add whatever information is available, skip the field which are not available-->
2929

30-
- Operating System:
30+
- Operating System:
3131
- Deployment Method: <!-- snap/docker/tar/etc -->
3232

3333

.github/ISSUE_TEMPLATE/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ contact_links:
55
about: Hang out with the community of Engineering Managers, Tech Leads, and CTOs.
66
- name: Get on a Call
77
url: https://calendly.com/middleware-dhruv/30min
8-
about: Get a tailored demo for your use cases
8+
about: Get a tailored demo for your use cases

.github/ISSUE_TEMPLATE/feature.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ labels: enhancement
1717
- [ ] TODO 2
1818
- [ ] TODO 3
1919

20-
## Further Comments / References
20+
## Further Comments / References
2121

2222
<!-- Any additional comments for this . -->
23-
<!-- Add References to similar features provided by any other platform(if possible) -->
23+
<!-- Add References to similar features provided by any other platform(if possible) -->

.github/pull_request_template.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## Linked Issue(s)
1+
## Linked Issue(s)
22

33
<!-- Link the issues being closed by or related to this PR. For example, you can use Closes #594 if this PR closes issue number 594 -->
44

.github/workflows/black.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ jobs:
3030
run: python -m pip install black==24.3.0
3131

3232
- name: Run Black Check
33-
run: black . --check
33+
run: black . --check

.github/workflows/build.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on:
55
types: [published]
66
push:
77
branches: ["main"]
8-
paths:
8+
paths:
99
- 'Dockerfile'
1010
- 'backend/**'
1111
- 'database-docker/**'
@@ -125,7 +125,7 @@ jobs:
125125
run: |
126126
mkdir -p /tmp/digests
127127
digest="${{ steps.build.outputs.digest }}"
128-
touch "/tmp/digests/${digest#sha256:}"
128+
touch "/tmp/digests/${digest#sha256:}"
129129
130130
131131
- name: Upload digest
@@ -186,11 +186,11 @@ jobs:
186186
stop-runner-arm:
187187
name: Stop self-hosted EC2 arm runner
188188
needs:
189-
- start-runner-arm
189+
- start-runner-arm
190190
- build
191191
- merge
192192
runs-on: ubuntu-latest
193-
if: ${{ always() }}
193+
if: ${{ always() }}
194194
steps:
195195
- name: Configure AWS credentials
196196
uses: aws-actions/configure-aws-credentials@v1
@@ -205,4 +205,3 @@ jobs:
205205
github-token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
206206
label: ${{ needs.start-runner-arm.outputs.label }}
207207
ec2-instance-id: ${{ needs.start-runner-arm.outputs.ec2-instance-id }}
208-

.github/workflows/pre-commit.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Linting-Precommit
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
jobs:
12+
pre_job:
13+
name: Path match check
14+
runs-on: ubuntu-latest
15+
outputs:
16+
should_skip: ${{ steps.skip_check.outputs.should_skip }}
17+
steps:
18+
- id: skip_check
19+
uses: fkirc/skip-duplicate-actions@master
20+
with:
21+
github_token: ${{ secrets.GITHUB_TOKEN }}
22+
paths_ignore: '["**.po", "**.json"]'
23+
24+
linting:
25+
name: All file linting
26+
needs: pre_job
27+
if: ${{ needs.pre_job.outputs.should_skip != 'true' }}
28+
runs-on: ubuntu-latest
29+
steps:
30+
- uses: actions/checkout@v4
31+
32+
- name: Setup Node.js 18
33+
uses: actions/setup-node@v3
34+
with:
35+
node-version: 18
36+
37+
- name: Install dependencies for cli
38+
run: yarn add eslint@^8.40.0 eslint-plugin-import@^2.29.0 eslint-plugin-prettier@^5.0.1 eslint-plugin-react@^7.29.4 eslint-plugin-unused-imports@^3.0.0 --dev
39+
working-directory: cli
40+
41+
- name: Setup Node.js 16
42+
uses: actions/setup-node@v3
43+
with:
44+
node-version: 16
45+
46+
- name: Install dependencies for web-server
47+
run: yarn add eslint@^8.40.0 [email protected] eslint-plugin-import@^2.29.0 eslint-plugin-prettier@^5.0.1 eslint-plugin-react@^7.29.4 eslint-plugin-unused-imports@^3.0.0 --dev
48+
working-directory: web-server
49+
50+
- name: Run pre-commit hooks
51+
uses: pre-commit/[email protected]

.github/workflows/pytest.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
pip install -r requirements.txt
3434
3535
- name: Test with pytest
36-
env:
36+
env:
3737
DB_HOST: "localhost"
3838
DB_NAME: "mhq-oss"
3939
DB_PASS: "postgres"

.pre-commit-config.yaml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
exclude: (\.git/|\.tox/|\.venv/|build/|static/|dist/|node_modules/|__init__.py|app.py|sync_app.py)
2+
repos:
3+
- repo: https://github.com/pre-commit/pre-commit-hooks
4+
rev: v4.0.1
5+
hooks:
6+
- id: trailing-whitespace
7+
- id: check-yaml
8+
- id: end-of-file-fixer
9+
- repo: https://github.com/PyCQA/flake8
10+
rev: 7.1.1
11+
hooks:
12+
- id: flake8
13+
args:
14+
- --ignore=E501,W503,W605
15+
16+
# I dont find any dedicated hook for this, so using a custom one
17+
- repo: local
18+
hooks:
19+
- id: linting webserver
20+
name: Linting-webserver
21+
entry: bash -c 'cd web-server && yarn lint-fix'
22+
language: system
23+
- repo: local
24+
hooks:
25+
- id: linting cli
26+
name: Linting-cli
27+
entry: bash -c 'cd cli && yarn lint-fix'
28+
language: system
29+
- repo: https://github.com/PyCQA/autoflake
30+
rev: v2.3.1
31+
hooks:
32+
- id: autoflake
33+
args: [--remove-all-unused-imports, --in-place]
34+
# black fixes code, so let it be at the last
35+
- repo: https://github.com/psf/black
36+
rev: 24.8.0
37+
hooks:
38+
- id: black

CONTRIBUTING.md

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,53 @@ We use pull requests for code contributions. To submit a pull request:
1414

1515
1. Fork the repository.
1616
2. Create a new branch for your feature or bug fix.
17-
3. Make your changes and commit them with clear and concise messages.
17+
3. Make your changes and commit them with clear and concise messages. Refer [Making Commits](#making-commits)
1818
4. Push your changes to your fork.
1919
5. Submit a pull request to the main repository, detailing the changes you've made and referencing any relevant issues.
2020

2121
## Code Style
2222

23-
Please follow the existing code style and conventions used in the project. If you're unsure, feel free to ask for clarification in the pull request or issue comments.
23+
Please follow the existing code style and conventions used in the project. If you're unsure, feel free to ask for clarification in the pull request or issue comments. For linting and all refer [Making Commits](#making-commits)
24+
25+
## Making Commits
26+
27+
1. Pre-commit should be installed as a dev dependency already. If not then Create a virual environment [venv](https://packaging.python.org/en/latest/guides/installing-using-pip-and-virtual-environments/#create-and-use-virtual-environments) or [pyenv](https://github.com/pyenv/pyenv?tab=readme-ov-file#installation) and run the following command from project root dir:
28+
29+
```
30+
pip install -r backend/dev-requirements.txt --upgrade
31+
```
32+
Also install the eslint for both `cli/` and `webserver/`. Please use node 16 for that
33+
*NOTE*: If NVM is not installed, install using [nvm](https://github.com/nvm-sh/nvm?tab=readme-ov-file#installing-and-updating)
34+
```
35+
nvm install 16
36+
nvm use 16
37+
```
38+
```
39+
cd cli
40+
yarn add eslint@^8.40.0 eslint-plugin-import@^2.29.0 eslint-plugin-prettier@^5.0.1 eslint-plugin-react@^7.29.4 eslint-plugin-unused-imports@^3.0.0 --dev
41+
```
42+
```
43+
cd web-server
44+
yarn add eslint@^8.40.0 [email protected] eslint-plugin-import@^2.29.0 eslint-plugin-prettier@^5.0.1 eslint-plugin-react@^7.29.4 eslint-plugin-unused-imports@^3.0.0 --dev
45+
```
46+
Then install it:
47+
```
48+
pre-commit install
49+
```
50+
2. Then after adding the changes to staging, commit it normally. You will observe pre-commit hooks running.
51+
52+
*NOTE*: The pre-commit hooks modifies the files and you have to again add the modified changes to staging and then commit
53+
54+
3. You can run the pre-commit without committing anything as
55+
```
56+
pre-commit run --all-files
57+
```
58+
or
59+
```
60+
pre-commit run --files [path/to/file]
61+
```
62+
63+
*NOTE*: Make sure the terminal is using node 16 for the linting before committing(Until we upgrade node for webserver)
2464
2565
## Labels
2666
@@ -33,7 +73,7 @@ We use the following labels to categorize and prioritize issues:
3373
- `good first issue`: Indicates that the issue is suitable for newcomers to the project.
3474
- `priority`: high/medium/low: Indicates the priority level of the issue.
3575
- `discussion`: Indicates that the issue is open for discussion and feedback.
36-
76+
3777
If you're creating a new issue, please apply the appropriate labels to help us better organize and address it.
3878
3979
## Feedback

README.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,9 @@ They are:
114114

115115
### ☁️ Using GitPod
116116

117-
Gitpod enables development on remote machines and helps you get started with Middleware if your machine does not support running the project locally.
117+
Gitpod enables development on remote machines and helps you get started with Middleware if your machine does not support running the project locally.
118118

119-
If you want to run the project locally you can [setup using docker](#-using-docker) or [setup everything manually](#-manual-setup).
119+
If you want to run the project locally you can [setup using docker](#-using-docker) or [setup everything manually](#-manual-setup).
120120

121121
1. Click the button below to open this project in Gitpod.
122122

@@ -162,8 +162,8 @@ Make sure docker is running.
162162
- The postgres database can be accessed at host: `localhost`, port: `5434`, username: `postgres`, password: `postgres`, db name: `mhq-oss`.
163163
- The redis server can be accessed at host: `localhost`, port: `6385`.
164164

165-
5. **View the logs**: Although the CLI tracks all logs, the logs of services running inside the container can be viewed in different terminals using the following commands:
166-
165+
5. **View the logs**: Although the CLI tracks all logs, the logs of services running inside the container can be viewed in different terminals using the following commands:
166+
167167
**Frontend logs**
168168
```bash
169169
docker exec -it middleware-dev tail --lines 500 -f /var/log/web-server/web-server.log
@@ -205,13 +205,13 @@ To set up middleware locally, follow these steps:
205205
3. **Run Redis and Postgres Containers**:
206206

207207
If you don't have docker installed, please install docker [over here](https://docs.docker.com/get-docker/)
208-
208+
209209
Run the following commands to run Postgres and Redis using docker.
210210

211211
```bash
212212
cd database-docker && docker-compose up -d
213213
```
214-
214+
215215
If you don't prefer Docker, you can choose to install [Postgres](https://www.postgresql.org/download/) and [Redis](https://redis.io/docs/latest/operate/oss_and_stack/install/install-redis/) manually.
216216
217217
Once you are done with using or developing Middleware, you can choose to close these running container. (NOTE: Don't do this if you are following this document and trying to run Middleware.)
@@ -222,7 +222,7 @@ To set up middleware locally, follow these steps:
222222
```
223223

224224
4. **Generate Encryption keys**:
225-
225+
226226
Generate encryption keys for the project by running the following command in the project root directory:
227227

228228
```bash
@@ -232,14 +232,14 @@ To set up middleware locally, follow these steps:
232232
5. **Backend Server Setup**
233233

234234
- Install python version `3.11.6`
235-
235+
236236
- For this you can install python from [over here](https://www.python.org/downloads/) if you don't have it on your machine.
237237
- Install pyenev
238-
238+
239239
```bash
240240
git clone https://github.com/pyenv/pyenv.git ~/.pyenv
241241
```
242-
242+
243243
- Add pyenv to your shell's configuration file (.bashrc, .bash_profile, .zshrc, etc.):
244244

245245
```bash
@@ -251,7 +251,7 @@ To set up middleware locally, follow these steps:
251251
```
252252
source ~/.bashrc
253253
```
254-
- Move backend directory to create a virtual environment
254+
- Move backend directory to create a virtual environment
255255

256256
```bash
257257
cd backend
@@ -263,7 +263,7 @@ To set up middleware locally, follow these steps:
263263
```bash
264264
. venv/bin/activate
265265
```
266-
266+
267267
- Install Dependencies
268268

269269
```bash
@@ -286,22 +286,22 @@ To set up middleware locally, follow these steps:
286286
```
287287

288288
- Start the backend servers
289-
289+
290290
- Change Directory to analytics_server
291291
```bash
292292
cd analytics_server
293293
```
294-
294+
295295
- For backend analytics server:
296296
```bash
297297
flask --app app --debug run --port 9696
298298
```
299-
299+
300300
- For backend sync server:
301301
```bash
302302
flask --app sync_app --debug run --port 9697
303303
```
304-
NOTE: Open this sync sever in a new terminal window after activating the virtual environment only after starting analytics server.
304+
NOTE: Open this sync sever in a new terminal window after activating the virtual environment only after starting analytics server.
305305

306306
6. **Web Server Setup**
307307

@@ -316,7 +316,7 @@ To set up middleware locally, follow these steps:
316316
cd web-server
317317
yarn
318318
```
319-
319+
320320
- Start the web-server
321321
```bash
322322
yarn dev
@@ -413,7 +413,7 @@ We look forward to your part in keeping Middleware secure!
413413
414414
415415
## License
416-
416+
417417
This project is licensed under the [Apache 2.0](https://github.com/middlewarehq/middleware/blob/main/LICENSE) License - see the LICENSE.md file for details.
418418
419419

SECURITY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ This document outlines the security practices and considerations for the middlew
77
We appreciate your help in keeping middleware secure. If you discover a security vulnerability, please report it responsibly by following these steps:
88

99
* **Email:** Send an email to [[email protected]](mailto:[email protected]).
10-
* **Include:**
10+
* **Include:**
1111
* A detailed description of the vulnerability, including the affected components and potential impact.
1212
* Steps to reproduce the vulnerability (if possible), including any specific code snippets or configurations.
1313
* Any additional information that may help us understand and address the vulnerability.

backend/analytics_server/mhq/api/deployment_analytics.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
)
2222
from mhq.service.deployments.analytics import get_deployment_analytics_service
2323
from mhq.service.query_validator import get_query_validator
24-
from mhq.store.models import SettingType, EntityType, Team
24+
from mhq.store.models import SettingType, EntityType
2525
from mhq.store.models.code.filter import PRFilter
2626
from mhq.store.models.code.pull_requests import PullRequest
27-
from mhq.store.models.code.repository import OrgRepo, TeamRepos
27+
from mhq.store.models.code.repository import OrgRepo
2828
from mhq.store.models.code.workflows.filter import WorkflowFilter
2929
from mhq.service.deployments.models.models import (
3030
Deployment,

0 commit comments

Comments
 (0)