Skip to content

Commit

Permalink
Merge pull request #67 from chriswebb09/dev-branch
Browse files Browse the repository at this point in the history
Dev branch
  • Loading branch information
chriswebb09 authored Jan 6, 2024
2 parents 2ec88dc + 33b39c6 commit 3acafad
Show file tree
Hide file tree
Showing 14 changed files with 530 additions and 189 deletions.
1 change: 1 addition & 0 deletions DirectReport/browserview/auth/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def account_data():
"username": current_user.username,
"email": current_user.email,
"github_username": current_user.github_username,
"github_repo": current_user.github_repo
}
user_element = {"user": user_account, "reports": report_results, "shortlog": shortlog}
return user_element, 201
25 changes: 21 additions & 4 deletions DirectReport/browserview/dashboard/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
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.browserview.services.prompt_logic import generate_email, team_summary_from_shortlog
from DirectReport.models.report.report_model import ReportModel
from DirectReport.datadependencies import appsecrets

Expand Down Expand Up @@ -55,13 +56,27 @@ def dashboard_reports_update():
client = GithubClient()
h_token = session['header_token']
user_repos = client.get_user_repos(current_user.github_username, h_token)
commits_last_month = client.get_commits_in_last_month(current_user.github_username, current_user.github_repo, h_token)
commits_last_sixty = client.get_commits_in_last_sixty_days(current_user.github_username, current_user.github_repo, h_token)
commits_last_ninety = client.get_commits_in_last_ninety_days(current_user.github_username, current_user.github_repo, h_token)
get_pull_requests_count = client.get_pull_requests_count(current_user.github_username, current_user.github_repo, h_token)
get_pull_requests_count_sixty = client.get_pull_requests_count_sixty_days(current_user.github_username, current_user.github_repo, h_token)
repo_data = []
for repo in user_repos:
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]
response_data = json.loads(filtered_str)
raw_data = team_summary_from_shortlog(prompt)
print(raw_data)
raw_reponse = raw_data["choices"][0]["message"]["content"]
response_data = json.loads(raw_reponse)
# print(response_data)
# list(raw_data.choices)[0]
# my_openai_obj.to_dict()['message']['content']
# response_data = json.loads(raw_data)
# response_data = json.dumps(raw_data)
# raw_data = googleAi.get_data_from(prompt)
# begin, end = raw_data.find('{'), raw_data.rfind('}')
# filtered_str = raw_data[begin: end + 1]
# response_data = json.loads(filtered_str)
response_data["broad_categories"] = {
"debug_info": 16,
"code_maintenance": 9,
Expand All @@ -71,6 +86,8 @@ def dashboard_reports_update():
"readme_update": 1,
"syntax_fix": 1,
}
response_data["commit_nums"] = {"15 days": 4, "30 days": (commits_last_month / 10), "60 days": (commits_last_sixty / 10), "90 days": (commits_last_ninety / 10), "120 days": 30}
response_data["pull_requests"] = {"30 days": 5, "60 days": 10, "90 days": 15, "120 days": 20, "150 days": 20, "1 year": 30}
response_data["repos"] = repo_data
ReportBuilder.new(response_data, prompt, current_user.id, "DirectReport")
return response_data, 201
Expand Down
5 changes: 5 additions & 0 deletions DirectReport/browserview/main/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
def before_request():
if current_user.is_authenticated:
print("authenticated user")
print(current_user.github_username)
print(current_user.github_repo)
else:
print("unauthenticated user")

