-
Notifications
You must be signed in to change notification settings - Fork 119
feat: Enable real-time dashboard statistics and fix developer setup #194
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Parvm1102
wants to merge
2
commits into
AOSSIE-Org:main
Choose a base branch
from
Parvm1102:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,185 @@ | ||
| """ | ||
| Repository stats endpoint for analyzing GitHub repositories. | ||
| """ | ||
| import logging | ||
| import re | ||
| from typing import Any, Dict, List, Optional | ||
| from fastapi import APIRouter, HTTPException | ||
| from pydantic import BaseModel | ||
| from app.services.github.repo_stats import GitHubRepoStatsService | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
| router = APIRouter() | ||
|
|
||
|
|
||
| class RepoStatsRequest(BaseModel): | ||
| repo_url: str | ||
|
|
||
|
|
||
| class AuthorInfo(BaseModel): | ||
| login: str | None = None | ||
| avatar_url: str | None = None | ||
| profile_url: str | None = None | ||
|
|
||
|
|
||
| class ContributorInfo(BaseModel): | ||
| login: str | None = None | ||
| avatar_url: str | None = None | ||
| profile_url: str | None = None | ||
| contributions: int = 0 | ||
| type: str = "User" | ||
|
|
||
|
|
||
| class PullRequestDetail(BaseModel): | ||
| number: int | ||
| title: str | ||
| state: str | ||
| url: str | ||
| created_at: str | None = None | ||
| updated_at: str | None = None | ||
| author: AuthorInfo | ||
| labels: List[str] = [] | ||
| comments: int = 0 | ||
| draft: bool = False | ||
|
|
||
|
|
||
| class PullRequestStats(BaseModel): | ||
| open: int = 0 | ||
| closed: int = 0 | ||
| merged: int = 0 | ||
| total: int = 0 | ||
| details: List[PullRequestDetail] = [] | ||
|
|
||
|
|
||
| class IssueDetail(BaseModel): | ||
| number: int | ||
| title: str | ||
| state: str | ||
| url: str | ||
| created_at: str | None = None | ||
| author: AuthorInfo | ||
| labels: List[str] = [] | ||
| comments: int = 0 | ||
|
|
||
|
|
||
| class IssueStats(BaseModel): | ||
| open: int = 0 | ||
| closed: int = 0 | ||
| total: int = 0 | ||
| details: List[IssueDetail] = [] | ||
|
|
||
|
|
||
| class CommitActivity(BaseModel): | ||
| week: str | ||
| total: int = 0 | ||
| days: List[int] = [] | ||
|
|
||
|
|
||
| class ReleaseInfo(BaseModel): | ||
| tag_name: str | ||
| name: str | None = None | ||
| published_at: str | None = None | ||
| url: str | None = None | ||
| prerelease: bool = False | ||
|
|
||
|
|
||
| class RepositoryInfo(BaseModel): | ||
| name: str | ||
| full_name: str | ||
| description: str | None = None | ||
| url: str | ||
| stars: int = 0 | ||
| forks: int = 0 | ||
| watchers: int = 0 | ||
| open_issues_count: int = 0 | ||
| default_branch: str | None = None | ||
| created_at: str | None = None | ||
| updated_at: str | None = None | ||
| pushed_at: str | None = None | ||
| topics: List[str] = [] | ||
| license: str | None = None | ||
|
|
||
|
|
||
| class Metrics(BaseModel): | ||
| total_contributors: int = 0 | ||
| total_commits_recent: int = 0 | ||
| stars: int = 0 | ||
| forks: int = 0 | ||
| open_prs: int = 0 | ||
| open_issues: int = 0 | ||
|
|
||
|
|
||
| class RepoStatsResponse(BaseModel): | ||
| status: str | ||
| repo: str | None = None | ||
| message: str | None = None | ||
| repository: RepositoryInfo | None = None | ||
| contributors: List[ContributorInfo] = [] | ||
| pull_requests: PullRequestStats | None = None | ||
| issues: IssueStats | None = None | ||
| commit_activity: List[CommitActivity] = [] | ||
| languages: Dict[str, int] = {} | ||
| releases: List[ReleaseInfo] = [] | ||
| metrics: Metrics | None = None | ||
|
|
||
|
|
||
| def parse_repo_url(repo_input: str) -> tuple[str, str]: | ||
| """Parse repository URL or owner/repo format""" | ||
| repo_input = repo_input.strip().rstrip('/').rstrip('.git') | ||
|
|
||
| patterns = [ | ||
| (r'github\.com[:/]([^/]+)/([^/]+?)(?:\.git)?$', 'url'), | ||
| (r'^([a-zA-Z0-9][-a-zA-Z0-9]*)/([a-zA-Z0-9._-]+)$', 'short') | ||
| ] | ||
|
|
||
| for pattern, _ in patterns: | ||
| match = re.search(pattern, repo_input) | ||
| if match: | ||
| owner, repo = match.groups() | ||
| return owner, repo | ||
|
|
||
| raise ValueError( | ||
| f"Invalid repository format: '{repo_input}'. " | ||
| "Expected: 'owner/repo' or 'https://github.com/owner/repo'" | ||
| ) | ||
|
|
||
|
|
||
| @router.post("/repo-stats", response_model=RepoStatsResponse) | ||
| async def analyze_repository(request: RepoStatsRequest): | ||
| """ | ||
| Analyze a GitHub repository and return comprehensive stats. | ||
|
|
||
| Returns contributors, pull requests, issues, commit activity, | ||
| languages, and other repository metrics. | ||
| """ | ||
| try: | ||
| logger.info(f"Received repo-stats request for: {request.repo_url}") | ||
|
|
||
| # Parse the repository URL | ||
| try: | ||
| owner, repo = parse_repo_url(request.repo_url) | ||
| except ValueError as e: | ||
| raise HTTPException(status_code=400, detail=str(e)) from e | ||
|
|
||
| logger.info(f"Fetching stats for {owner}/{repo}") | ||
|
|
||
| # Fetch comprehensive stats from GitHub | ||
| async with GitHubRepoStatsService() as stats_service: | ||
| result = await stats_service.get_comprehensive_stats(owner, repo) | ||
|
|
||
| logger.info(f"Successfully fetched stats for {owner}/{repo}") | ||
|
|
||
| return result | ||
|
|
||
| except HTTPException: | ||
| raise | ||
| except ValueError as e: | ||
| logger.exception(f"Value error: {e}") | ||
| raise HTTPException(status_code=404, detail=str(e)) from e | ||
| except Exception as e: | ||
| logger.exception(f"Error analyzing repository: {e}") | ||
| raise HTTPException( | ||
| status_code=500, | ||
| detail=f"Failed to analyze repository: {str(e)}" | ||
| ) from e | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,3 +42,4 @@ pytest_cache/ | |
| .env | ||
| *.sqlite3 | ||
| .vercel | ||
| repositories/ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.