-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
52 lines (41 loc) · 1.4 KB
/
app.py
File metadata and controls
52 lines (41 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# 📄 File: app.py
from flask import Flask, request, jsonify
from run_docgen_cli import run_docgen, run_docgen_for_existing_repo
import json
from flask_cors import CORS
from docgen_from_github import checkout_branch
from dotenv import load_dotenv
load_dotenv()
import os
app = Flask(__name__)
CORS(app)
@app.route("/default-doc", methods=["POST"])
def generate_docs():
data = request.get_json()
repo_url = data.get("repo_url", "").strip()
branch = data.get("branch", "").strip()
if not repo_url:
return jsonify({"error": "Missing repo_url"}), 400
try:
if branch:
print(f"📦 Generating docs for branch: {branch}")
result = run_docgen_for_existing_repo(branch)
else:
print(f"📦 Generating docs from URL: {repo_url}")
result = run_docgen(repo_url)
return jsonify(result)
except Exception as e:
return jsonify({"error":str(e)}),500
@app.route("/branch-doc", methods=["POST"])
def generate_docs_for_branch():
data = request.get_json()
branch = data.get("branch")
if not branch:
return jsonify({"error": "Missing branch"}), 400
try:
result = run_docgen_for_existing_repo(branch)
return jsonify(result)
except Exception as e:
return jsonify({"error": str(e)}), 500
if __name__ == "__main__":
app.run(host="0.0.0.0", port=os.getenv("PORT", 5000))