diff --git a/.gitignore b/.gitignore index 72364f9..0c82fb9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,50 @@ +# Created by .ignore support plugin (hsz.mobi) +### JetBrains template +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff: +.idea/workspace.xml +.idea/tasks.xml +.idea/dictionaries +.idea/vcs.xml +.idea/jsLibraryMappings.xml + +# Sensitive or high-churn files: +.idea/dataSources.ids +.idea/dataSources.xml +.idea/dataSources.local.xml +.idea/sqlDataSources.xml +.idea/dynamic.xml +.idea/uiDesigner.xml + +# Gradle: +.idea/gradle.xml +.idea/libraries + +# Mongo Explorer plugin: +.idea/mongoSettings.xml + +## File-based project format: +*.iws + +## Plugin-specific files: + +# IntelliJ +/out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties +### Python template # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] @@ -87,3 +134,18 @@ ENV/ # Rope project settings .ropeproject +### VirtualEnv template +# Virtualenv +# http://iamzed.com/2009/05/07/a-primer-on-virtualenv/ +.Python +[Bb]in +[Ii]nclude +[Ll]ib +[Ll]ib64 +[Ll]ocal +[Ss]cripts +pyvenv.cfg +.venv +pip-selfcheck.json + +.idea \ No newline at end of file diff --git a/server.py b/server.py new file mode 100644 index 0000000..3297d17 --- /dev/null +++ b/server.py @@ -0,0 +1,34 @@ +import os +from sys import platform as _platform + +from flask import Flask, abort, request +from flask import request +app = Flask(__name__) + + +# 104.192.143.192/28 +# 104.192.143.208/28 +trusted_remote_addrs = list(map( + lambda last: '104.192.143.' + str(last), + list(range(192, 192 + 16)) + list(range(208, 208 + 16)) +)) + ['127.0.0.1'] + + +@app.before_request +def limit_remote_addr(): + if request.remote_addr not in trusted_remote_addrs: + abort(403) + + +@app.route('/webhook', methods=['GET', 'POST']) +def tracking(): + if request.method == 'POST': + data = request.get_json() + commit_author = data['actor']['username'] + commit_hash = data['push']['changes'][0]['new']['target']['hash'][:7] + commit_url = data['push']['changes'][0]['new']['target']['links']['html']['href'] + print('Webhook received! %s committed %s' % (commit_author, commit_hash)) + return 'OK' + +if __name__ == '__main__': + app.run(host='0.0.0.0', port=5000, debug=True) \ No newline at end of file