Skip to content

Commit

Permalink
cleanup code
Browse files Browse the repository at this point in the history
  • Loading branch information
chriswebb09 committed Jan 2, 2024
1 parent 472fee4 commit 5dc49b4
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 41 deletions.
2 changes: 0 additions & 2 deletions DirectReport/browserview/auth/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
from werkzeug.security import generate_password_hash
from DirectReport.browserview.auth import bp
from DirectReport.browserview.services.github import GithubClient
from DirectReport.browserview.services.huggingface_client import HuggingFaceClient
from DirectReport.browserview.services.googleai_client import GoogleAIClient
from DirectReport.datadependencies import appsecrets
from DirectReport.models.report.report_builder import ReportBuilder
from DirectReport.models.user_model import UserModel
Expand Down
4 changes: 1 addition & 3 deletions DirectReport/browserview/dashboard/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def dashboard_reports_update():
repo_data.append(repo["name"])
raw_data = googleAi.get_data_from(prompt)
begin, end = raw_data.find('{'), raw_data.rfind('}')
filtered_str = raw_data[begin: end + 1]
filtered_str = raw_data[begin : end + 1]
response_data = json.loads(filtered_str)
response_data["broad_categories"] = {
"debug_info": 16,
Expand All @@ -72,8 +72,6 @@ def dashboard_reports_update():
"syntax_fix": 1,
}
response_data["repos"] = repo_data
print(response_data)
print("\n\n")
ReportBuilder.new(response_data, prompt, current_user.id, "DirectReport")
return response_data, 201

Expand Down
29 changes: 8 additions & 21 deletions DirectReport/browserview/main/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ def home():
@bp.route('/authorize/github')
def oauth2_authorize():
github_url = (
"https://github.com/login/oauth/authorize?scope=user:email&client_id="
+ client_id
+ "&client_secret="
+ client_secret
+ "&redirect_uri=http%3A%2F%2F127.0.0.1%3A5000%2Fcallback%2Fgithub"
"https://github.com/login/oauth/authorize?scope=user:email&client_id="
+ client_id
+ "&client_secret="
+ client_secret
+ "&redirect_uri=http%3A%2F%2F127.0.0.1%3A5000%2Fcallback%2Fgithub"
)
return redirect(github_url)

Expand All @@ -51,18 +51,15 @@ def get_commits_last_month(repo_name):
response = requests.get(url, headers=headers, params=params)
if response.status_code == 200:
pull_requests = response.json()
print(pull_requests)
return pull_requests
else:
print(f"Error: {response.status_code}")
print(response.text)


