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

Feature: add webhook notification capability #724

Draft
wants to merge 21 commits into
base: master
Choose a base branch
from

Conversation

Guts
Copy link
Contributor

@Guts Guts commented May 1, 2021

I propose here to add the possibility to send a notification to a web hook for each new comment.

Notable changes

  • creation of a new WebHook class in the notifications module
  • by default, it sends a POST request with the same metadata as the mail notification (name, mail and site of the author as well as the moderation links)
  • add requests as dependency
  • possibility for the end user to pass a JSON template to the webhook (useful for tools allowing formatting, like Slack/Teams/Matrix...). An example of template for Slack is provided (into contrib subfolder) with this render:

image

Questions

  • Maybe it is possible with Werkzeug, Flask or the stdlib directly for the POST request? I'm not expert on this side so, don't hesitate on review my code.
  • I wanted to use f-strings but apparently the project is still tested on Python 3.5 (which has reached EOL), but not 3.9. Is it a voluntary choice?
  • I had to fix dependencies consistency between setup.py and tox.ini, in order to get CI fixed. Requirements are not well documented and the development workflow is quite unclear. Would you accept a PR to switch to requirements.txt files and/or pyproject.tom (recomended by tox anyway)?

Misc

@Guts
Copy link
Contributor Author

Guts commented Jun 17, 2021

ping @posativ @ix5 @blatinier : any chance to see it merged or reviewed?

@ix5
Copy link
Member

ix5 commented Jun 17, 2021

Can't say much, but here are my thoughts:

@Guts
Copy link
Contributor Author

Guts commented Jun 17, 2021

Thanks for your feedback.

f-strings are pretty dangerous, see Armin Ronacher: Be Careful with Python's New-Style String Format

I did not know that but it's quite old (not sure it's still applicable) and it's a concern only when we format some secret no? If you prefer, we can switch to f"{var}" or "%s" % var.

Avoid adding new dependencies. POST requests can be done with urllib

Sure but it would be quite harder to handle different cases (HTTP warnings, redirections, etc...).

Squash your commits

I will.

Guts added 3 commits June 19, 2021 13:30
Exclude .venv from flake8
Add webhook

Fix string formatting

Fix string formatting

Make it compatible with Python 3.5 ?!

Add default webhook section

Clean up and docstrings

Handle HTTP errors

Add webhook template for Slack

Add requests as dependency

Remove unused var

Complete post data without template

Enable cache
@jelmer
Copy link
Member

jelmer commented Jun 21, 2021

It would be great if this had some unit tests.

@Guts
Copy link
Contributor Author

Guts commented Jun 22, 2021

Sure!

I did not write them because I can't find which tests framework is recommended.

Can you tell me which one please? (pypi package name)

@jelmer
Copy link
Member

jelmer commented Jun 22, 2021

We're using nosetests; you can invoke them with nose or by running "make test"

@Guts
Copy link
Contributor Author

Guts commented Jun 22, 2021

We're using nosetests; you can invoke them with nose or by running "make test"

Ok. What I need is the PyPi package to install it as testing dependency in a virtual env (I don't want to install something widely on my system). I can't find noestests on pypi.org but I've found 2 nose* packages: this one https://pypi.org/project/nose/ or this one https://pypi.org/project/nose2/?

@jelmer
Copy link
Member

jelmer commented Jun 22, 2021

I think the pypi name is just "nose", but you should also be able to just use python's standard unittest framework to run the tests - we don't use anything nose-specific.

@Guts
Copy link
Contributor Author

Guts commented Jun 22, 2021

I think the pypi name is just "nose", but you should also be able to just use python's standard unittest framework to run the tests - we don't use anything nose-specific.

Good news because running make test returns an error (Ubuntu 20.04, after make init with node 14):

:~/Git/External/isso$ make test
python3 setup.py nosetests
usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
   or: setup.py --help [cmd1 cmd2 ...]
   or: setup.py --help-commands
   or: setup.py cmd --help

error: invalid command 'nosetests'
make: *** [Makefile:71 : test] Erreur 1

Thanks for your help. I'll try to write some unit tests with the standard lib.

@vincentbernat
Copy link
Contributor

nose is only a runner. You can also run them with python3 -m unittest discover isso/tests or by using pytest which also includes a runner.

@Guts Guts marked this pull request as draft June 23, 2021 05:35
@mcnaveen
Copy link

mcnaveen commented Oct 9, 2021

I & @mskian ended up creating this - https://github.com/mskian/isso-telegram-notifier

@Guts
Copy link
Contributor Author

Guts commented Oct 9, 2021

I & @mskian ended up creating this - https://github.com/mskian/isso-telegram-notifier

Nice work! Why not develop it right into Isso?

@jelmer
Copy link
Member

jelmer commented Oct 9, 2021

I & @mskian ended up creating this - https://github.com/mskian/isso-telegram-notifier

Nice work! Why not develop it right into Isso?

If this was added to mainline isso, it would be hard to make sure that it kept working - the maintainers can't test with lots of different configurations.

@ix5
Copy link
Member

ix5 commented Dec 21, 2021

Nice work! I have not verified the functionality myself, but the code looks neat.

Please add (unit) tests as requested by @jelmer

isso/ext/notifications.py Show resolved Hide resolved
isso/ext/notifications.py Show resolved Hide resolved
share/isso.conf Show resolved Hide resolved
share/isso.conf Show resolved Hide resolved
# webhook URL
url =

# path to the JSON template. Optional.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can users supply an absolute or relative path here? Please state so clearly.

isso/ext/notifications.py Show resolved Hide resolved
isso/ext/notifications.py Show resolved Hide resolved
isso/ext/notifications.py Show resolved Hide resolved
isso/ext/notifications.py Show resolved Hide resolved
isso/ext/notifications.py Show resolved Hide resolved
@ix5 ix5 self-assigned this Dec 27, 2021
@ix5 ix5 added feature server (Python) server code labels Dec 31, 2021
def setUp(self):
self.path = tempfile.NamedTemporaryFile().name

def makeClient(self, ip):

conf = config.load(pkg_resources.resource_filename('isso', 'defaults.ini'))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't include these unrelated formatting changes - they make the PR harder to review.

@ix5
Copy link
Member

ix5 commented Feb 10, 2022

@Guts this is a great feature, would you mind rebasing and addressing the points raised by jelmer and myself?

@ix5 ix5 mentioned this pull request Feb 10, 2022
@ix5 ix5 added this to the 0.13 milestone Feb 13, 2022
@ix5 ix5 modified the milestones: 0.13, 0.14 May 24, 2022
@abhin4v
Copy link

abhin4v commented Feb 25, 2023

It'll be great to have this feature. It'll enable me to trigger a build of my static website in which I render the Isso comments at build time.

@ix5 ix5 modified the milestones: 0.14, 0.13.1 May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature server (Python) server code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants