Skip to content

Commit

Permalink
Merge pull request #57 from chriswebb09/dev-branch
Browse files Browse the repository at this point in the history
add in auto github connecting functionality
  • Loading branch information
chriswebb09 authored Jan 2, 2024
2 parents ef1dfb4 + 7ca5ebc commit 98d3b70
Show file tree
Hide file tree
Showing 27 changed files with 302 additions and 279 deletions.
Binary file removed DirectReport/browserview/api/.DS_Store
Binary file not shown.
72 changes: 0 additions & 72 deletions DirectReport/browserview/api/reports.py
Original file line number Diff line number Diff line change
@@ -1,84 +1,12 @@
#!/usr/bin/env python3

from flask import render_template, request, json
from flask_login import login_required, current_user

from DirectReport.browserview.services.github import GithubClient
from DirectReport.browserview.services.github import GoogleAIClient
from DirectReport.models.report.report_builder import ReportBuilder
from DirectReport.models.report.report_model import ReportModel

from DirectReport.browserview.api import bp


# @bp.route("/report", methods=['GET', 'POST'])
# @login_required
# def report():
# prompt = ""
# prompt = request.get_json()["prompt"]
# client = GithubClient()
# user_repos = client.get_user_repos("chriswebb09")
# repodata = []
# for repo in user_repos:
# repodata.append(repo["name"])
# log_item = "Adrian Prantl (67):\n add mangling testcase\n Debug Info: Represent private discriminators in DWARF.\n Revert \"Debug Info: Represent private discriminators in DWARF.\n Debug Info: Represent private discriminators in DWARF.\n Un-XFAIL and update test.\n Move the logic for ignoring the debug locations for closure setup code into SILGen. NFC-ish.\n Debug Info: Associate a function call with the beginning of the expression.\n Debug Info / SILGen: fix the source location of variable assignments\n typo\n Fix the debug locations of inserted operations in AvailableValueAggregator.\n Don't emit shadow copies for anonymous variables.\n Remove dead API IRGenDebugInfo::setArtificialTrapLocation().\n Use compiler-generated location for func.-sig.-spec. thunks\n whitespace\n Fix the missing inlined-at field of function-level SILDebugScopes.\n Add debug info support for inlined and specialized generic variables.\n Revert Add debug info support for inlined and specialized generic variables.\n Add debug info support for inlined and specialized generic variables.\n Update mangling prefix in Mangling.rst\n Add initial support for debug info for coroutine allocas.\n Temporarily disable failing test case, rdar://problem/43340064\n Add build-script support for the Swift LLDB backwards-compatibility tests.\n Remove accidentally committed debugging code\n Deserialize Swift compatibility version in CompilerInvocation::loadFromSerializedAST()\n SILGen: Preserve function argument debug info for arguments needing alloc_stack\n Use as the filename for SILLocation-less functions to avoid misleading source locatio\nns in backtraces.\n Add a -verify-linetable LLVM option.\n Enable debug info for inlined generics by default. It works now.\n Fix nonasserts compilation\n\nAhmad Alhashemi (5):\n [Parser] Detect nonbreaking space U+00A0 and fixit\n Move non-breaking space handling to lexUnknown\n Add more non-breaking space test cases\n Minor style edits\n Add tests for non-breaking space detect and fix-it\n\nAkshay Shrimali (1):\n Update README.md\n\nAlan Zeino (1):\n Fix typo in code example in libSyntax README\n\nAlbin Sadowski (1):\n Fix syntax highlighting in CHANGELOG (#15107)\n\nAlejandro (3):\n Remove a warning, some doc fixes (#16863)\n [SR-8178] Fix BinaryFloatingPoint.random(in:) open range returning upperBound (#17794)\n [Docs] Fix minor code typo in SILPro..Man..md\n\nAlex Blewitt (5):\n [SR-7032] Fix compare for lhs and rhs\n [SR-7036] Use || instead of && for kind comparison\n [SR-7041] Remove duplicate conditional check\n Remove duplicate verb\n [SR-7043] Remove duplicate if statement"
# googleAi = GoogleAIClient()
# response_data = googleAi.get_data_from(prompt).replace("\'", "\"")
# response_data = response_data.replace('\n', " ")
# data_json = json.loads(response_data)
# data_json["broad_categories"] = {
# "debug_info": 16,
# "code_maintenance": 9,
# "documentation": 7,
# "test_related": 6,
# "nonbreaking_space_handling": 5,
# "readme_update": 1,
# "syntax_fix": 1,
# }
# data_json["shortlog"] = client.parse_git_shortlog(log_item)
# data_json["repos"] = repodata
# ReportBuilder.new(data_json, prompt, current_user.id, "DirectReport")
# return data_json, 201


