Skip to content

Commit

Permalink
initial commit 🎉
Browse files Browse the repository at this point in the history
  • Loading branch information
SkalskiP committed Jan 3, 2024
1 parent f503503 commit 18ea490
Show file tree
Hide file tree
Showing 8 changed files with 165 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
venv/
idea/
28 changes: 26 additions & 2 deletions README.md
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
```
5 changes: 5 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"organizations": [
"roboflow"
]
}
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pandas
requests
Empty file added startrack/__init__.py
Empty file.
42 changes: 42 additions & 0 deletions startrack/app.py
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)
1 change: 1 addition & 0 deletions startrack/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GITHUB_TOKEN_ENV = "GITHUB_TOKEN"
87 changes: 87 additions & 0 deletions startrack/core.py
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()

0 comments on commit 18ea490

Please sign in to comment.