@bp.route('/repo', methods=['GET', 'POST'])
def reponame():
print("\n")
print(request.method)
print("/repo")
args_url = request.args.get('repo_url')
print(args_url)
h_token = session['header_token']
repo_name = "https://api.github.com/repos/" + args_url + "/commits"
headers = {
Expand All @@ -81,19 +78,17 @@ def reponame():

@bp.route('/callback/github', methods=['GET', 'POST'])
def ouath2_callback():
print("/callback/github")
data = {'client_id': client_id, 'client_secret': client_secret, 'code': request.args.get("code")}
response = requests.post('https://github.com/login/oauth/access_token', data=data)
res = response.text.split('&', 1)
token = res[0].split('=')[1]
HEADER_TOKEN = token
session['header_token'] = token
headers2 = {
'Accept': 'application/vnd.github+json',
'X-GitHub-Api-Version': '2022-11-28',
'Content-Type': 'application/x-www-form-urlencoded',
}
data2 = '{\n' + ' "access_token": "' + HEADER_TOKEN + '" \n}'
data2 = '{\n' + ' "access_token": "' + token + '" \n}'
response2 = requests.post(
url="https://api.github.com/applications/" + client_id + "/token",
headers=headers2,
Expand All @@ -109,9 +104,6 @@ def ouath2_callback():

@bp.route('/repos', methods=['GET', 'POST'])
def repos():
print("\n")
print(request.method)
print("/repos")
if request.method == 'GET':
h_token = session['header_token']
username = current_user.github_username
Expand Down Expand Up @@ -141,11 +133,9 @@ def repos():
print(f"Error Response FROM API: {response.status_code} - {response.text}")
return jsonify([]), 200
else:
print("posted to repos")
return jsonify([]), 200



@bp.route("/team", methods=['GET'])
def team():
return render_template('team/team.html', title='Team', data=[])
Expand All @@ -166,9 +156,6 @@ def repo(reponame=None):
client = GithubClient()
try:
repo = client.get_repo_issues(current_user.github_username, reponame)
print(repo)
print("\n")
except Exception as e:
print(e)
repo = []
return render_template('team/team.html', title='Team', data=repo)
4 changes: 0 additions & 4 deletions DirectReport/browserview/services/github.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
#!/usr/bin/env python3

import json
import re

import requests

from DirectReport.datadependencies import appsecrets, prompts


Expand Down Expand Up @@ -80,4 +77,3 @@ def get_repo_issues(self, repo_owner, repo_name):
response = requests.get(url, headers=headers)
response.raise_for_status()
return response.json()

1 change: 0 additions & 1 deletion DirectReport/browserview/services/googleai_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,3 @@ def query(self, prompt):
print(response.status_code)
data = {}
return data

6 changes: 2 additions & 4 deletions DirectReport/browserview/services/huggingface_client.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
#!/usr/bin/env python3

import json
import re

import requests

from DirectReport.datadependencies import appsecrets, prompts


class HuggingFaceClient:
def query(self, payload):
API_URL = "https://api-inference.huggingface.co/models/meta-llama/Llama-2-7b-chat-hf"
headers = {"Authorization": "Bearer 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"}
headers = {f"Authorization": f"Bearer {appsecrets.MISTRAL_API_KEY}"}
response = requests.post(API_URL, headers=headers, json=payload)
return response.json()
2 changes: 1 addition & 1 deletion DirectReport/browserview/services/prompt_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def generate_email(data):
return response


def get_team_summarys_from_git_shortlog(data):
def team_summary_from_shortlog(data):
prompt = prompts.GENERATE_SUMMARY_PROMPT_PREIX + data
message = [{"role": "user", "content": prompt}]
response = openai.ChatCompletion.create(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,11 @@ const AccountUserInfo = (userData, reportData) => {
</div>

<div className="rounded-2xl flex items-center justify-center">
<button className="bg-sky-500 hover:bg-slate-100 self-center text-white font-mono tracking-wide shadow-[1.5px_2px_1.0px_0.7px_rgba(0,0,0,0.48)] hover:white hover:text-blue-500 hover:border-gray-200 text-lg font-bold py-4 px-10 rounded-3xl mt-4 mb-8"
type="button">
<button className="bg-sky-500 hover:bg-slate-100 self-center text-white font-mono tracking-wide shadow-[1.5px_2px_1.0px_0.7px_rgba(0,0,0,0.48)] hover:white hover:text-blue-500 hover:border-gray-200 text-lg font-bold py-3 px-20 rounded-3xl mt-4 mb-6" type="button">
<svg xmlns="http://www.w3.org/2000/svg" className="h-7 w-6 inline-block ml-5" fill="currentColor" viewBox="0 0 24 24">
<path d="M12 0c-6.626 0-12 5.373-12 12 0 5.302 3.438 9.8 8.207 11.387.599.111.793-.261.793-.577v-2.234c-3.338.726-4.033-1.416-4.033-1.416-.546-1.387-1.333-1.756-1.333-1.756-1.089-.745.083-.729.083-.729 1.205.084 1.839 1.237 1.839 1.237 1.07 1.834 2.807 1.304 3.492.997.107-.775.418-1.305.762-1.604-2.665-.305-5.467-1.334-5.467-5.931 0-1.311.469-2.381 1.236-3.221-.124-.303-.535-1.524.117-3.176 0 0 1.008-.322 3.301 1.23.957-.266 1.983-.399 3.003-.404 1.02.005 2.047.138 3.006.404 2.291-1.552 3.297-1.23 3.297-1.23.653 1.653.242 2.874.118 3.176.77.84 1.235 1.911 1.235 3.221 0 4.609-2.807 5.624-5.479 5.921.43.372.823 1.102.823 2.222v3.293c0 .319.192.694.801.576 4.765-1.589 8.199-6.086 8.199-11.386 0-6.627-5.373-12-12-12z"/>
</svg>
<a className="px-4 py-10 tracking-wide" href='/authorize/github'>GitHub</a>
<a className="pl-3 pr-15 py-5 tracking-wide" href='/authorize/github'>GitHub</a>
</button>
</div>
</div>
Expand Down
2 changes: 0 additions & 2 deletions DirectReport/browserview/static/js/teamreport/teamreport.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ class TeamReport extends React.Component {
"Content-Type": "application/json"
}
}).then(result => {
console.log(result.data);
// alert(result.data);
this.handleTeamDataChange(result.data["team"]);
this.handleReportDataChange(result.data["report"]);
showGraphics(result.data, '#map-container');
Expand Down

0 comments on commit 5dc49b4

Please sign in to comment.