# @bp.route("/reports/new", methods=['GET', 'POST'])
# @login_required
# def team_report():
# if request.method == "POST":
# json_data = request.get_json()
# report_model = ReportModel(json_data["id"], json_data['summary'], json_data['created_at'])
# print(report_model)
# return render_template('team/teamreport.html', title='Team Report', data=[])
#

# @bp.route("/reports/<uid>", methods=['GET'])
# @login_required
# def get_report(uid=None):
# reports = ReportBuilder.get_reports_for_user_id(current_user.id)
# report = list(filter(lambda report: report["uuid"] == uid, reports))[0]
# return render_template('team/teamreport.html', title='Team Report', teamData=report["report"])
#


@bp.route("/reports/list", methods=['GET'])
@login_required
def get_list():
print(current_user.id)
reports = ReportBuilder.get_reports_for_user_id(current_user.id)
return reports, 201


#
# @bp.route("/reports", methods=['GET', 'POST'])
# @login_required
# def list_entries():
# """
# Retrieves and renders the list of all entries.
# :return: Rendered HTML template for the list page.
# """
# reports = ReportBuilder.get_reports_for_user_id(current_user.id)
# report_results = []
# for report in reports:
# report_element = {"report": report}
# report_results.append(report_element)
# return render_template('list.html', title='List', data=report_results)
8 changes: 1 addition & 7 deletions DirectReport/browserview/auth/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from flask import render_template, request, redirect, url_for, flash
from flask_login import login_user, login_required, logout_user, current_user
from werkzeug.security import generate_password_hash

from DirectReport.browserview.auth import bp
from DirectReport.browserview.services.github import GithubClient
from DirectReport.datadependencies import appsecrets
Expand Down Expand Up @@ -54,12 +53,6 @@ def login():
)


# @bp.route("/account", methods=['GET', 'POST'])
# @login_required
# def account():
# return render_template('account.html', title='Account', name=current_user.username, userid=current_user.id)


@bp.route("/account_data", methods=['GET'])
@login_required
def account_data():
Expand All @@ -78,6 +71,7 @@ def account_data():
"userid": current_user.id,
"username": current_user.username,
"email": current_user.email,
"github_username": current_user.github_username,
}
user_element = {"user": user_account, "reports": report_results, "shortlog": shortlog}
return user_element, 201
27 changes: 12 additions & 15 deletions DirectReport/browserview/dashboard/routes.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#!/usr/bin/env python3

from datetime import datetime, timedelta
import requests
from flask import render_template, session, request, redirect, json
from flask import render_template, session, request, redirect, json, jsonify
from flask_login import login_user, login_required, logout_user, current_user

from DirectReport.browserview.dashboard import bp
Expand All @@ -22,6 +21,12 @@ def dashboard_home():
return render_template('account.html', title='Account', name=current_user.username, userid=current_user.id)


@bp.route("/edit", methods=['GET', 'POST'])
@login_required
def dashbboard_edit():
return render_template('edit_account.html', title='Edit Account')


@bp.route("/reports/saved", methods=['GET', 'POST'])
@login_required
def dashboard_reports_saved():
Expand All @@ -32,12 +37,6 @@ def dashboard_reports_saved():

results = requests.get('http://127.0.0.1:5000/api/reports/list')
print(results)
# reports = ReportBuilder.get_reports_for_user_id(current_user.id)
# report_results = []
# for report in reports:
# report_element = {"report": report}
# report_results.append(report_element)
# print(len(report_results))
return render_template('list.html', title='List', data=results)


