diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml new file mode 100644 index 0000000..6307598 --- /dev/null +++ b/.github/workflows/linter.yml @@ -0,0 +1,56 @@ +################################# +################################# +## Super Linter GitHub Actions ## +################################# +################################# +name: Lint Code Base + +# +# Documentation: +# https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions +# + +############################# +# Start the job on all push # +############################# +on: + push: + branches-ignore: [master, main] + # Remove the line above to run when pushing to master + pull_request: + branches: [master, main] + +############### +# Set the Job # +############### +jobs: + build: + # Name the Job + name: Lint Code Base + # Set the agent to run on + runs-on: ubuntu-latest + + ################## + # Load all steps # + ################## + steps: + ########################## + # Checkout the code base # + ########################## + - name: Checkout Code + uses: actions/checkout@v3 + with: + # Full git history is needed to get a proper list of changed files within `super-linter` + fetch-depth: 0 + + ################################ + # Run Linter against code base # + ################################ + - name: Lint Code Base + uses: github/super-linter/slim@v4 + env: + VALIDATE_ALL_CODEBASE: true + DEFAULT_BRANCH: main + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # VALIDATE_GITHUB_ACTIONS: true + VALIDATE_PYTHON_BLACK: true diff --git a/python/app.py b/python/app.py index 3d518e1..b52bbbc 100755 --- a/python/app.py +++ b/python/app.py @@ -17,7 +17,7 @@ app = Flask(__name__) # Make instance of redis queue -q = Queue(connection=Redis(host='redis_cache', port=6379)) +q = Queue(connection=Redis(host="redis_cache", port=6379)) # Write the username and repo to the test table @@ -25,26 +25,31 @@ def write_to_db(username, repo): """ Writes the username, repo, and time to the test table """ - conn = psycopg2.connect("host=database dbname=webhooks user=postgres password=mysecretpassword") + conn = psycopg2.connect( + "host=database dbname=webhooks user=postgres password=mysecretpassword" + ) cur = conn.cursor() try: - cur.execute(""" + cur.execute( + """ INSERT INTO test_webhook (username, target_repo, event_timestamp) VALUES (%s, %s, %s); - """, (username, repo, datetime.now())) + """, + (username, repo, datetime.now()), + ) except psycopg2.Error as e: - print('Error: %s', e) + print("Error: %s", e) conn.commit() cur.close() conn.close() # Do the things -@app.route('/webhook', methods=['POST']) +@app.route("/webhook", methods=["POST"]) def respond(): username = request.json["repository"]["owner"]["login"] repo = request.json["repository"]["name"] write_to_db(username, repo) return Response(status=201) # TODO: add some business logic to do something else with the data, maybe - # put it into redis to queue up something bigger? \ No newline at end of file + # put it into redis to queue up something bigger? diff --git a/systemd/app.py b/systemd/app.py index a1ddf03..7525e75 100755 --- a/systemd/app.py +++ b/systemd/app.py @@ -28,16 +28,15 @@ def run_container(who_to_greet): Runs a Docker container that greets a named user """ container = client.containers.run( - image='python:3.9', - command='python3 -c "print(\'Hello, {}!\')"'.format(who_to_greet), - detach=True + image="python:3.9", + command="python3 -c \"print('Hello, {}!')\"".format(who_to_greet), + detach=True, ) # Do the things -@app.route('/webhook', methods=['POST']) +@app.route("/webhook", methods=["POST"]) def respond(): who_to_greet = request.json["repository"]["owner"]["login"] - job = q.enqueue_call(func=run_container, args=(), - result_ttl=5000) + job = q.enqueue_call(func=run_container, args=(), result_ttl=5000) return Response(status=201) diff --git a/systemd/worker.py b/systemd/worker.py index faa4078..695f297 100755 --- a/systemd/worker.py +++ b/systemd/worker.py @@ -3,13 +3,13 @@ import redis from rq import Worker, Queue, Connection -listen = ['default'] +listen = ["default"] -redis_url = 'redis://localhost:16379' +redis_url = "redis://localhost:16379" conn = redis.from_url(redis_url) -if __name__ == '__main__': +if __name__ == "__main__": with Connection(conn): worker = Worker(list(map(Queue, listen))) worker.work()