-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 9a324c4
Showing
19 changed files
with
1,389 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
name-template: '$NEXT_MINOR_VERSION' | ||
tag-template: 'v$NEXT_MINOR_VERSION' | ||
filter-by-commitish: true | ||
commitish: master | ||
autolabeler: | ||
- label: 'maintenance' | ||
files: | ||
- '*.md' | ||
- '.github/*' | ||
- label: 'bug' | ||
branch: | ||
- '/bug-.+' | ||
- label: 'maintenance' | ||
branch: | ||
- '/maintenance-.+' | ||
- label: 'feature' | ||
branch: | ||
- '/feature-.+' | ||
categories: | ||
- title: '🔥 Breaking Changes' | ||
labels: | ||
- 'breakingchange' | ||
- title: '🚀 New Features' | ||
labels: | ||
- 'feature' | ||
- 'enhancement' | ||
- title: '🐛 Bug Fixes' | ||
labels: | ||
- 'fix' | ||
- 'bugfix' | ||
- 'bug' | ||
- 'BUG' | ||
- title: '🧰 Maintenance' | ||
labels: | ||
- 'maintenance' | ||
- 'dependencies' | ||
- 'documentation' | ||
- 'docs' | ||
- 'testing' | ||
change-template: '- $TITLE (#$NUMBER)' | ||
exclude-labels: | ||
- 'skip-changelog' | ||
template: | | ||
# Changes | ||
$CHANGES | ||
## Contributors | ||
We'd like to thank all the contributors who worked on this release! | ||
$CONTRIBUTORS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
matrix: | ||
- name: Markdown | ||
expect_match: false | ||
apsell: | ||
lang: en | ||
d: en_US | ||
ignore-case: true | ||
dictionary: | ||
wordlists: | ||
- .github/wordlist.txt | ||
output: wordlist.dic | ||
pipeline: | ||
- pyspelling.filters.markdown: | ||
markdown_extensions: | ||
- markdown.extensions.extra: | ||
- pyspelling.filters.html: | ||
comments: false | ||
attributes: | ||
- alt | ||
ignores: | ||
- ':matches(code, pre)' | ||
- code | ||
- pre | ||
- blockquote | ||
- img | ||
sources: | ||
- '*.md' | ||
- 'docs/*.rst' | ||
- 'docs/*.ipynb' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Alertist | ||
awaited |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# For most projects, this workflow file will not need changing; you simply need | ||
# to commit it to your repository. | ||
# | ||
# You may wish to alter this file to override the set of languages analyzed, | ||
# or to provide custom queries or build logic. | ||
# | ||
# ******** NOTE ******** | ||
# We have attempted to detect the languages in your repository. Please check | ||
# the `language` matrix defined below to confirm you have the correct set of | ||
# supported CodeQL languages. | ||
# | ||
name: "CodeQL" | ||
|
||
on: | ||
push: | ||
branches: [ master ] | ||
pull_request: | ||
# The branches below must be a subset of the branches above | ||
branches: [ master ] | ||
|
||
jobs: | ||
analyze: | ||
name: Analyze | ||
runs-on: ubuntu-latest | ||
permissions: | ||
actions: read | ||
contents: read | ||
security-events: write | ||
|
||
strategy: | ||
fail-fast: false | ||
matrix: | ||
language: [ 'python' ] | ||
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] | ||
# Learn more about CodeQL language support at https://git.io/codeql-language-support | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
# Initializes the CodeQL tools for scanning. | ||
- name: Initialize CodeQL | ||
uses: github/codeql-action/init@v3 | ||
with: | ||
languages: ${{ matrix.language }} | ||
# If you wish to specify custom queries, you can do so here or in a config file. | ||
# By default, queries listed here will override any specified in a config file. | ||
# Prefix the list here with "+" to use these queries and those in the config file. | ||
# queries: ./path/to/local/query, your-org/your-repo/queries@main | ||
|
||
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java). | ||
# If this step fails, then you should remove it and run the build manually (see below) | ||
- name: Autobuild | ||
uses: github/codeql-action/autobuild@v3 | ||
|
||
# ℹ️ Command-line programs to run using the OS shell. | ||
# 📚 https://git.io/JvXDl | ||
|
||
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines | ||
# and modify them (or add more) to build your code if your project | ||
# uses a compiled language | ||
|
||
#- run: | | ||
# make bootstrap | ||
# make release | ||
|
||
- name: Perform CodeQL Analysis | ||
uses: github/codeql-action/analyze@v3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
--- | ||
|
||
name: Integration | ||
|
||
on: | ||
pull_request: | ||
push: | ||
paths-ignore: | ||
- *.md' | ||
- 'docs/**' | ||
branches: | ||
- main | ||
- master | ||
- '[0-9].[0-9]' | ||
|
||
jobs: | ||
integration: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: install python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: 3.12 | ||
|
||
- name: install poetry and dependencies | ||
run: | | ||
pip install poetry | ||
poetry install | ||
poetry build | ||
- name: run tests | ||
run: | | ||
poetry run pytest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
name: Publish tag to Pypi | ||
|
||
on: | ||
release: | ||
types: [published] | ||
|
||
permissions: | ||
contents: read # to fetch code (actions/checkout) | ||
|
||
jobs: | ||
|
||
build_and_package: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: install python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: 3.12 | ||
|
||
- name: Build the package | ||
run: | | ||
poetry build | ||
- name: Basic package test prior to upload | ||
run: | | ||
twine check dist/* | ||
- name: Publish to Pypi | ||
uses: pypa/gh-action-pypi-publish@release/v1 | ||
with: | ||
user: __token__ | ||
password: ${{ secrets.PYPI_API_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
name: Release Drafter | ||
|
||
on: | ||
push: | ||
# branches to consider in the event; optional, defaults to all | ||
branches: | ||
- master | ||
|
||
permissions: {} | ||
jobs: | ||
update_release_draft: | ||
permissions: | ||
pull-requests: write # to add label to PR (release-drafter/release-drafter) | ||
contents: write # to create a github release (release-drafter/release-drafter) | ||
|
||
runs-on: ubuntu-latest | ||
steps: | ||
# Drafts your next Release notes as Pull Requests are merged into "master" | ||
- uses: release-drafter/release-drafter@v6 | ||
with: | ||
# (Optional) specify config name to use, relative to .github/. Default: release-drafter.yml | ||
config-name: release-drafter-config.yml | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
name: spellcheck | ||
on: | ||
pull_request: | ||
jobs: | ||
check-spelling: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
- name: Check Spelling | ||
uses: rojopolis/[email protected] | ||
with: | ||
config_path: .github/spellcheck-settings.yml | ||
task_name: Markdown |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.venv | ||
__pycache__/* | ||
dist/* | ||
__pycache__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Copyright 2024 Chayim Kirshen | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# alertist | ||
|
||
Alertist is a library that makes it as easy as possible to send a message to a target, without rewriting code. All configuration happens via environment variables. | ||
|
||
----- | ||
|
||
## Motivation | ||
|
||
Sending alerts just needs to be easy. Code shouldn't need rewriting so that you can change the destination for a message, a deployment shouldn't have to happen, and CI changed just to send an email, when an SNS message will do. Enter alertist. | ||
|
||
Alertist makes is simple to send alerts. Configure environment variables, and run your python application. But maybe that doesn't work for you - alertist loads a .env by default, from your current working directory, making it as painless as possible to trigger alert sending, without application overhead. | ||
|
||
## Installation | ||
|
||
`pip install alertist` | ||
|
||
## Usage | ||
|
||
Create an alertist object, and call the `alert` method with the target and message. The alertist object, must be instantiated with the target, or alert type you'd like to send. | ||
|
||
```python | ||
|
||
from alertist import Alertist | ||
from alertist.targets import Pushover | ||
|
||
a = Alertist(Pushover) | ||
a.alert("Hello, world!") | ||
``` | ||
|
||
If you'd like to send a message asynchronously, you use the exact same code, except that the `alert` method is now called `aalert`, and must be awaited. | ||
|
||
```python | ||
from alertist import Alertist | ||
from alertist.targets import Pushover | ||
|
||
a = Alertist(Pushover) | ||
await a.alert("Hello, world!") | ||
``` | ||
|
||
Supported alert types can be found in the [targets folder](alertist/targets). | ||
|
||
----- | ||
|
||
## Contributing | ||
|
||
### Writing a new alert target | ||
|
||
Bug, features, or integrations? Feel free to contribute in whatever way you can! But below, let's highlight how to create a new alert target. | ||
|
||
1. Create a new class subclassing `ABCTarget` | ||
1. Implement the synchronous `alert` method, and asynchronous `aalert` method | ||
1. Add all environment variables that can be configured to `CONFIG_KEYS` in your class. | ||
1. Add your class to `targets.__all__` in `__init__.py` | ||
1. Write two unit tests, probably mocking your connecting. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from .conf import Config | ||
from typing import Optional, List | ||
from .targets.abstract import ABCTarget | ||
import os | ||
|
||
|
||
class Alertist: | ||
ALERTS = [] | ||
|
||
def __init__( | ||
self, | ||
alert: Optional[ABCTarget] = None, | ||
# alerts: Optional[List[ABCTarget]] = None, | ||
) -> None: | ||
Config() | ||
if alert is not None: | ||
self.ALERTS = [alert] | ||
# TODO support for multiple | ||
# elif alerts is not None: | ||
# self.ALERTS = alerts | ||
# else: | ||
# pass | ||
# TODO dynamic alerts here, this is a placeholder | ||
# keys = os.getenv("ALERTS", "").split(",") | ||
# self.ALERTS = keys | ||
|
||
if len(self.ALERTS) == 0: | ||
raise ValueError("Configure an alert target") | ||
|
||
def alert(self, message: str, **kwargs): | ||
for a in self.ALERTS: | ||
a().alert(message, **kwargs) | ||
|
||
async def aalert(self, message: str, **kwargs): | ||
for a in self.ALERTS: | ||
await a().aalert(message, **kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from dotenv import load_dotenv | ||
import os | ||
|
||
|
||
class Singleton(type): | ||
_instances = {} | ||
|
||
def __call__(cls, *args, **kwargs): | ||
if cls not in cls._instances: | ||
instance = super().__call__(*args, **kwargs) | ||
cls._instances[cls] = instance | ||
return cls._instances[cls] | ||
|
||
|
||
class Config(metaclass=Singleton): | ||
# _KEYS = [ | ||
# "PUSHOVER_USER", | ||
# "PUSHOVER_API_TOKEN", | ||
# ] | ||
|
||
def __init__(self): | ||
import alertist.targets | ||
|
||
load_dotenv() | ||
for t in alertist.targets.__all__: | ||
klass = getattr(alertist.targets, t) | ||
for k in klass.CONFIG_KEYS: | ||
setattr(self, k, os.environ.get(k)) |
Oops, something went wrong.