Skip to content

Commit

Permalink
Set up pre-commit (#1806)
Browse files Browse the repository at this point in the history
* Add pre-commit config

Include changes automatically generated by isort and ruff.

* Add workflow job

* Update README.md

* Resolve conflicts
  • Loading branch information
arkid15r authored Feb 24, 2024
1 parent 500305e commit 66868d0
Show file tree
Hide file tree
Showing 121 changed files with 10,924 additions and 10,505 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Pre-Commit
on:
- merge_group
- pull_request
- push
- workflow_dispatch

env:
FORCE_COLOR: 1

concurrency:
cancel-in-progress: true
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}

jobs:
pre-commit:
name: Run pre-commit
runs-on: ubuntu-latest
steps:
- name: Check out Repository
uses: actions/checkout@v4

- name: Set up Python
uses: actions/[email protected]
with:
python-version: '3.11'

- name: Run pre-commit
uses: pre-commit/[email protected]
27 changes: 27 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: check-ast
# Enable after the initial automated run results are accepted.
# - id: check-builtin-literals
- id: check-yaml
- id: fix-encoding-pragma
args:
- --remove
- id: mixed-line-ending
args:
- --fix=lf

- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort
exclude: ^(docs)

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.13
hooks:
- id: ruff
args: [--fix]
- id: ruff-format
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ Please follow the development server setup procedure [here](https://github.com/O


Please follow the [black](https://github.com/psf/black) code style for the project. It helps us in keeping the codebase consistent and improves readability for other developers.
Use `pre-commit run` command to make sure your changes comply with the standards.



Expand Down
84 changes: 36 additions & 48 deletions blt/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,14 @@
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.8/ref/settings/
"""
# from google.oauth2 import service_account
import os
import socket
import sys

import dj_database_url
from django.http import Http404
from django.utils.translation import gettext_lazy as _
import environ
# from google.oauth2 import service_account
import os
import socket
from django.utils.translation import gettext_lazy as _

env = environ.Env()
# reading .env file
Expand All @@ -31,16 +29,16 @@
print("Current hostname:", current_hostname)
print(os.environ)

#if current_hostname == "owasp.org":
# if current_hostname == "owasp.org":

PROJECT_NAME = "BLT"
DOMAIN_NAME = "blt.owasp.org"
FQDN = "blt.owasp.org"
DOMAIN_NAME_PREVIOUS = os.environ.get("DOMAIN_NAME_PREVIOUS", "BLT")
DOMAIN_NAME_PREVIOUS = os.environ.get("DOMAIN_NAME_PREVIOUS", "BLT")
# else:
# # Default values if hostname does not match
# PROJECT_NAME = os.environ.get("PROJECT_NAME", "BLT")
# DOMAIN_NAME = os.environ.get("DOMAIN_NAME", "127.0.0.1")
# DOMAIN_NAME = os.environ.get("DOMAIN_NAME", "127.0.0.1")
# FQDN = "www." + DOMAIN_NAME

PROJECT_NAME_LOWER = PROJECT_NAME.lower()
Expand All @@ -52,12 +50,12 @@
SERVER_EMAIL = os.environ.get("FROM_EMAIL", "test@localhost")


EMAIL_TO_STRING = PROJECT_NAME + " <"+ SERVER_EMAIL +">"
BLOG_URL = os.environ.get("BLOG_URL","https://owasp.org/www-project-bug-logging-tool/")
FACEBOOK_URL = os.environ.get("FACEBOOK_URL","https://www.facebook.com/groups/owaspfoundation/")
TWITTER_URL = os.environ.get("TWITTER_URL","https://twitter.com/owasp")
GITHUB_URL = os.environ.get("GITHUB_URL","https://github.com/OWASP/BLT")
EXTENSION_URL = os.environ.get("EXTENSION_URL","https://github.com/OWASP/BLT")
EMAIL_TO_STRING = PROJECT_NAME + " <" + SERVER_EMAIL + ">"
BLOG_URL = os.environ.get("BLOG_URL", "https://owasp.org/www-project-bug-logging-tool/")
FACEBOOK_URL = os.environ.get("FACEBOOK_URL", "https://www.facebook.com/groups/owaspfoundation/")
TWITTER_URL = os.environ.get("TWITTER_URL", "https://twitter.com/owasp")
GITHUB_URL = os.environ.get("GITHUB_URL", "https://github.com/OWASP/BLT")
EXTENSION_URL = os.environ.get("EXTENSION_URL", "https://github.com/OWASP/BLT")

ADMINS = (("Admin", DEFAULT_FROM_EMAIL),)

Expand Down Expand Up @@ -122,7 +120,7 @@
"allauth.account.middleware.AccountMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
'allauth.account.middleware.AccountMiddleware',#Newly added for allauth 0.60.1
"allauth.account.middleware.AccountMiddleware", # Newly added for allauth 0.60.1
"django.middleware.clickjacking.XFrameOptionsMiddleware",
"django.middleware.security.SecurityMiddleware",
"whitenoise.middleware.WhiteNoiseMiddleware",
Expand Down Expand Up @@ -201,9 +199,7 @@
# }


REST_AUTH = {
'SESSION_LOGIN': False
}
REST_AUTH = {"SESSION_LOGIN": False}
CONN_MAX_AGE = None

WSGI_APPLICATION = "blt.wsgi.application"
Expand Down Expand Up @@ -286,7 +282,6 @@
GS_SECRET_ACCESS_KEY = os.environ.get("GS_SECRET_ACCESS_KEY", "blank")
GOOGLE_APPLICATION_CREDENTIALS = "/app/google-credentials.json"


GS_BUCKET_NAME = "bhfiles"
DEFAULT_FILE_STORAGE = "storages.backends.gcloud.GoogleCloudStorage"
GS_FILE_OVERWRITE = False
Expand All @@ -295,6 +290,7 @@

import sentry_sdk
from sentry_sdk.integrations.django import DjangoIntegration

sentry_sdk.init(
dsn=os.environ.get("SENTRY_DSN", "https://key.ingest.sentry.io/project"),
integrations=[DjangoIntegration()],
Expand All @@ -320,7 +316,14 @@
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")

# Allow all host headers
ALLOWED_HOSTS = ["." + DOMAIN_NAME, "127.0.0.1", "localhost", "0.0.0.0", "blt.owasp.org", "." + DOMAIN_NAME_PREVIOUS]
ALLOWED_HOSTS = [
"." + DOMAIN_NAME,
"127.0.0.1",
"localhost",
"0.0.0.0",
"blt.owasp.org",
"." + DOMAIN_NAME_PREVIOUS,
]

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.8/howto/static-files/
Expand All @@ -331,8 +334,8 @@
# Extra places for collectstatic to find static files.
STATICFILES_DIRS = (
os.path.join(BASE_DIR, "static"),
os.path.join(BASE_DIR, "website","static"),
os.path.join(BASE_DIR, "company","static"),
os.path.join(BASE_DIR, "website", "static"),
os.path.join(BASE_DIR, "company", "static"),
)

ABSOLUTE_URL_OVERRIDES = {
Expand Down Expand Up @@ -374,9 +377,7 @@
CACHES = {"default": {"BACKEND": "django.core.cache.backends.locmem.LocMemCache"}}
else:
if os.environ.get("MEMCACHIER_SERVERS", ""):
os.environ["MEMCACHE_SERVERS"] = os.environ.get(
"MEMCACHIER_SERVERS", ""
).replace(",", ";")
os.environ["MEMCACHE_SERVERS"] = os.environ.get("MEMCACHIER_SERVERS", "").replace(",", ";")
os.environ["MEMCACHE_USERNAME"] = os.environ.get("MEMCACHIER_USERNAME", "")
os.environ["MEMCACHE_PASSWORD"] = os.environ.get("MEMCACHIER_PASSWORD", "")

Expand All @@ -400,14 +401,12 @@
}
}
else:
CACHES = {
"default": {"BACKEND": "django.core.cache.backends.locmem.LocMemCache"}
}
CACHES = {"default": {"BACKEND": "django.core.cache.backends.locmem.LocMemCache"}}

CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
'LOCATION': 'unique-snowflake',
"default": {
"BACKEND": "django.core.cache.backends.locmem.LocMemCache",
"LOCATION": "unique-snowflake",
}
}

Expand All @@ -422,23 +421,14 @@
REST_FRAMEWORK = {
"DEFAULT_PAGINATION_CLASS": "rest_framework.pagination.PageNumberPagination",
"DEFAULT_FILTER_BACKENDS": ("django_filters.rest_framework.DjangoFilterBackend",),
"DEFAULT_AUTHENTICATION_CLASSES": (
"rest_framework.authentication.TokenAuthentication",
),
"DEFAULT_AUTHENTICATION_CLASSES": ("rest_framework.authentication.TokenAuthentication",),
"PAGE_SIZE": 10,
'DEFAULT_THROTTLE_RATES': {
'anon': f'{anon_throttle}/day',
'user': f'{user_throttle}/day'
}
"DEFAULT_THROTTLE_RATES": {"anon": f"{anon_throttle}/day", "user": f"{user_throttle}/day"},
}

SOCIALACCOUNT_PROVIDER = {
'github': {
'scope': ('user:email',)
},
'google': {
'scope': ('user:email',)
}
"github": {"scope": ("user:email",)},
"google": {"scope": ("user:email",)},
}

X_FRAME_OPTIONS = "SAMEORIGIN"
Expand Down Expand Up @@ -491,9 +481,7 @@

SUPERUSERS = ((SUPERUSER_USERNAME, SUPERUSER_EMAIL, SUPERUSER_PASSWORD),)

STRIPE_LIVE_PUBLIC_KEY = os.environ.get(
"STRIPE_LIVE_PUBLIC_KEY", "<your publishable key>"
)
STRIPE_LIVE_PUBLIC_KEY = os.environ.get("STRIPE_LIVE_PUBLIC_KEY", "<your publishable key>")
STRIPE_LIVE_SECRET_KEY = os.environ.get("STRIPE_LIVE_SECRET_KEY", "<your secret key>")
STRIPE_TEST_PUBLIC_KEY = os.environ.get(
"STRIPE_TEST_PUBLIC_KEY",
Expand Down Expand Up @@ -524,7 +512,7 @@
IS_TEST = True


# Twitter
# Twitter

BEARER_TOKEN = os.environ.get("BEARER_TOKEN")
APP_KEY = os.environ.get("APP_KEY")
Expand Down
Loading

0 comments on commit 66868d0

Please sign in to comment.