Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pre-commit hooks for code checks #6407

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 2 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
- checkout
- run:
name: flake8 tests
command: |
command: |
pip install flake8
flake8 manage.py backend tests migrations

Expand All @@ -53,7 +53,7 @@ jobs:
- checkout
- run:
name: black tests
command: |
command: |
pip install 'black==23.12.1' ## TODO: Update to version 24
black --check manage.py backend tests migrations

Expand Down Expand Up @@ -509,5 +509,3 @@ workflows:
- backend-code-check-PEP8
- backend-code-check-Black
- backend-functional-tests


2 changes: 1 addition & 1 deletion .circleci/rdsid.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ for line in $ARNS; do
if [[ ! -z $MATCHES ]]; then
echo $MATCHES
fi
done
done
2 changes: 1 addition & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ exclude_lines =

# Don't complain if tests don't hit defensive assertion code:
except Exception as e:


ignore_errors = True

Expand Down
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,3 @@ frontend/package-lock.json
frontend/.env
frontend/.eslintcache
frontend/coverage/

106 changes: 106 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: trailing-whitespace
name: trim trailing whitespace
description: trims trailing whitespace.
entry: trailing-whitespace-fixer
language: python
types: [text]
stages: [commit, push, manual]

- id: end-of-file-fixer
name: fix end of files
description: ensures that a file is either empty, or ends with one newline.
entry: end-of-file-fixer
language: python
types: [text]
stages: [commit, push, manual]

- id: detect-aws-credentials
name: detect aws credentials
description: detects *your* aws credentials from the aws cli credentials file.
entry: detect-aws-credentials
language: python
types: [text]
args:
- "--allow-missing-credentials"

- id: detect-private-key
name: detect private key
description: detects the presence of private keys.
entry: detect-private-key
language: python
types: [text]

# - id: pretty-format-json
# name: pretty format json
# description: sets a standard for formatting json files.
# entry: pretty-format-json
# language: python
# types: [text]
# files: \.(json)$
# args:
# - "--autofix"

- id: check-merge-conflict
name: check for merge conflicts
description: checks for files that contain merge conflict strings.
entry: check-merge-conflict
language: python
types: [text]

- id: check-yaml
name: YAML File check
description: Checks if YAML File is valid and there are not any indention errors.

- id: check-added-large-files
name: check for added large files
description: prevents giant files from being committed.
entry: check-added-large-files
language: python
stages: [commit, push, manual]
args: ['--maxkb=10240']

# Versioning: Commit messages & changelog
- repo: https://github.com/commitizen-tools/commitizen
rev: v3.13.0
hooks:
- id: commitizen
stages: [commit-msg]

# Lint / autoformat: Python code
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: "v0.4.2"
hooks:
# Run the linter
- id: ruff
files: ^backend/(?:.*/)*.*$
args: [--fix, --exit-non-zero-on-fix]
# Run the formatter
- id: ruff-format
files: ^backend/(?:.*/)*.*$

# INFO: Searches for code that is used or lingering around. (Disabled since there were a lot of work from dev end to remove stuff)
# - repo: https://github.com/asottile/dead
# rev: v1.5.2
# hooks:
# - id: dead

# Autoformat: YAML, JSON, Markdown, etc. (Disabled since pre-commit wasn't able to fix and needs dev input)
# - repo: https://github.com/pre-commit/mirrors-prettier
# rev: v3.1.0
# hooks:
# - id: prettier
# args:
# [
# --ignore-unknown,
# --no-error-on-unmatched-pattern,
# "!chart/**",
# "!CHANGELOG.md",
# "!CONTRIBUTING.md",
# "!frontend/pnpm-lock.yaml",
# "!backend/tests/test_data/**",
# ]
1 change: 0 additions & 1 deletion .tx/config
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,3 @@ trans.el = frontend/src/locales/el.json
trans.it = frontend/src/locales/it.json
trans.ja = frontend/src/locales/ja.json
trans.zh_TW = frontend/src/locales/zh_TW.json

