Skip to content

Commit

Permalink
Merge pull request #103 from blaggacao/refactor-formatting
Browse files Browse the repository at this point in the history
refactor formatting
  • Loading branch information
blaggacao authored Oct 2, 2024
2 parents 7ce9dd5 + d2d7278 commit 8b57e6d
Show file tree
Hide file tree
Showing 35 changed files with 478 additions and 286 deletions.
130 changes: 130 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
{
"env": {
"browser": true,
"node": true,
"es2022": true
},
"parserOptions": {
"sourceType": "module"
},
"extends": "eslint:recommended",
"rules": {
"indent": "off",
"brace-style": "off",
"no-mixed-spaces-and-tabs": "off",
"no-useless-escape": "off",
"space-unary-ops": ["error", { "words": true }],
"linebreak-style": "off",
"quotes": ["off"],
"semi": "off",
"camelcase": "off",
"no-unused-vars": "off",
"no-console": ["warn"],
"no-extra-boolean-cast": ["off"],
"no-control-regex": ["off"]
},
"root": true,
"globals": {
"frappe": true,
"Vue": true,
"SetVueGlobals": true,
"erpnext": true,
"hub": true,
"$": true,
"jQuery": true,
"moment": true,
"hljs": true,
"Awesomplete": true,
"CalHeatMap": true,
"Sortable": true,
"Showdown": true,
"Taggle": true,
"Gantt": true,
"Slick": true,
"PhotoSwipe": true,
"PhotoSwipeUI_Default": true,
"fluxify": true,
"io": true,
"c3": true,
"__": true,
"_p": true,
"_f": true,
"repl": true,
"Class": true,
"locals": true,
"cint": true,
"cstr": true,
"cur_frm": true,
"cur_dialog": true,
"cur_page": true,
"cur_list": true,
"cur_tree": true,
"cur_pos": true,
"msg_dialog": true,
"is_null": true,
"in_list": true,
"has_common": true,
"posthog": true,
"has_words": true,
"validate_email": true,
"open_web_template_values_editor": true,
"get_number_format": true,
"format_number": true,
"format_currency": true,
"round_based_on_smallest_currency_fraction": true,
"roundNumber": true,
"comment_when": true,
"replace_newlines": true,
"open_url_post": true,
"toTitle": true,
"lstrip": true,
"strip": true,
"strip_html": true,
"replace_all": true,
"flt": true,
"precision": true,
"md5": true,
"CREATE": true,
"AMEND": true,
"CANCEL": true,
"copy_dict": true,
"get_number_format_info": true,
"print_table": true,
"Layout": true,
"web_form_settings": true,
"$c": true,
"$a": true,
"$i": true,
"$bg": true,
"$y": true,
"$c_obj": true,
"$c_obj_csv": true,
"refresh_many": true,
"refresh_field": true,
"toggle_field": true,
"get_field_obj": true,
"get_query_params": true,
"unhide_field": true,
"hide_field": true,
"set_field_options": true,
"getCookie": true,
"getCookies": true,
"get_url_arg": true,
"get_server_fields": true,
"set_multiple": true,
"QUnit": true,
"Chart": true,
"Cypress": true,
"cy": true,
"describe": true,
"expect": true,
"it": true,
"context": true,
"before": true,
"beforeEach": true,
"onScan": true,
"extend_cscript": true,
"localforage": true,
"Plaid": true
}
}
15 changes: 15 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Since version 2.23 (released in August 2019), git-blame has a feature
# to ignore or bypass certain commits.
#
# This file contains a list of commits that are not likely what you
# are looking for in a blame, such as mass reformatting or renaming.
# You can set this file as a default ignore file for blame by running
# the following command.
#
# $ git config blame.ignoreRevsFile .git-blame-ignore-revs

# pre-commit formatting ruff, eslint, prettier (automated)
63a4acf6c9fe9657fa6d7ad659465b0d5ef3d73f

# pre-commit formatting ruff, eslint, prettier (manual fixup)
cecf0bec9de2dcd176fc632e8a5348ab2f491cbe
4 changes: 4 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Any python files modifed but no test files modified
needs-tests:
- any: ['payments/**/*.py']
all: ['!payments/**/test*.py']
49 changes: 36 additions & 13 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,47 @@ repos:
- id: check-yaml
- id: debug-statements

- repo: https://github.com/asottile/pyupgrade
rev: v2.34.0
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v2.7.1
hooks:
- id: pyupgrade
args: ['--py310-plus']
- id: prettier
types_or: [javascript, vue, scss]
# Ignore any files that might contain jinja / bundles
exclude: |
(?x)^(
payments/public/dist/.*|
cypress/.*|
.*node_modules.*|
payments/templates/includes/.*
)$
- repo: https://github.com/adityahase/black
rev: 9cb0a69f4d0030cdf687eddf314468b39ed54119
- repo: https://github.com/pre-commit/mirrors-eslint
rev: v8.44.0
hooks:
- id: black
additional_dependencies: ['click==8.0.4']
- id: eslint
types_or: [javascript]
args: ['--quiet']
# Ignore any files that might contain jinja / bundles
exclude: |
(?x)^(
payments/public/dist/.*|
cypress/.*|
.*node_modules.*|
payments/templates/includes/.*
)$
- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.2.0
hooks:
- id: flake8
additional_dependencies: ['flake8-bugbear',]
args: ['--config', '.github/helper/flake8.conf']
- id: ruff
name: "Run ruff import sorter"
args: ["--select=I", "--fix"]

