Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
@@ -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
19 changes: 12 additions & 7 deletions python/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,34 +17,39 @@
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
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?
# put it into redis to queue up something bigger?
11 changes: 5 additions & 6 deletions systemd/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Check notice

Code scanning / CodeQL

Unused local variable

The value assigned to local variable 'job' is never used.
return Response(status=201)
6 changes: 3 additions & 3 deletions systemd/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()