From 68e4ef71af7609ccc6d9d624c33f6a0e30a43c66 Mon Sep 17 00:00:00 2001 From: HRUSHIKESH DOKALA <96101829+Hk669@users.noreply.github.com> Date: Sat, 13 Jul 2024 00:57:34 +0530 Subject: [PATCH] chore: Improvements (#10) * feat: store env variables * 1. fetch repos based on user query everytime --- client/package-lock.json | 23 +++++++++++++++++++---- client/package.json | 3 +++ client/src/App.jsx | 17 ++++++++++------- client/src/components/Input/Input.jsx | 2 +- client/src/components/Login/Login.jsx | 8 +++++--- src/api.py | 14 +++++++++----- src/search.py | 2 +- 7 files changed, 48 insertions(+), 21 deletions(-) diff --git a/client/package-lock.json b/client/package-lock.json index 2f90802..39f1cbf 100644 --- a/client/package-lock.json +++ b/client/package-lock.json @@ -22,6 +22,9 @@ "react-scripts": "5.0.1", "react-toastify": "^10.0.5", "web-vitals": "^2.1.4" + }, + "devDependencies": { + "dotenv": "^16.4.5" } }, "node_modules/@adobe/css-tools": { @@ -7190,11 +7193,15 @@ } }, "node_modules/dotenv": { - "version": "10.0.0", - "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-10.0.0.tgz", - "integrity": "sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q==", + "version": "16.4.5", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.5.tgz", + "integrity": "sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg==", + "dev": true, "engines": { - "node": ">=10" + "node": ">=12" + }, + "funding": { + "url": "https://dotenvx.com" } }, "node_modules/dotenv-expand": { @@ -15178,6 +15185,14 @@ } } }, + "node_modules/react-scripts/node_modules/dotenv": { + "version": "10.0.0", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-10.0.0.tgz", + "integrity": "sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q==", + "engines": { + "node": ">=10" + } + }, "node_modules/react-toastify": { "version": "10.0.5", "resolved": "https://registry.npmjs.org/react-toastify/-/react-toastify-10.0.5.tgz", diff --git a/client/package.json b/client/package.json index 59769a8..b60cac6 100644 --- a/client/package.json +++ b/client/package.json @@ -41,5 +41,8 @@ "last 1 firefox version", "last 1 safari version" ] + }, + "devDependencies": { + "dotenv": "^16.4.5" } } diff --git a/client/src/App.jsx b/client/src/App.jsx index 17d0028..89e0a96 100644 --- a/client/src/App.jsx +++ b/client/src/App.jsx @@ -23,13 +23,16 @@ function App() { const token = localStorage.getItem("jwt_token"); if (token) { try { - const response = await fetch(`http://127.0.0.1:8000/verify-token`, { - method: "GET", - headers: { - Authorization: `Bearer ${token}`, - "Content-Type": "application/json", - }, - }); + const response = await fetch( + `${process.env.REACT_APP_API_URL}/verify-token`, + { + method: "GET", + headers: { + Authorization: `Bearer ${token}`, + "Content-Type": "application/json", + }, + } + ); if (response.ok) { const data = await response.json(); setIsAuthenticated(true); diff --git a/client/src/components/Input/Input.jsx b/client/src/components/Input/Input.jsx index 511b396..c515d30 100644 --- a/client/src/components/Input/Input.jsx +++ b/client/src/components/Input/Input.jsx @@ -32,7 +32,7 @@ const Input = ({ onSubmit }) => { try { const response = await axios.post( - `http://127.0.0.1:8000/api/recommendations/`, + `${process.env.REACT_APP_API_URL}/api/recommendations/`, { username: username, languages: languages, diff --git a/client/src/components/Login/Login.jsx b/client/src/components/Login/Login.jsx index 7bb23d2..fb5f811 100644 --- a/client/src/components/Login/Login.jsx +++ b/client/src/components/Login/Login.jsx @@ -3,9 +3,11 @@ import React from "react"; import "./Login.css"; import { FaGithub } from "react-icons/fa"; +const API_URL = process.env.REACT_APP_API_URL; + const Login = () => { const handleLogin = () => { - window.location.href = `http://127.0.0.1:8000/github-login`; + window.location.href = `${API_URL}/github-login`; }; return ( @@ -59,8 +61,8 @@ const Login = () => { your skills and interests.
  • - Exposure: Enables you to contribute to - the open-source community and make a difference. + Exposure: Enables you to contribute to the + open-source community and make a difference.
  • Secure, Fast, and Free to Use: Access all diff --git a/src/api.py b/src/api.py index 0b0fd2a..c4655f9 100644 --- a/src/api.py +++ b/src/api.py @@ -13,9 +13,7 @@ import uvicorn from .user_data import get_repos from src.db import (recommend, - get_topic_based_recommendations, - get_chromadb_collection, - upsert_to_chroma_db) + get_topic_based_recommendations) from src.models import User, GithubUser, get_user_collection load_dotenv() @@ -165,7 +163,7 @@ async def get_recommendations(request: Request, current_user: dict = Depends(get body = await request.json() extra_topics = body.get("extra_topics", []) languages = body.get("languages", []) - username = body.get("username", current_user.get("username")) + urls = [] user = User(username=current_user["username"], access_token=current_user["access_token"],extra_topics=extra_topics, extra_languages=languages) @@ -175,6 +173,13 @@ async def get_recommendations(request: Request, current_user: dict = Depends(get logger.info("Generating topic-based recommendations") return get_topic_based_recommendations(user) + try: + fetched_repos = await main(language_topics, access_token=user.access_token, extra_topics=extra_topics, extra_languages=languages) + logger.info(f"Fetched {len(fetched_repos)} repositories") + except Exception as e: + logger.error(f"Error fetching repositories: {str(e)}") + raise ValueError("Error fetching repositories") + try: urls = recommend(user_details, language_topics) except Exception as e: @@ -184,7 +189,6 @@ async def get_recommendations(request: Request, current_user: dict = Depends(get if urls and len(urls) < 10: logger.info("Fewer than 10 recommendations found, fetching more repositories based on topics") - fetched_repos = await main(language_topics, access_token=user.access_token, extra_topics=extra_topics, extra_languages=languages) urls = recommend(user_details, language_topics) seen_full_names = set() diff --git a/src/search.py b/src/search.py index c25f844..db6a8a2 100644 --- a/src/search.py +++ b/src/search.py @@ -123,7 +123,7 @@ async def main(language_topics, results = await asyncio.gather(*tasks) for result in results: unique_repos.update(result) - print(f"Unique Repositories: {unique_repos}") + print(f"Unique Repositories: {len(unique_repos)}") logger.info(f"Found {len(unique_repos)} unique repositories\n--------")