Skip to content

Commit

Permalink
Chore: update repo to current InvenHost defaults (#2)
Browse files Browse the repository at this point in the history
* update repo to current InvenHost defaults

* style fixes
  • Loading branch information
matmair authored Jan 4, 2024
1 parent 59765c9 commit 069eeea
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 56 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/ action.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
name: Plugin action
on:
push:
branches: ['main']
branches: ['main', 'master']
pull_request:
types: [opened, edited, reopened]
release:
types: [published]

jobs:
plugin-action:
uses: matmair/inventree-meta-plugin/.github/workflows/plugin_action.yaml@main
secrets: inherit
name: CI
uses: matmair/inventree-meta-plugin/.github/workflows/plugin_action.yaml@next
secrets:
PYPI_API_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
37 changes: 16 additions & 21 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
exclude: .*/(static|migrations|locale)/.*
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- id: mixed-line-ending
- repo: https://github.com/pycqa/flake8
rev: '5.0.4'
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- id: mixed-line-ending
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.11
hooks:
- id: flake8
additional_dependencies: [
'flake8-bugbear',
'flake8-docstrings',
'flake8-string-format',
'pep8-naming ',
]
- repo: https://github.com/pycqa/isort
rev: '5.10.1'
- id: ruff
args: [--fix]
- id: ruff-format
- repo: https://github.com/codespell-project/codespell
rev: v2.2.6
hooks:
- id: isort
- id: codespell
31 changes: 26 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ build-backend = "setuptools.build_meta"

[project]
name = "inventree-apprise"
version = "1.0"
description=" Send notifications from InvenTree via Apprise "
version = "1.1"
description=" Send notifications from InvenTree via Apprise"
readme = "README.md"
license = {text = "MIT"}
keywords = ["inventree", "inventree-plugin", "apprise"]
authors = [
{name = "Matthias J Mair", email = "info@mjmair.com"}
{name = "Matthias Mair", email = "code@mjmair.com"}
]
classifiers=[
"Programming Language :: Python :: 3",
Expand All @@ -30,11 +30,32 @@ dependencies = ['django', 'apprise']
dev = ['twine', 'setuptools']

[project.urls]
repository = "https://github.com/matmair/inventree-apprise"
"Bug Tracker" = "https://github.com/matmair/inventree-apprise/issues"
"Repository" = "https://github.com/invenhost/inventree-apprise"
"Bug Tracker" = "https://github.com/invenhost/inventree-apprise/issues"

[project.entry-points."inventree_plugins"]
inventree-apprise = "inventree_apprise:ApprisePlugin"

[tool.setuptools.packages.find]
where = ["src"]

[tool.ruff]
exclude=[".git","__pycache__","dist","build","test.py","tests", "venv","env",".venv",".env"]

[tool.ruff.lint]
select = ["A", "B", "C4", "D", "DJ", "N", "I","S"]
ignore = ["N999", ]

[tool.ruff.lint.pydocstyle]
convention = "google"

[tool.ruff.lint.isort]
combine-as-imports = true
section-order = ["future", "standard-library", "django", "third-party", "first-party", "local-folder" ]
known-first-party = ["src", "plugin", "InvenTree", "common"]

[tool.ruff.lint.isort.sections]
"django" = ["django"]

[tool.check-wheel-contents]
ignore = ['W004']
9 changes: 0 additions & 9 deletions setup.cfg

This file was deleted.

40 changes: 23 additions & 17 deletions src/inventree_apprise/ApprisePlugin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
"""Plugin to send notifications from InvenTree via Apprise."""

import apprise
from django.utils.translation import gettext_lazy as _

import apprise

from plugin import InvenTreePlugin, registry
from plugin.mixins import BulkNotificationMethod, SettingsMixin

Expand All @@ -20,28 +22,30 @@ def get_plugin(self):
class ApprisePlugin(SettingsMixin, InvenTreePlugin):
"""Send notifications from InvenTree via Apprise."""

NAME = 'ApprisePlugin'
SLUG = 'apprise'
NAME = "ApprisePlugin"
SLUG = "apprise"
TITLE = "Apprise Notifications"
SETTINGS = {
'ENABLE_NOTIFICATION_APPRISE': {
'name': _('Enable apprise notifications'),
'description': _('Allow sending of event notifications via apprise'),
'default': False,
'validator': bool,
"ENABLE_NOTIFICATION_APPRISE": {
"name": _("Enable apprise notifications"),
"description": _("Allow sending of event notifications via apprise"),
"default": False,
"validator": bool,
},
'NOTIFICATION_APPRISE_URL': {
'name': _('Apprise URLs'),
'description': _('URLs for notification enppoints, seperated by semicolons'),
'protected': True,
"NOTIFICATION_APPRISE_URL": {
"name": _("Apprise URLs"),
"description": _(
"URLs for notification enppoints, separated by semicolons"
),
"protected": True,
},
}

class SlackNotification(PlgMixin, BulkNotificationMethod):
"""Notificationmethod for delivery via Apprise."""

METHOD_NAME = 'apprise'
GLOBAL_SETTING = 'ENABLE_NOTIFICATION_APPRISE'
METHOD_NAME = "apprise"
GLOBAL_SETTING = "ENABLE_NOTIFICATION_APPRISE"

def get_targets(self):
"""Not used by this method."""
Expand All @@ -50,18 +54,20 @@ def get_targets(self):
def send_bulk(self):
"""Send the notifications out via slack."""
instance = registry.plugins.get(self.get_plugin().SLUG.lower())
url = instance.get_setting('NOTIFICATION_APPRISE_URL')
url = instance.get_setting("NOTIFICATION_APPRISE_URL")

if not url:
return False

apobj = apprise.Apprise()

# Add all of the notification services
for notifiy_url in url.split(';'):
for notifiy_url in url.split(";"):
apobj.add(notifiy_url)

# Send notification out
ret = apobj.notify(body=str(self.context['message']), title=str(self.context['name']))
ret = apobj.notify(
body=str(self.context["message"]), title=str(self.context["name"])
)

return bool(ret)
4 changes: 3 additions & 1 deletion src/inventree_apprise/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@

from .ApprisePlugin import ApprisePlugin

__all__ = [ApprisePlugin, ]
__all__ = [
ApprisePlugin,
]

0 comments on commit 069eeea

Please sign in to comment.