-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
217 lines (168 loc) · 6.53 KB
/
app.py
File metadata and controls
217 lines (168 loc) · 6.53 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
#!/usr/bin/env python3
"""
Flask web frontend for GitHub Profile Analyzer & Candidate Matcher.
Usage:
python app.py
Then open http://localhost:5000 in your browser.
"""
from flask import Flask, render_template, request, jsonify, Response
import os
import json
from dotenv import load_dotenv
# Import functions from the existing CLI tool
from github_commits import (
get_user_repos,
get_commits_for_repo,
get_commit_patch,
prepare_commits_for_analysis,
analyze_commits_with_llm,
generate_rating_report,
parse_job_description,
search_github_users,
analyze_candidate_for_job,
fetch_user_commits,
evaluate_candidates,
generate_ranked_report,
)
load_dotenv()
app = Flask(__name__)
# Set up GitHub headers
def get_headers():
headers = {"Accept": "application/vnd.github.v3+json"}
token = os.environ.get("GITHUB_TOKEN")
if token:
headers["Authorization"] = f"token {token}"
return headers
@app.route("/")
def index():
"""Home page - single user analysis form."""
return render_template("index.html")
@app.route("/analyze", methods=["POST"])
def analyze():
"""Analyze a single GitHub user."""
username = request.form.get("username", "").strip()
if not username:
return render_template("profile.html", error="Please enter a username")
headers = get_headers()
try:
# Fetch repos and commits
repos = get_user_repos(username, headers)
if not repos:
return render_template("profile.html", error=f"No repositories found for {username}")
all_commits = []
for repo in repos:
repo_name = repo["name"]
owner = repo["owner"]["login"]
commits = get_commits_for_repo(owner, repo_name, username, headers)
for commit in commits:
all_commits.append({"repo": repo_name, "owner": owner, "commit": commit})
if not all_commits:
return render_template("profile.html", error=f"No commits found for {username}")
# Sort by date
all_commits.sort(key=lambda x: x["commit"]["commit"]["author"]["date"], reverse=True)
# Fetch patches (limit to 50 for speed)
patches = {}
for item in all_commits[:50]:
sha = item["commit"]["sha"]
patch = get_commit_patch(item["owner"], item["repo"], sha, headers)
patches[sha] = patch or ""
# Analyze with LLM
commit_summaries = prepare_commits_for_analysis(all_commits, patches)
analysis = analyze_commits_with_llm(username, commit_summaries)
return render_template(
"profile.html",
username=username,
analysis=analysis,
total_commits=len(all_commits),
total_repos=len(repos)
)
except Exception as e:
return render_template("profile.html", error=str(e))
@app.route("/match")
def match_form():
"""Job matching form page."""
return render_template("match.html")
@app.route("/match", methods=["POST"])
def match():
"""Match candidates against a job description."""
jd_text = request.form.get("job_description", "").strip()
users_text = request.form.get("usernames", "").strip()
if not jd_text:
return render_template("match.html", error="Please enter a job description")
if not users_text:
return render_template("match.html", error="Please enter candidate usernames")
headers = get_headers()
try:
# Parse job description
jd_requirements = parse_job_description(jd_text)
# Parse usernames
usernames = [u.strip() for u in users_text.replace("\n", ",").split(",") if u.strip()]
if not usernames:
return render_template("match.html", error="No valid usernames provided")
# Evaluate candidates
results = evaluate_candidates(usernames, jd_requirements, headers)
return render_template(
"results.html",
jd_requirements=jd_requirements,
results=results,
mode="match"
)
except Exception as e:
return render_template("match.html", error=str(e))
@app.route("/search")
def search_form():
"""GitHub search form page."""
return render_template("search.html")
@app.route("/search", methods=["POST"])
def search():
"""Search GitHub for candidates and match against JD."""
jd_text = request.form.get("job_description", "").strip()
language = request.form.get("language", "").strip() or None
location = request.form.get("location", "").strip() or None
experience_level = request.form.get("experience_level", "any").strip()
max_candidates = int(request.form.get("max_candidates", 10))
if not jd_text:
return render_template("search.html", error="Please enter a job description")
headers = get_headers()
try:
# Parse job description
jd_requirements = parse_job_description(jd_text)
# Search GitHub for users filtered by experience level
usernames = search_github_users(
headers,
language=language,
location=location,
experience_level=experience_level,
max_results=max_candidates
)
if not usernames:
return render_template("search.html", error="No candidates found matching search criteria")
# Evaluate candidates
results = evaluate_candidates(usernames[:max_candidates], jd_requirements, headers)
return render_template(
"results.html",
jd_requirements=jd_requirements,
results=results,
mode="search",
search_params={"language": language, "location": location, "experience_level": experience_level}
)
except Exception as e:
return render_template("search.html", error=str(e))
@app.route("/api/export", methods=["POST"])
def export_results():
"""Export results as JSON."""
data = request.get_json()
return Response(
json.dumps(data, indent=2),
mimetype="application/json",
headers={"Content-Disposition": "attachment;filename=results.json"}
)
if __name__ == "__main__":
# Check for required environment variables
if not os.environ.get("OPENROUTER_API_KEY"):
print("Warning: OPENROUTER_API_KEY not set. Analysis features will not work.")
if not os.environ.get("GITHUB_TOKEN"):
print("Warning: GITHUB_TOKEN not set. You may hit rate limits.")
print("\nStarting GitHub Analyzer Web UI...")
print("Open http://localhost:5000 in your browser\n")
app.run(debug=True, port=5000)