├── .github ├── FUNDING.yml └── workflows │ └── main.yml ├── .gitignore ├── CONTRIBUTING.md ├── Dockerfile ├── LICENSE ├── MANIFEST.in ├── Makefile ├── README.rst ├── entrypoint.sh ├── github_release_notifier ├── __init__.py ├── cli.py ├── notifier.py ├── parser.py └── webhook.py ├── logo.png ├── mycron.sh ├── setup.cfg └── setup.py /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: [jaymoulin] # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] 4 | patreon: # 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: jaymoulin # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | custom: ['https://www.paypal.me/jaymoulin', 'https://www.buymeacoffee.com/jaymoulin', 'https://www.tipeeestream.com/cursedware/donation', 'https://streamlabs.com/cursedware/tip'] 13 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | push: 5 | tags: 6 | - '*' 7 | 8 | jobs: 9 | build: 10 | 11 | runs-on: ubuntu-latest 12 | 13 | steps: 14 | - uses: actions/checkout@v2 15 | - name: Installing dependencies 16 | run: | 17 | sudo apt update && sudo apt install make -y 18 | echo "${{ secrets.DOCKER_HUB_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_HUB_LOGIN }}" --password-stdin 19 | - name: install buildx 20 | id: buildx 21 | uses: crazy-max/ghaction-docker-buildx@v1 22 | - name: Build image 23 | run: make build-docker 24 | - name: Publish image 25 | run: make publish-docker latest 26 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | *.egg-info 3 | dist 4 | __pycache__ 5 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | How to Contribute 2 | ================= 3 | 4 | This project welcomes your contribution. There are several ways to help out: 5 | 6 | * Create an [issue](https://github.com/femtopixel/github-release-notifier/issues/) on GitHub, 7 | if you have found a bug or have an idea for a feature 8 | * Write test cases for open bug issues 9 | * Write patches for open bug/feature issues 10 | 11 | Issues 12 | ------ 13 | 14 | * Submit an [issue](https://github.com/femtopixel/github-release-notifier/issues/) 15 | * Make sure it does not already exist. 16 | * Clearly describe the issue including steps to reproduce, when it is a bug. 17 | * Make sure you note the version you use. 18 | 19 | Additional Resources 20 | -------------------- 21 | 22 | * [Existing issues](https://github.com/femtopixel/github-release-notifier/issues/) 23 | * [General GitHub documentation](https://help.github.com/) 24 | * [GitHub pull request documentation](https://help.github.com/send-pull-requests/) 25 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM python:alpine 2 | 3 | ARG VERSION=0.4.1 4 | ARG TARGETPLATFORM 5 | LABEL maintainer="Jay MOULIN " 6 | LABEL version=${VERSION}-${TARGETPLATFORM} 7 | 8 | COPY . /app 9 | WORKDIR /app 10 | 11 | RUN pip install -e . && \ 12 | mkdir -p ${HOME}/.github_release_notifier && \ 13 | touch ${HOME}/.github_release_notifier/versions 14 | 15 | COPY ./entrypoint.sh /bin/entrypoint 16 | COPY ./mycron.sh /bin/mycron 17 | ENTRYPOINT ["/bin/entrypoint"] 18 | CMD ["/bin/mycron"] 19 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 FemtoPixel 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include *.md 2 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | VERSION ?= 0.4.5 2 | CACHE ?= --no-cache=1 3 | 4 | .PHONY: docker build-docker publish-docker 5 | test: install check 6 | twine upload -r testpypi dist/* 7 | publish: install check 8 | twine upload dist/* 9 | install: clean 10 | sudo python3 setup.py sdist 11 | check: 12 | twine check dist/* 13 | build: 14 | mkdir -p build 15 | dist: 16 | mkdir -p dist 17 | clean: build dist 18 | sudo rm -Rf build/* 19 | sudo rm -Rf dist/* 20 | 21 | docker: build-docker publish-docker 22 | build-docker: 23 | docker buildx build --platform linux/arm/v7,linux/arm64/v8,linux/amd64,linux/arm/v6,linux/386 ${PUSH} --build-arg VERSION=${VERSION} --tag femtopixel/github-release-notifier --tag femtopixel/github-release-notifier:${VERSION} ${CACHE} . 24 | publish-docker: 25 | PUSH=--push CACHE= make build-docker 26 | 27 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | .. image:: https://github.com/femtopixel/github-release-notifier/raw/master/logo.png 2 | 3 | ======================= 4 | Github Release Notifier 5 | ======================= 6 | 7 | .. image:: https://img.shields.io/github/release/femtopixel/github-release-notifier.svg 8 | :alt: latest release 9 | :target: http://github.com/femtopixel/github-release-notifier/releases 10 | .. image:: https://img.shields.io/pypi/v/github-release-notifier.svg 11 | :alt: latest release 12 | :target: https://pypi.org/project/github-release-notifier/ 13 | .. image:: https://img.shields.io/docker/pulls/femtopixel/github-release-notifier.svg 14 | :alt: Docker pull 15 | :target: https://hub.docker.com/r/femtopixel/github-release-notifier/ 16 | .. image:: https://img.shields.io/docker/stars/femtopixel/github-release-notifier.svg 17 | :alt: Docker stars 18 | :target: https://hub.docker.com/r/femtopixel/github-release-notifier/ 19 | .. image:: https://github.com/jaymoulin/jaymoulin.github.io/raw/master/ppl.png 20 | :alt: PayPal donation 21 | :target: https://www.paypal.me/jaymoulin 22 | .. image:: https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png 23 | :alt: Buy me a coffee 24 | :target: https://www.buymeacoffee.com/jaymoulin 25 | .. image:: https://ko-fi.com/img/githubbutton_sm.svg 26 | :alt: Buy me a coffee 27 | :target: https://ko-fi.com/jaymoulin 28 | 29 | DISCLAIMER: As-of 2021, this product does not have a free support team anymore. If you want this product to be maintained, please support. 30 | 31 | (This product is available under a free and permissive license, but needs financial support to sustain its continued improvements. In addition to maintenance and stability there are many desirable features yet to be added.) 32 | 33 | This program will allow you to be notified of Github new releases 34 | 35 | Installation 36 | ------------ 37 | 38 | .. code:: 39 | 40 | pip3 install github-release-notifier 41 | 42 | Usage 43 | ----- 44 | 45 | .. code:: 46 | 47 | usage: github-release-notifier [-h] [--action {cron,subscribe,unsubscribe}] [--package PACKAGE] 48 | [--webhook WEBHOOK] [--uuid UUID] 49 | 50 | optional arguments: 51 | -h, --help show this help message and exit 52 | --action {cron,subscribe,unsubscribe}, -a {cron,subscribe,unsubscribe} 53 | Action to do (default: cron) 54 | --package PACKAGE, -p PACKAGE 55 | Github package name / url (required for 56 | subscribe/unsubscribe) - prints uuid on subscription 57 | --webhook WEBHOOK, -w WEBHOOK 58 | URL to your webhook (required for 59 | subscribe/unsubscribe) 60 | --uuid UUID, -u UUID UUID of your webhook (required for unsubscribe) 61 | 62 | Example 63 | ~~~~~~~ 64 | 65 | First, I register my webhook : 66 | 67 | .. code:: 68 | 69 | github-release-notifier --action subscribe --webhook https://example.com/updated --package jaymoulin/google-music-manager 70 | 71 | an UUID is printed. this UUID will be required to unsubscribe the webhook. 72 | 73 | When `jaymoulin/google-music-manager` releases a new version, `https://example.com/updated` will be called with HTTP method `POST` and body, a JSON like this : 74 | 75 | .. code:: 76 | 77 | { 78 | "date": [2017, 11, 13, 19, 46, 35, 0, 317, 0], 79 | "version": "0.7.2", 80 | "title": "Fixes split modules", 81 | "content": "", 82 | "media": "https://avatars0.githubusercontent.com/u/14236493?s=60&v=4", 83 | "author": "jaymoulin" 84 | "package_name": "jaymoulin/google-music-manager" 85 | } 86 | 87 | For this to happen, the system should check if a new version have been released. 88 | We can do that by calling `github-release-notifier` without any parameter or setting `--action` to `cron` (which is default). 89 | 90 | To automate this process, we could add this process in a cronjob: 91 | 92 | .. code:: 93 | 94 | (crontab -l ; echo "0 0 * * * github-release-notifier") | sort - | uniq - | crontab - 95 | 96 | This will check every day at midnight if new versions have been released. 97 | 98 | Configuration 99 | ------------- 100 | 101 | Environment variables can be defined to change default `hooks` or `versions` database files (plain json file) 102 | 103 | .. code:: 104 | 105 | GRN_VERSIONS_FILE: Path to saved versions (default: ${HOME}/.github_release_notifier/versions) 106 | GRN_HOOKS_FILE: Path to hooks configuration (default: ${HOME}/.github_release_notifier/hooks) 107 | 108 | Docker Usage 109 | ------------ 110 | 111 | First run the daemon 112 | 113 | .. code:: 114 | 115 | docker run --name GRN -d femtopixel/github-release-notifier 116 | 117 | you can mount a volume to `/root/.github_release_notifier/` to keep tracks of webhooks and versions 118 | 119 | example: 120 | 121 | .. code:: 122 | 123 | docker run --name GRN -d -v /path/to/your/saves:/root/.github_release_notifier/ femtopixel/github-release-notifier 124 | 125 | Then register your webhook : 126 | 127 | .. code:: 128 | 129 | docker exec GRN -a subscribe -p jaymoulin/google-music-manager -w https://example.com/updated 130 | 131 | 132 | Submitting bugs and feature requests 133 | ------------------------------------ 134 | 135 | Bugs and feature request are tracked on GitHub 136 | 137 | Author 138 | ------ 139 | 140 | Jay MOULIN jaymoulin+github-release-notifier@gmail.com See also the list of contributors which participated in this program. 141 | 142 | License 143 | ------- 144 | 145 | Github Release Notifier is licensed under the MIT License 146 | -------------------------------------------------------------------------------- /entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | if [ "${1#-}" != "$1" ]; then 5 | set -- github-release-notifier "$@" 6 | fi 7 | 8 | exec "$@" 9 | -------------------------------------------------------------------------------- /github_release_notifier/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | This program will allow you to be notified of Github new releases 3 | """ 4 | 5 | __all__ = ['parser', 'webhook', 'notifier'] 6 | __version__ = '0.4.5' 7 | -------------------------------------------------------------------------------- /github_release_notifier/cli.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding: utf-8 3 | 4 | import argparse 5 | from github_release_notifier import notifier, webhook 6 | 7 | 8 | def main(): 9 | parser = argparse.ArgumentParser() 10 | parser.add_argument( 11 | "--action", 12 | '-a', 13 | default='cron', 14 | choices=['cron', 'subscribe', 'unsubscribe'], 15 | help="Action to do (default: cron)" 16 | ) 17 | parser.add_argument( 18 | "--package", 19 | '-p', 20 | help="Github package name / url (required for subscribe/unsubscribe) - prints uuid on subscription" 21 | ) 22 | parser.add_argument( 23 | "--webhook", 24 | '-w', 25 | help="URL to your webhook (required for subscribe/unsubscribe)" 26 | ) 27 | parser.add_argument( 28 | "--uuid", 29 | '-u', 30 | help="UUID of your webhook (required for unsubscribe)" 31 | ) 32 | args = parser.parse_args() 33 | if args.action == 'cron': 34 | print(notifier.run()) 35 | if args.action == 'subscribe': 36 | print(webhook.subscribe(args.package, args.webhook)) 37 | if args.action == 'unsubscribe': 38 | webhook.unsubscribe(args.uuid, args.package, args.webhook) 39 | 40 | 41 | if __name__ == "__main__": 42 | main() 43 | -------------------------------------------------------------------------------- /github_release_notifier/notifier.py: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | 3 | import sys 4 | import json 5 | import os 6 | import requests 7 | import logging 8 | import threading 9 | import re 10 | from .webhook import get, get_list 11 | from .parser import parse 12 | from pathlib import Path 13 | from distutils.version import LooseVersion 14 | 15 | __DEFAULT_FILE__ = os.getenv('GRN_VERSIONS_FILE', str(Path.home()) + '/.github_release_notifier/versions') 16 | 17 | 18 | def version_compare(version1: str, version2: str) -> int: 19 | def normalize(v): 20 | return [int(x) for x in re.sub(r'([^.0-9]+)', '', v).split(".")] 21 | 22 | return (normalize(version1) > normalize(version2)) - (normalize(version1) < normalize(version2)) 23 | 24 | 25 | def _call_webhook(webhook: str, entry: str, logger: logging.Logger) -> None: 26 | logger.info("Hook call : %s / %s" % (webhook, json.dumps(entry))) 27 | try: 28 | requests.post(webhook, json=entry) 29 | except requests.exceptions.RequestException: 30 | logger.error("Error occurred : %s" % (sys.exc_info()[0])) 31 | 32 | 33 | def run(file: str = __DEFAULT_FILE__) -> dict: 34 | logging.basicConfig(level=logging.INFO) 35 | logger = logging.getLogger(__name__) 36 | updated = {} 37 | for package in get_list(): 38 | try: 39 | for entry in parse(package): 40 | try: 41 | condition = version_compare(str(entry['version']), str(get_version(package))) > 0 42 | except TypeError: 43 | try: 44 | condition = LooseVersion(str(entry['version'])) > LooseVersion(str(get_version(package))) 45 | except (AttributeError, TypeError): 46 | condition = False 47 | if condition: 48 | database = _get_database(file) 49 | database[package] = entry['version'] 50 | _set_database(database, file) 51 | updated[package] = entry['version'] 52 | for webhook in get(package): 53 | threading.Thread(target=_call_webhook, args=(webhook, entry, logger,)).start() 54 | except NameError as e: 55 | logger.error("Package removed : %s" % package) 56 | database = _get_database(file) 57 | del database[package] 58 | _set_database(database, file) 59 | return updated 60 | 61 | 62 | def _get_database(file: str = __DEFAULT_FILE__) -> dict: 63 | if not Path(file).is_file(): 64 | raise ValueError('Unexpected database file provided') 65 | return json.loads(open(file, "r").read()) 66 | 67 | 68 | def _set_database(database: dict, filepath: str = __DEFAULT_FILE__) -> None: 69 | dirname = os.path.dirname(filepath) 70 | if not os.path.exists(dirname): 71 | os.makedirs(dirname) 72 | file = open(filepath, "w+") 73 | file.write(json.dumps(database)) 74 | file.close() 75 | 76 | 77 | def get_version(package: str, file: str = __DEFAULT_FILE__) -> str: 78 | database = _get_database(file) 79 | return database.get(package, '0.0.0') 80 | -------------------------------------------------------------------------------- /github_release_notifier/parser.py: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | 3 | import feedparser 4 | import re 5 | import requests 6 | from typing import List 7 | 8 | 9 | def parse(package: str) -> List[dict]: 10 | package_name = get_package(package) 11 | url = 'https://github.com/%s/releases.atom' % package_name 12 | feed = feedparser.parse(url) 13 | entries = [] 14 | for item in feed['entries']: 15 | current_dict = { 16 | 'author': None, 17 | "content": None, 18 | "media": None, 19 | "date": item['updated_parsed'], 20 | "title": item['title_detail']['value'], 21 | "version": re.search('(?<=Repository/)[0-9]+/(.+)', item['id']).group(1), 22 | "package_name": package_name, 23 | } 24 | if 'authors' in item and item['authors'][0] is not None and 'name' in item['authors'][0]: 25 | current_dict['author'] = item['authors'][0]['name'] 26 | if 'content' in item and item['content'][0] is not None and 'value' in item['content'][0]: 27 | current_dict['content'] = item['content'][0]['value'] 28 | if ( 29 | 'media_thumbnail' in item and 30 | item['media_thumbnail'][0] is not None 31 | and 'url' in item['media_thumbnail'][0] 32 | ): 33 | current_dict['media'] = item['media_thumbnail'][0]['url'] 34 | entries.append(current_dict) 35 | return entries 36 | 37 | 38 | def get_package(entry: str) -> str: 39 | if 'github' in entry: 40 | entry = re.search('(?<=github.com/)[^/]+/[^/]+', entry).group(0) 41 | request = requests.get('https://github.com/%s/tags.atom' % entry) 42 | if request.status_code != 200: 43 | raise NameError('%s is not a valid github url/package' % entry) 44 | return entry 45 | -------------------------------------------------------------------------------- /github_release_notifier/webhook.py: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | 3 | import json 4 | import os 5 | from .parser import get_package 6 | from pathlib import Path 7 | from hashlib import sha224 8 | from typing import KeysView 9 | 10 | __SALT__ = 'saltedUnique' 11 | __DEFAULT_FILE__ = os.getenv('GRN_HOOKS_FILE', str(Path.home()) + '/.github_release_notifier/hooks') 12 | 13 | 14 | def _get_database(file: str = __DEFAULT_FILE__) -> dict: 15 | database = {} 16 | if Path(file).is_file(): 17 | database = json.loads(open(file, "r").read()) 18 | return database 19 | 20 | 21 | def _set_database(database: dict, filepath: str = __DEFAULT_FILE__) -> None: 22 | dirname = os.path.dirname(filepath) 23 | if not os.path.exists(dirname): 24 | os.makedirs(dirname) 25 | file = open(filepath, "w+") 26 | file.write(json.dumps(database)) 27 | file.close() 28 | 29 | 30 | def subscribe(package: str, callback: str, file: str = __DEFAULT_FILE__, salt: str = __SALT__) -> str: 31 | package = get_package(package) 32 | database = _get_database(file) 33 | try: 34 | database[package] = list(filter(callback.__ne__, database[package])) 35 | except KeyError: 36 | database[package] = [] 37 | database[package].append(callback) 38 | _set_database(database, file) 39 | return get_uuid(package, callback, salt) 40 | 41 | 42 | def get_uuid(package: str, callback: str, salt: str = __SALT__) -> str: 43 | package = get_package(package) 44 | return sha224(callback.encode('utf-8') + package.encode('utf-8') + salt.encode('utf-8')).hexdigest() 45 | 46 | 47 | def unsubscribe(uuid: str, package: str, callback, file: str = __DEFAULT_FILE__, salt: str = __SALT__) -> None: 48 | package = get_package(package) 49 | database = _get_database(file) 50 | if uuid == get_uuid(package, callback, salt): 51 | database[package] = list(filter(callback.__ne__, database[package])) 52 | else: 53 | raise NameError('Wrong uuid for your package') 54 | _set_database(database, file) 55 | 56 | 57 | def get(package: str, file: str = __DEFAULT_FILE__) -> dict: 58 | package = get_package(package) 59 | database = _get_database(file) 60 | return database.get(package, {}) 61 | 62 | 63 | def get_list(file: str = __DEFAULT_FILE__) -> KeysView: 64 | database = _get_database(file) 65 | return database.keys() 66 | -------------------------------------------------------------------------------- /logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/femtopixel/github-release-notifier/8f753e36fb739c992b7afb40919d05917bb9151a/logo.png -------------------------------------------------------------------------------- /mycron.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | # start-cron.sh 4 | 5 | while [ true ]; do 6 | github-release-notifier 7 | sleep 24h 8 | done 9 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [metadata] 2 | name = github_release_notifier 3 | version = attr: github_release_notifier.__version__ 4 | description = Get notified when a specific package got a new release on Github 5 | long_description = file: README.rst 6 | author = Jay MOULIN 7 | url = https://github.com/femtopixel/github-release-notifier/ 8 | license = MIT 9 | classifiers = 10 | Development Status :: 5 - Production/Stable 11 | Programming Language :: Python 12 | License :: OSI Approved :: MIT License 13 | Natural Language :: English 14 | Operating System :: OS Independent 15 | Programming Language :: Python :: 3 16 | Topic :: Communications 17 | Topic :: Internet 18 | Topic :: Software Development :: Pre-processors 19 | Intended Audience :: Developers 20 | Topic :: Software Development :: Build Tools 21 | 22 | [options] 23 | include_package_data = True 24 | packages = find: 25 | install_requires = 26 | feedparser 27 | requests 28 | python_requires = >=3 29 | 30 | [options.entry_points] 31 | console_scripts = 32 | github-release-notifier = github_release_notifier.cli:main 33 | grn = github_release_notifier.cli:main 34 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | 3 | from setuptools import setup 4 | 5 | setup() 6 | --------------------------------------------------------------------------------