4 changes: 2 additions & 2 deletions backend/models/postgis/tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def get_all_organisations():
)

dto = TagsDTO()
dto.tags = [r for r, in result]
dto.tags = [r for (r,) in result]
return dto

@staticmethod
Expand All @@ -58,5 +58,5 @@ def get_all_campaigns():
result = db.session.query(Tags.campaigns).filter(Tags.campaigns.isnot(None))

dto = TagsDTO()
dto.tags = [r for r, in result]
dto.tags = [r for (r,) in result]
return dto
2 changes: 1 addition & 1 deletion backend/services/messaging/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ <h1 style="font-family: sans-serif; font-weight: 500; margin: 0 0 20px 0; font-s
</td>
</tr>
</table>
</div>
</div>
</div>
</td>
</tr>
Expand Down
22 changes: 11 additions & 11 deletions backend/services/messaging/templates/encourage_mapper_en.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
Hi {{ values["USERNAME"] }}
</h1>
<p style="margin-bottom: 1.714rem; line-height: 1.5;">
you recently participated in the mapping project -
<a style="color: #d73f3f; font-weight: 700" href="{{values['APP_BASE_URL']}}/projects/{{values['PROJECT_ID']}}">{{values['PROJECT_NAME']}}</a> - on the
you recently participated in the mapping project -
<a style="color: #d73f3f; font-weight: 700" href="{{values['APP_BASE_URL']}}/projects/{{values['PROJECT_ID']}}">{{values['PROJECT_NAME']}}</a> - on the
<a style="color: #d73f3f; font-weight: 700" href="{{values['APP_BASE_URL']}}">{{values["ORG_CODE"]}} Tasking Manager</a>.
We want to inform you the project has reached <span style=" font-weight: 700">{{ values["PROJECT_COMPLETION"] }}% </span> of completeness.
<br> <br>
Expand All @@ -37,10 +37,10 @@
Hi {{ values["USERNAME"] }}
</h1>
<p style="margin-bottom: 1.714rem; line-height: 1.5;">
you recently participated in the mapping project -
<a style="color: #d73f3f; font-weight: 700" href="{{values['APP_BASE_URL']}}/projects/{{values['PROJECT_ID']}}">{{values['PROJECT_NAME']}}</a> - on the
you recently participated in the mapping project -
<a style="color: #d73f3f; font-weight: 700" href="{{values['APP_BASE_URL']}}/projects/{{values['PROJECT_ID']}}">{{values['PROJECT_NAME']}}</a> - on the
<a style="color: #d73f3f; font-weight: 700" href="{{values['APP_BASE_URL']}}">{{values["ORG_CODE"]}} Tasking Manager</a>.
We want to inform you the project has been completed. It is time to celebrate!
We want to inform you the project has been completed. It is time to celebrate!
<br>
Do you want to continue? Find the suitable project for you here: <a style="color: #d73f3f" href="{{values['APP_BASE_URL']}}/explore">{{values['APP_BASE_URL']}}/explore</a>
</p>
Expand Down Expand Up @@ -92,7 +92,7 @@
aria-label=""
style="border-collapse: separate; mso-table-lspace: 0pt; mso-table-rspace: 0pt; width: 100%; margin-bottom:2.285rem;"> <!-- Noncompliant -->
<th style="width:60%;">
<img style="text-decoration: none; font-weight: normal;"
<img style="text-decoration: none; font-weight: normal;"
src={{ project.org_logo }}
alt="logo of the organization" height="32"/>
</th>
Expand All @@ -109,19 +109,19 @@
<p style="
padding: 5px 8px;
border-radius: 2px;
border: 1px solid #faa71e;
border: 1px solid #faa71e;
color: #faa71e;">
{% elif project.priority == "MEDIUM" %}
<p style="
padding: 5px 8px;
border-radius: 2px;
border: 1px solid #929DB3;
border: 1px solid #929DB3;
color: #929DB3;">
{% elif project.priority == "LOW" %}
<p style="
padding: 5px 8px;
border-radius: 2px;
border: 1px solid #68707f;
border: 1px solid #68707f;
color: #68707f;">
{% endif %}
{{ project.priority }}
Expand Down Expand Up @@ -189,8 +189,8 @@
</div>
</div>
</div>
<table
aria-label=""
<table
aria-label=""
style="
margin-top: 4px;
align-items: center;
Expand Down
10 changes: 5 additions & 5 deletions backend/services/messaging/templates/profile-progress.html
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,11 @@
<tbody>
<tr>
<td style=" padding: 11px 24px; border: #d73f3f; border-radius:2px;" bgcolor="#d73f3f">
<a
href="{{values['APP_BASE_URL']}}/settings"
<a
href="{{values['APP_BASE_URL']}}/settings"
style="
font-size:1.142rem;
color: #ffffff;
font-size:1.142rem;
color: #ffffff;
text-decoration: none;
display: inline-block;
"
Expand All @@ -137,4 +137,4 @@
</table>
<!-- button component ends -->
</div>
{% endblock %}
{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
<br>
<div style="padding: 0 2.357rem">
<p>
Project
Project
<a style="color: #d73f3f" href="{{values['APP_BASE_URL']}}/projects/{{values['PROJECT_ID']}}">{{values['PROJECT_NAME']}}</a>
associated with your organisation
associated with your organisation
<a style="color: #d73f3f" href="{{values['APP_BASE_URL']}}/organisations/{{values['PROJECT_ORG_ID']}}">{{values['PROJECT_ORG_NAME']}}</a>
has been transferred to
has been transferred to
<a style="color: #d73f3f" href="{{values['APP_BASE_URL']}}/users/{{values['TRANSFERRED_TO']}}">{{values['TRANSFERRED_TO']}}</a>
by
<a style="color: #d73f3f" href="{{values['APP_BASE_URL']}}/users/{{values['TRANSFERRED_BY']}}">{{values['TRANSFERRED_BY']}}</a>
on
<a style="color: #d73f3f" href="{{values['APP_BASE_URL']}}/users/{{values['TRANSFERRED_BY']}}">{{values['TRANSFERRED_BY']}}</a>
on
<a style="color: #d73f3f; font-weight: 700" href="{{values['APP_BASE_URL']}}">{{values["ORG_CODE"]}} Tasking Manager</a>.
</p>
<br><br>
Please ignore this email if you have received it by mistake.<br>
Many thanks,<br>
{{values['ORG_NAME']}}<br>
</div>
{% endblock %}
{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
Validated
</td>
</tr>
</table>
</table>
<p
style="
font-size: 14px;
Expand Down Expand Up @@ -101,11 +101,11 @@
<tbody>
<tr>
<td style=" padding: 11px 24px; border: #d73f3f; border-radius:2px;" bgcolor="#d73f3f">
<a
href="{{values['APP_BASE_URL']}}/learn"
<a
href="{{values['APP_BASE_URL']}}/learn"
style="
font-size:1.142rem;
color: #ffffff;
font-size:1.142rem;
color: #ffffff;
text-decoration: none;
display: inline-block;
"
Expand Down
10 changes: 5 additions & 5 deletions backend/services/messaging/templates/welcome.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@
<tbody>
<tr>
<td style=" padding: 11px 24px; border: #d73f3f; border-radius:2px;" bgcolor="#d73f3f">
<a
href="{{values['APP_BASE_URL']}}"
<a
href="{{values['APP_BASE_URL']}}"
style="
font-size:1.142rem;
color: #ffffff;
font-size:1.142rem;
color: #ffffff;
text-decoration: none;
display: inline-block;
"
Expand All @@ -69,4 +69,4 @@
</table>
<!-- table component ends -->
</div>
{% endblock %}
{% endblock %}
2 changes: 1 addition & 1 deletion docker-compose.override.sample.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ services:
- 3000:3000
volumes:
- ./frontend:/usr/src/app
- /usr/src/app/node_modules
- /usr/src/app/node_modules
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ volumes:
name: tm-db-data-main

networks:
tm-net:
tm-net:
name: tm-net

services:
Expand Down