- id: ruff
name: "Run ruff linter"

- id: ruff-format
name: "Run ruff formatter"

ci:
autoupdate_schedule: weekly
Expand Down
46 changes: 23 additions & 23 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
module.exports = {
parserPreset: 'conventional-changelog-conventionalcommits',
rules: {
'subject-empty': [2, 'never'],
'type-case': [2, 'always', 'lower-case'],
'type-empty': [2, 'never'],
'type-enum': [
2,
'always',
[
'build',
'chore',
'ci',
'docs',
'feat',
'fix',
'perf',
'refactor',
'revert',
'style',
'test',
],
],
},
parserPreset: "conventional-changelog-conventionalcommits",
rules: {
"subject-empty": [2, "never"],
"type-case": [2, "always", "lower-case"],
"type-empty": [2, "never"],
"type-enum": [
2,
"always",
[
"build",
"chore",
"ci",
"docs",
"feat",
"fix",
"perf",
"refactor",
"revert",
"style",
"test",
],
],
},
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// Copyright (c) 2018, Frappe Technologies and contributors
// For license information, please see license.txt

frappe.ui.form.on('Braintree Settings', {

});
frappe.ui.form.on("Braintree Settings", {});
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@


class BraintreeSettings(Document):
supported_currencies = [
supported_currencies = (
"AED",
"AMD",
"AOA",
Expand Down Expand Up @@ -150,7 +150,7 @@ class BraintreeSettings(Document):
"ZAR",
"ZMK",
"ZWD",
]
)

def validate(self):
if not self.flags.ignore_mandatory:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Copyright (c) 2018, Frappe Technologies and contributors
// For license information, please see license.txt

frappe.ui.form.on('GoCardless Mandate', {
});
frappe.ui.form.on("GoCardless Mandate", {});
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def set_status(event):

def set_mandate_status(event):
mandates = []
if isinstance(event["links"], (list,)):
if isinstance(event["links"], list):
for link in event["links"]:
mandates.append(link["mandate"])
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
// refresh(frm) {

// },
// });
// });
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,15 @@


class GoCardlessSettings(Document):
supported_currencies = ["EUR", "DKK", "GBP", "SEK", "AUD", "NZD", "CAD", "USD"]
supported_currencies = ("EUR", "DKK", "GBP", "SEK", "AUD", "NZD", "CAD", "USD")

def validate(self):
self.initialize_client()

def initialize_client(self):
self.environment = self.get_environment()
try:
self.client = gocardless_pro.Client(
access_token=self.access_token, environment=self.environment
)
self.client = gocardless_pro.Client(access_token=self.access_token, environment=self.environment)
return self.client
except Exception as e:
frappe.throw(e)
Expand Down Expand Up @@ -64,7 +62,6 @@ def on_payment_request_submission(self, data):
return True

def check_mandate_validity(self, data):

if frappe.db.exists("GoCardless Mandate", dict(customer=data.get("payer_name"), disabled=0)):
registered_mandate = frappe.db.get_value(
"GoCardless Mandate", dict(customer=data.get("payer_name"), disabled=0), "mandate"
Expand Down Expand Up @@ -124,9 +121,7 @@ def create_charge_on_gocardless(self):
redirect_to = self.data.get("redirect_to") or None
redirect_message = self.data.get("redirect_message") or None

reference_doc = frappe.get_doc(
self.data.get("reference_doctype"), self.data.get("reference_docname")
)
reference_doc = frappe.get_doc(self.data.get("reference_doctype"), self.data.get("reference_docname"))
self.initialize_client()

try:
Expand Down Expand Up @@ -172,7 +167,7 @@ def create_charge_on_gocardless(self):
frappe.log_error("Gocardless payment failed")
self.integration_request.db_set("error", payment.status, update_modified=False)

except Exception as e:
except Exception:
frappe.log_error("GoCardless Payment Error")

if self.flags.status_changed_to == "Completed":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,8 @@ def stk_push(
errorMessage(str): This is a predefined code that indicates the reason for request failure.
"""

time = (
str(datetime.datetime.now()).split(".")[0].replace("-", "").replace(" ", "").replace(":", "")
)
password = f"{str(business_shortcode)}{str(passcode)}{time}"
time = str(datetime.datetime.now()).split(".")[0].replace("-", "").replace(" ", "").replace(":", "")
password = f"{business_shortcode!s}{passcode!s}{time}"
encoded = base64.b64encode(bytes(password, encoding="utf8"))
payload = {
"BusinessShortCode": business_shortcode,
Expand All @@ -135,9 +133,7 @@ def stk_push(
"CallBackURL": callback_url,
"AccountReference": reference_code,
"TransactionDesc": description,
"TransactionType": "CustomerPayBillOnline"
if self.env == "sandbox"
else "CustomerBuyGoodsOnline",
"TransactionType": "CustomerPayBillOnline" if self.env == "sandbox" else "CustomerBuyGoodsOnline",
}
headers = {
"Authorization": f"Bearer {self.authentication_token}",
Expand Down
Loading

0 comments on commit 8b57e6d

Please sign in to comment.