Expand All @@ -56,18 +55,13 @@ def dashboard_reports_update():
prompt = ""
prompt = request.get_json()["prompt"]
client = GithubClient()
user_repos = client.get_user_repos("chriswebb09")
user_repos = client.get_user_repos(current_user.github_username)
repodata = []
for repo in user_repos:
repodata.append(repo["name"])
log_item = "Adrian Prantl (67):\n add mangling testcase\n Debug Info: Represent private discriminators in DWARF.\n Revert \"Debug Info: Represent private discriminators in DWARF.\n Debug Info: Represent private discriminators in DWARF.\n Un-XFAIL and update test.\n Move the logic for ignoring the debug locations for closure setup code into SILGen. NFC-ish.\n Debug Info: Associate a function call with the beginning of the expression.\n Debug Info / SILGen: fix the source location of variable assignments\n typo\n Fix the debug locations of inserted operations in AvailableValueAggregator.\n Don't emit shadow copies for anonymous variables.\n Remove dead API IRGenDebugInfo::setArtificialTrapLocation().\n Use compiler-generated location for func.-sig.-spec. thunks\n whitespace\n Fix the missing inlined-at field of function-level SILDebugScopes.\n Add debug info support for inlined and specialized generic variables.\n Revert Add debug info support for inlined and specialized generic variables.\n Add debug info support for inlined and specialized generic variables.\n Update mangling prefix in Mangling.rst\n Add initial support for debug info for coroutine allocas.\n Temporarily disable failing test case, rdar://problem/43340064\n Add build-script support for the Swift LLDB backwards-compatibility tests.\n Remove accidentally committed debugging code\n Deserialize Swift compatibility version in CompilerInvocation::loadFromSerializedAST()\n SILGen: Preserve function argument debug info for arguments needing alloc_stack\n Use as the filename for SILLocation-less functions to avoid misleading source locatio\nns in backtraces.\n Add a -verify-linetable LLVM option.\n Enable debug info for inlined generics by default. It works now.\n Fix nonasserts compilation\n\nAhmad Alhashemi (5):\n [Parser] Detect nonbreaking space U+00A0 and fixit\n Move non-breaking space handling to lexUnknown\n Add more non-breaking space test cases\n Minor style edits\n Add tests for non-breaking space detect and fix-it\n\nAkshay Shrimali (1):\n Update README.md\n\nAlan Zeino (1):\n Fix typo in code example in libSyntax README\n\nAlbin Sadowski (1):\n Fix syntax highlighting in CHANGELOG (#15107)\n\nAlejandro (3):\n Remove a warning, some doc fixes (#16863)\n [SR-8178] Fix BinaryFloatingPoint.random(in:) open range returning upperBound (#17794)\n [Docs] Fix minor code typo in SILPro..Man..md\n\nAlex Blewitt (5):\n [SR-7032] Fix compare for lhs and rhs\n [SR-7036] Use || instead of && for kind comparison\n [SR-7041] Remove duplicate conditional check\n Remove duplicate verb\n [SR-7043] Remove duplicate if statement"
googleAi = GoogleAIClient()
response_data = googleAi.get_data_from(prompt)
print(response_data)
# ).replace("\'", "\"")
# response_data = response_data.replace('\n', " ")
# print(response_data)
# data_json = json.loads(response_data)
response_data["broad_categories"] = {
"debug_info": 16,
"code_maintenance": 9,
Expand All @@ -88,4 +82,7 @@ def dashboard_reports_update():
def dashboard_saved_report(uid=None):
reports = ReportBuilder.get_reports_for_user_id(current_user.id)
report = list(filter(lambda report: report["uuid"] == uid, reports))[0]
return render_template('team/teamreport.html', title='Team Report', teamData=report["report"])
json_data = json.dumps(report)
return render_template(
'team/teamreport.html', title='Team Report', data=json_data, report=json_data, raw_input=report['raw_input']
)
40 changes: 26 additions & 14 deletions DirectReport/browserview/main/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
from datetime import datetime, timedelta

import requests
from flask import render_template, session, request, redirect, json
from flask import render_template, session, request, redirect, json, jsonify
from flask_login import current_user

from DirectReport.models.user_model import UserModel
from DirectReport.browserview.main import bp
from DirectReport.browserview.services.github import GithubClient
from DirectReport.browserview.services.prompt_logic import generate_email
Expand Down Expand Up @@ -41,15 +42,12 @@ def get_commits_last_month():
owner = 'chriswebb09'
repo = 'your_repository'
url = f'https://api.github.com/repos/{owner}/{repo}/pulls'

# Replace 'your_token' with your personal access token
headers = {'Authorization': 'token your_token'}

# Calculate the date one month ago
since_date = (datetime.utcnow() - timedelta(days=30)).strftime('%Y-%m-%dT%H:%M:%SZ')
params = {'state': 'all', 'sort': 'created', 'direction': 'desc', 'since': since_date}
response = requests.get(url, headers=headers, params=params)

if response.status_code == 200:
pull_requests = response.json()
print(pull_requests)
Expand All @@ -71,7 +69,7 @@ def reponame():
response3 = requests.get(url=reponame, headers=headers443, auth=(client_id, client_secret))
json_Data3 = json.loads(response3.content)

USERNAME = "chriswebb09"
USERNAME = current_user.github_username
REPO = "DirectReport"

# Calculate the date one month ago
Expand Down Expand Up @@ -134,7 +132,6 @@ def ouath2_callback():
'X-GitHub-Api-Version': '2022-11-28',
'Content-Type': 'application/x-www-form-urlencoded',
}
HEADER_TOKEN = token
data2 = '{\n' + ' "access_token": "' + HEADER_TOKEN + '" \n}'
response2 = requests.post(
url="https://api.github.com/applications/" + client_id + "/token",
Expand All @@ -143,15 +140,30 @@ def ouath2_callback():
auth=(client_id, client_secret),
)
json_Data = json.loads(response2.content)
repos = requests.get(
json_Data["user"]['repos_url'] + "?sort=updated&direction=desc", data=data2, auth=(client_id, client_secret)
)
json_Data2 = json.loads(repos.content)
user_info = json_Data["user"]

