Skip to content

Commit

Permalink
The bot should ultimately provide one or more links to the repositori…
Browse files Browse the repository at this point in the history
…es for the projects that match the answers. OWASP-BLT#11
  • Loading branch information
Sarthak5598 committed May 28, 2024
1 parent aee940b commit 20df46c
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 27 deletions.
39 changes: 12 additions & 27 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import sqlite3

import json
import git
from dotenv import load_dotenv
from flask import Flask, jsonify, request
Expand Down Expand Up @@ -38,6 +39,9 @@
# logging.info(f"Body: {request.get_data(as_text=True)}")


with open('repos.json') as f:
repos_data = json.load(f)

@app.route("/update_server", methods=["POST"])
def webhook():
if request.method == "POST":
Expand Down Expand Up @@ -171,37 +175,18 @@ def list_repo():
user_name = data.get("user_name")
tech_name = text.strip().lower()

repos = None
if tech_name in {"django"}:
repos = "(https://github.com/OWASP-BLT/BLT)"
elif tech_name in {"python"}:
repos = "(https://github.com/OWASP-BLT/BLT)"
"(https://github.com/OWASP-BLT/BLT-Flutter)"
"(https://github.com/OWASP-BLT/BLT-Lettuce)"
elif tech_name in {"dart", "flutter"}:
repos = "(https://github.com/OWASP-BLT/BLT-Flutter)"
"(https://github.com/OWASP-BLT/BLT-Lettuce)"
elif tech_name in {"blockchain", "cryptography"}:
repos = "(https://github.com/OWASP-BLT/BLT-Bacon)"
elif tech_name in {"javascript"}:
repos = "(https://github.com/OWASP-BLT/BLT-Action)"
"(https://github.com/OWASP-BLT/BLT-Extension)"
"(https://github.com/OWASP-BLT/BLT)"
elif tech_name in {"css", "html"}:
repos = "(https://github.com/OWASP-BLT/BLT-Extension)"
"(https://github.com/OWASP-BLT/BLT)"

message = (
f"""Hello {user_name}, You can implement your '{tech_name}' knowledge here:
{repos}
"""
if repos
else f"Hello {user_name}, the technology '{tech_name}' is not recognized. Please try again."
)
repos = repos_data.get(tech_name)

if repos:
repos_list = "\n".join(repos)
message = f"Hello {user_name}, you can implement your '{tech_name}' knowledge here:\n{repos_list}"
else:
message = f"Hello {user_name}, the technology '{tech_name}' is not recognized. Please try again."

return jsonify(
{
"response_type": "in_channel",
"text": message,
}
)

38 changes: 38 additions & 0 deletions repo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"django": [
"https://github.com/OWASP-BLT/BLT"
],
"python": [
"https://github.com/OWASP-BLT/BLT",
"https://github.com/OWASP-BLT/BLT-Flutter",
"https://github.com/OWASP-BLT/BLT-Lettuce"
],
"dart": [
"https://github.com/OWASP-BLT/BLT-Flutter",
"https://github.com/OWASP-BLT/BLT-Lettuce"
],
"flutter": [
"https://github.com/OWASP-BLT/BLT-Flutter",
"https://github.com/OWASP-BLT/BLT-Lettuce"
],
"blockchain": [
"https://github.com/OWASP-BLT/BLT-Bacon"
],
"cryptography": [
"https://github.com/OWASP-BLT/BLT-Bacon"
],
"javascript": [
"https://github.com/OWASP-BLT/BLT-Action",
"https://github.com/OWASP-BLT/BLT-Extension",
"https://github.com/OWASP-BLT/BLT"
],
"css": [
"https://github.com/OWASP-BLT/BLT-Extension",
"https://github.com/OWASP-BLT/BLT"
],
"html": [
"https://github.com/OWASP-BLT/BLT-Extension",
"https://github.com/OWASP-BLT/BLT"
]
}

0 comments on commit 20df46c

Please sign in to comment.