Expand Down Expand Up @@ -60,8 +62,11 @@ def get_commits_last_month(repo_name):
@bp.route('/repo', methods=['GET', 'POST'])
def reponame():
args_url = request.args.get('repo_url')
repo = args_url.split('/')[1]
h_token = session['header_token']
repo_name = "https://api.github.com/repos/" + args_url + "/commits"
user_model = UserModel()
user_model.update_github_repo(current_user.email, repo)
headers = {
'Accept': 'application/vnd.github+json',
'Authorization': 'Bearer ' + h_token,
Expand Down
135 changes: 129 additions & 6 deletions DirectReport/browserview/services/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import re
import requests
from DirectReport.datadependencies import appsecrets, prompts

from datetime import datetime, timedelta

class GithubClient:
# Define a function to parse the git shortlog
Expand Down Expand Up @@ -45,7 +45,7 @@ def get_pull_request_comments(self, repo_owner, repo_name):
response.raise_for_status()
return response.json()

def get_pull_requests_count(self, repo_owner, repo_name):
def get_pull_requests_count(self, repo_owner, repo_name, token):
"""
Gets the number of comments on a pull request.
Expand All @@ -58,11 +58,64 @@ def get_pull_requests_count(self, repo_owner, repo_name):
The number of comments on the pull request.
"""

current_date = datetime.now()
thirty_days_ago = datetime.now() - timedelta(days=30)
since = thirty_days_ago.isoformat()
url = f"https://api.github.com/repos/{repo_owner}/{repo_name}/pulls"
headers = {"Authorization": f"token {appsecrets.GITHUB_TOKEN}"}
response = requests.get(url, headers=headers)
response.raise_for_status()
return len(response.json())
commits_count = 0
page = 1
per_page = 100 # Number of results per page
while True:
# Make a request to the GitHub API
response = requests.get(url, headers=headers, params={'since': since, 'page': page, 'per_page': per_page})
response.raise_for_status()
if response.status_code != 200:
# Break the loop if the response is not successful
break
commits = response.json()
current_count = len(commits)
commits_count += current_count
if current_count < per_page:
break
page += 1
return commits_count

def get_pull_requests_count_sixty_days(self, repo_owner, repo_name, token):
"""
Gets the number of comments on a pull request.
Args:
repo_owner: The owner of the GitHub repository.
repo_name: The name of the GitHub repository.
pull_request_number: The number of the pull request.
Returns:
The number of comments on the pull request.
"""

current_date = datetime.now()
thirty_days_ago = datetime.now() - timedelta(days=60)
since = thirty_days_ago.isoformat()
url = f"https://api.github.com/repos/{repo_owner}/{repo_name}/pulls"
headers = {"Authorization": f"token {appsecrets.GITHUB_TOKEN}"}
commits_count = 0
page = 1
per_page = 100 # Number of results per page
while True:
# Make a request to the GitHub API
response = requests.get(url, headers=headers, params={'since': since, 'page': page, 'per_page': per_page})
response.raise_for_status()
if response.status_code != 200:
# Break the loop if the response is not successful
break
commits = response.json()
current_count = len(commits)
commits_count += current_count
if current_count < per_page:
break
page += 1
return commits_count

def get_user_repos(self, repo_owner, token):
url = f"https://api.github.com/users/{repo_owner}/repos?sort=updated&order=desc"
Expand All @@ -71,9 +124,79 @@ def get_user_repos(self, repo_owner, token):
response.raise_for_status()
return response.json()

def get_repo_issues(self, repo_owner, repo_name):
def get_repo_issues(self, repo_owner, repo_name, token):
headers = {"Authorization": f"token {appsecrets.GITHUB_TOKEN}"}
url = f"https://api.github.com/repos/{repo_owner}/{repo_name}/issues"
response = requests.get(url, headers=headers)
response.raise_for_status()
return response.json()

def get_commits_in_last_month(self, repo_owner, repo_name, token):
current_date = datetime.now()
thirty_days_ago = datetime.now() - timedelta(days=30)
since = thirty_days_ago.isoformat()
headers = {"Authorization": f"token {token}"}
url = f"https://api.github.com/repos/{repo_owner}/{repo_name}/commits"
commits_count = 0
page = 1
per_page = 100 # Number of results per page
while True:
# Make a request to the GitHub API
response = requests.get(url, headers=headers, params={'since': since, 'page': page, 'per_page': per_page})
if response.status_code != 200:
# Break the loop if the response is not successful
break
commits = response.json()
current_count = len(commits)
commits_count += current_count
if current_count < per_page:
break
page += 1
return commits_count

def get_commits_in_last_sixty_days(self, repo_owner, repo_name, token):
current_date = datetime.now()
sixty_days_ago = datetime.now() - timedelta(days=60)
since = sixty_days_ago.isoformat()
headers = {"Authorization": f"token {token}"}
url = f"https://api.github.com/repos/{repo_owner}/{repo_name}/commits"
commits_count = 0
page = 1
per_page = 100 # Number of results per page
while True:
# Make a request to the GitHub API
response = requests.get(url, headers=headers, params={'since': since, 'page': page, 'per_page': per_page})
if response.status_code != 200:
# Break the loop if the response is not successful
break
commits = response.json()
current_count = len(commits)
commits_count += current_count
if current_count < per_page:
break
page += 1
return commits_count

def get_commits_in_last_ninety_days(self, repo_owner, repo_name, token):
current_date = datetime.now()
ninety_days_ago = datetime.now() - timedelta(days=90)
since = ninety_days_ago.isoformat()
headers = {"Authorization": f"token {token}"}
url = f"https://api.github.com/repos/{repo_owner}/{repo_name}/commits"
commits_count = 0
page = 1
per_page = 100 # Number of results per page
while True:
# Make a request to the GitHub API
response = requests.get(url, headers=headers, params={'since': since, 'page': page, 'per_page': per_page})
if response.status_code != 200:
# Break the loop if the response is not successful
break
commits = response.json()
current_count = len(commits)
commits_count += current_count
if current_count < per_page:
break
page += 1
return commits_count

Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,15 @@ const AccountUserInfo = (userData, reportData) => {
<ul>
<li>
<p className="text-justify pt-1 text-md font-mono tracking-wide text-sky-800">
<span className="ml-10 font-black font-mono">GITHUB ACOUNT USERNAME: </span>
{userData.github_username}
<span className="ml-10 font-black font-mono">GITHUB ACCOUNT: </span>
{userData.github_username ? userData.github_username : 'None Connected'}
</p>
</li>
<l>
<p className="text-justify pt-1 text-md font-mono tracking-wide text-sky-800">
<span className="ml-10 font-black font-mono">SELECTED REPO: </span>
DirectReport
{userData.github_repo ? userData.github_repo : 'None Selected'}

</p>
</l>
</ul>
Expand Down
18 changes: 9 additions & 9 deletions DirectReport/browserview/static/js/auth/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ const LoginForm = () => {
<div className="flex flex-col items-center justify-center px-6 py-20 mx-auto md:h-90 lg:py-220">
<div className="w-full bg-blue-500 rounded-3xl shadow dark:border md:mt-0 sm:max-w-md xl:p-0 dark:bg-gray-800 dark:border-gray-700 rounded-3xl shadow-[1.0px_1.0px_7.0px_0.0px_rgba(0,0,0,0.58)]">
<div className="p-6 space-y-4 md:space-y-6 sm:p-8">
<h1 className="text-xl font-bold leading-tight tracking-tight text-white md:text-2xl dark:text-white">
Sign in to your account
<h1 className="text-xl font-semibold leading-tight tracking-wider text-white md:text-2xl dark:text-white">
Sign into your account
</h1>
<form className="space-y-4 md:space-y-6" method="POST" action="/login">
<div>
<label htmlFor="email" className="block mb-2 text-sm font-medium text-white dark:text-white">Your email</label>
<input type="email" name="email" id="email" className="bg-gray-50 border border-gray-300 dark:text-white sm:text-sm rounded-lg focus:ring-primary-600 focus:border-primary-600 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500 shadow-[1.0px_1.0px_7.0px_0.0px_rgba(0,0,0,0.58)] " placeholder="[email protected]" required=""/>
<label htmlFor="email" className="block mb-2 text-sm font-semibold tracking-wider text-white dark:text-white">Your email</label>
<input type="email" name="email" id="email" className="bg-gray-50 border border-gray-300 dark:text-white font-semibold tracking-wider sm:text-sm rounded-lg focus:ring-primary-600 focus:border-primary-600 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500 shadow-[1.0px_1.0px_7.0px_0.0px_rgba(0,0,0,0.58)] " placeholder="[email protected]" required=""/>
</div>
<div>
<label htmlFor="password" className="block mb-2 text-sm font-medium text-white dark:text-white">
<label htmlFor="password" className="block mb-2 text-sm font-semibold tracking-wider text-white dark:text-white">
Password
</label>
<input type="password" name="password" id="password" placeholder="••••••••" className="bg-gray-50 border border-gray-300 text-white sm:text-sm rounded-lg focus:ring-primary-600 focus:border-primary-600 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500 shadow-[1.0px_1.0px_7.0px_0.0px_rgba(0,0,0,0.58)] " required=""/>
<input type="password" name="password" id="password" placeholder="••••••••" className="bg-gray-50 border border-gray-300 text-blue-500 font-semibold tracking-wider sm:text-sm rounded-lg focus:ring-primary-600 focus:border-primary-600 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500 shadow-[1.0px_1.0px_7.0px_0.0px_rgba(0,0,0,0.58)] " required=""/>
</div>
<div className="flex items-center justify-between">
<div className="flex items-start">
Expand All @@ -27,11 +27,11 @@ const LoginForm = () => {
Forgot password?
</a>
</div>
<button type="submit" className="w-full text-white bg-sky-500 hover:bg-primary-700 focus:ring-4 focus:outline-none focus:ring-primary-300 font-medium rounded-3xl text-sm px-5 py-2.5 text-center dark:bg-primary-600 dark:hover:bg-primary-700 dark:focus:ring-primary-800 shadow-[1.0px_1.0px_7.0px_0.0px_rgba(0,0,0,0.58)] ">
Sign in
<button type="submit" className="w-full font-semibold tracking-wider text-white bg-sky-500 hover:bg-primary-700 focus:ring-4 focus:outline-none focus:ring-primary-300 font-medium rounded-3xl text-sm px-5 py-2.5 text-center dark:bg-primary-600 dark:hover:bg-primary-700 dark:focus:ring-primary-800 shadow-[1.0px_1.0px_7.0px_0.0px_rgba(0,0,0,0.58)] ">
Sign In
</button>
<p className="text-sm font-light text-white dark:text-gray-400 ml-14">Don’t have an account yet?
<a href="/signup" className="font-medium text-gray-200 ml-3 hover:underline dark:text-primary-500">Sign up</a>
<a href="/signup" className="font-semibold tracking-wider text-gray-200 ml-3 hover:underline dark:text-primary-500">Sign up</a>
</p>
</form>
</div>
Expand Down
Loading

0 comments on commit 3acafad

Please sign in to comment.