user_model = UserModel()
user_model.update_github_username(current_user.email, user_info["login"])
return render_template('team/teamreport.html', title='Team', data=[])


@bp.route('/repos', methods=['GET', 'POST'])
def repos():
# args_url = request.args.get('repo_url')
h_token = session['header_token']
username = current_user.github_username # Replace with the GitHub username
url = f"https://api.github.com/users/{username}/repos" + "?sort=updated&direction=desc"
headers = {
'Accept': 'application/vnd.github+json',
'Authorization': 'Bearer ' + h_token,
'X-GitHub-Api-Version': '2022-11-28',
}
response = requests.get(url, headers=headers)
repos = response.json()
results = []
for repo in json_Data2:
for repo in repos:
owner = repo['owner']
url_repo = "https://api.github.com/repos/" + owner['login'] + "/" + repo['name']

data_res = {
"name": repo['name'],
"description": repo['description'],
Expand All @@ -160,7 +172,7 @@ def ouath2_callback():
"owner_url": owner['url'],
}
results.append(data_res)
return render_template('team/teamreport.html', title='Team', data=results)
return jsonify(results), 200


@bp.route("/team", methods=['GET'])
Expand All @@ -181,5 +193,5 @@ def generateemail():
@bp.route("/repo/<reponame>", methods=['GET'])
def repo(reponame=None):
client = GithubClient()
repo = client.get_repo_issues("chriswebb09", reponame)
repo = client.get_repo_issues(current_user.github_username, reponame)
return render_template('team/team.html', title='Team', data=repo)
8 changes: 2 additions & 6 deletions DirectReport/browserview/services/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,5 @@ def query(self, prompt):
def get_data_from(self, prompt):
response = self.query(prompt)
response_data = response["candidates"][0]["output"]
print("response: ")
# print(response_data.keys())
data2 = json.loads(response_data)
print(data2)
# print(response_data)
return data2
json_loaded = json.loads(response_data)
return json_loaded
2 changes: 0 additions & 2 deletions DirectReport/browserview/services/prompt_logic.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#!/usr/bin/env python3


import openai

from DirectReport.datadependencies import appsecrets, prompts

openai.api_key = appsecrets.SECRET_KEY
Expand Down
5 changes: 3 additions & 2 deletions DirectReport/browserview/static/js/account/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,16 @@ const Account = () => {
} else {
return (
<div className="mx-20 content-center mt-0 mb-0 h-50">
<div className="grid grid-cols-3 gap-8 mx-10 px-10 mt-2 justify-center">
<div className="py-2 px-2 mt-0 mb-2"></div>
<div className="grid grid-cols-3 gap-8 mx-10 px-10 mt-0 justify-center">
{userData && AccountUserInfo(userData, reportData)}
</div>
<div className="py-1 px-2 mt-0 mb-2"></div>
</div>
)
}
};



const domContainer = document.querySelector('#root');
ReactDOM.render(<Account/>, domContainer);
Loading

0 comments on commit 98d3b70

Please sign in to comment.