-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
165 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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,2 @@ | ||
venv/ | ||
idea/ |
This file contains 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 |
---|---|---|
@@ -1,2 +1,26 @@ | ||
# star-track | ||
A simple utility to track the statistics of your GitHub repo ⭐ | ||
<h1 align="center">star-track </h1> | ||
|
||
## 👋 hello | ||
|
||
Star-Track is a user-friendly utility for tracking GitHub repository statistics. It offers an efficient way to monitor and analyze the performance of your GitHub projects. | ||
|
||
## 💻 install | ||
|
||
- clone repository | ||
|
||
```bash | ||
git clone https://github.com/SkalskiP/star-track.git | ||
``` | ||
|
||
- setup python environment and activate it [optional] | ||
|
||
```bash | ||
python3 -m venv venv | ||
source venv/bin/activate | ||
``` | ||
|
||
- install required dependencies | ||
|
||
```bash | ||
pip install -r requirements.txt | ||
``` |
This file contains 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,5 @@ | ||
{ | ||
"organizations": [ | ||
"roboflow" | ||
] | ||
} |
This file contains 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,2 @@ | ||
pandas | ||
requests |
Empty file.
This file contains 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,42 @@ | ||
import os | ||
from typing import List | ||
|
||
from startrack.config import GITHUB_TOKEN_ENV | ||
from startrack.core import list_organization_repositories, RepositoryType, \ | ||
RepositoryData | ||
|
||
GITHUB_TOKEN = os.environ.get(GITHUB_TOKEN_ENV, None) | ||
ORGANIZATION_NAME = "roboflow" | ||
|
||
|
||
def get_all_organization_repositories( | ||
github_token: str, | ||
organization_name: str, | ||
repository_type: RepositoryType | ||
) -> List: | ||
all_repositories = [] | ||
page = 1 | ||
while True: | ||
repos = list_organization_repositories( | ||
github_token=github_token, | ||
organization_name=organization_name, | ||
repository_type=repository_type, | ||
page=page) | ||
if not repos: | ||
break | ||
all_repositories.extend(repos) | ||
page += 1 | ||
|
||
return all_repositories | ||
|
||
|
||
repositories_json = get_all_organization_repositories( | ||
github_token=GITHUB_TOKEN, | ||
organization_name=ORGANIZATION_NAME, | ||
repository_type=RepositoryType.PUBLIC) | ||
repositories = [ | ||
RepositoryData.from_json(repository_json) | ||
for repository_json | ||
in repositories_json] | ||
|
||
print(repositories) |
This file contains 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 @@ | ||
GITHUB_TOKEN_ENV = "GITHUB_TOKEN" |
This file contains 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,87 @@ | ||
from dataclasses import dataclass | ||
from enum import Enum | ||
from typing import List, Dict, Any | ||
|
||
import requests | ||
|
||
|
||
@dataclass | ||
class RepositoryData: | ||
""" | ||
Data class for storing repository information. | ||
Attributes: | ||
full_name (str): The name of the repository. | ||
star_count (int): The number of stars the repository has. | ||
fork_count (int): The number of forks the repository has. | ||
""" | ||
full_name: str | ||
star_count: int | ||
fork_count: int | ||
|
||
@classmethod | ||
def from_json(cls, data: Dict[str, Any]) -> 'RepositoryData': | ||
full_name = data['full_name'] | ||
star_count = data['stargazers_count'] | ||
fork_count = data['forks_count'] | ||
return cls(full_name=full_name, star_count=star_count, fork_count=fork_count) | ||
|
||
|
||
class RepositoryType(Enum): | ||
""" | ||
Enum for specifying types of repositories. | ||
Attributes: | ||
ALL: Represents all types of repositories. | ||
PUBLIC: Represents public repositories. | ||
PRIVATE: Represents private repositories. | ||
FORKS: Represents forked repositories. | ||
SOURCES: Represents source repositories. | ||
MEMBER: Represents member repositories. | ||
""" | ||
|
||
ALL = "all" | ||
PUBLIC = "public" | ||
PRIVATE = "private" | ||
FORKS = "forks" | ||
SOURCES = "sources" | ||
MEMBER = "member" | ||
|
||
|
||
def list_organization_repositories( | ||
github_token: str, | ||
organization_name: str, | ||
repository_type: RepositoryType = RepositoryType.ALL, | ||
page: int = 1 | ||
) -> List: | ||
""" | ||
Lists the repositories of a specified GitHub organization based on the repository | ||
type and page number. | ||
Args: | ||
github_token (str): The GitHub personal access token for authentication. | ||
organization_name (str): The name of the GitHub organization whose repositories | ||
are to be listed. | ||
repository_type (RepositoryType): The type of repositories to list. Defaults to | ||
RepositoryType.ALL. | ||
page (int): The page number of the results to fetch. Defaults to 1. | ||
Returns: | ||
List: A list containing details of the organization's repositories. | ||
""" | ||
|
||
headers = { | ||
"Accept": "application/vnd.github+json", | ||
"Authorization": f"Bearer {github_token}", | ||
"X-GitHub-Api-Version": "2022-11-28" | ||
} | ||
|
||
params = { | ||
"type": repository_type.value, | ||
"page": page | ||
} | ||
|
||
url = f"https://api.github.com/orgs/{organization_name}/repos" | ||
|
||
response = requests.get(url, headers=headers, params=params) | ||
return response.json() |