Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 4 additions & 28 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ jobs:
runs-on: ubuntu-latest
env:
GITHUB_EVENT_NAME: ${{ github.event_name }}
GITHUB_TOKEN: ${{ secrets.LAMIN_BUILD_DOCS }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
python: "3.12"
group: ["unit", "docs"]
group: ["docs"]
timeout-minutes: 15

steps:
Expand All @@ -28,34 +29,9 @@ jobs:
with:
python-version: ${{ matrix.python }}
- run: pip install git+https://github.com/laminlabs/laminci
- run: uv pip install --system git+https://github.com/laminlabs/lndocs
- uses: actions/cache@v4
with:
path: ~/.cache/pre-commit
key: pre-commit-${{ runner.os }}-${{ hashFiles('.pre-commit-config.yaml') }}
- name: Run lint
if: matrix.group == 'unit'
run: nox -s lint
- name: Run build
if: ${{ !(matrix.group == 'docs' && github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository) }}
run: nox -s "build(group='${{ matrix.group }}')"
- uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
- uses: cloudflare/wrangler-action@v3
if: ${{ !(matrix.group == 'docs' && github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository) }}
id: cloudflare
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: 472bdad691b4483dea759eadb37110bd
command: pages deploy "_build/html" --project-name=PROJECTNAME
gitHubToken: ${{ secrets.GITHUB_TOKEN }}
- uses: edumserrano/find-create-or-update-comment@v2
if: ${{ !(matrix.group == 'docs' && github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository) }}
with:
issue-number: ${{ github.event.pull_request.number }}
body-includes: "Deployment URL"
comment-author: "github-actions[bot]"
body: |
Deployment URL: ${{ steps.cloudflare.outputs.deployment-url }}
edit-mode: replace
- run: nox -s lint
- run: nox -s build
20 changes: 17 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# ghcontribs: Simple analytics for GitHub contributions across an organization
# githubcontribs: Simple analytics for GitHub contributions across an organization

## Contributing
Install:

Please run `pre-commit install` and `gitmoji -i` on the CLI before starting to work on this repository!
```bash
pip install githubcontribs
```

Quickstart:

```python
import githubcontribs
fetcher = githubcontribs.Fetcher("laminlabs")
df = fetcher.run("lamindb")
df.head()
#> Dataframe of contributions
```

Contributing: Please run `pre-commit install` and `gitmoji -i` on the CLI before starting to work on this repository!
7 changes: 0 additions & 7 deletions docs/guide.md

This file was deleted.

13 changes: 0 additions & 13 deletions docs/index.md

This file was deleted.

40 changes: 7 additions & 33 deletions docs/quickstart.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,43 +15,17 @@
"metadata": {},
"outputs": [],
"source": [
"from ghcontribs import ExampleClass, example_function"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "fa758625-efb0-4047-9a03-aa534bf6f78e",
"metadata": {},
"outputs": [],
"source": [
"example_function(\"A\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ad22eec0-8f75-4e0b-a132-8a43ccb09b37",
"metadata": {},
"outputs": [],
"source": [
"ex = ExampleClass(1)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8bf01623-742e-425a-973d-132fc61c3d9c",
"metadata": {},
"outputs": [],
"source": [
"assert ex.bar() == \"hello\""
"import githubcontribs\n",
"\n",
"fetcher = githubcontribs.Fetcher(\"laminlabs\")\n",
"df = fetcher.run(\"lamindb\")\n",
"df.head()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "py312",
"language": "python",
"name": "python3"
},
Expand All @@ -65,7 +39,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.12"
"version": "3.12.8"
}
},
"nbformat": 4,
Expand Down
5 changes: 0 additions & 5 deletions docs/reference.md

This file was deleted.

2 changes: 1 addition & 1 deletion githubcontribs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

__version__ = "0.0.1" # denote a pre-release for 0.1.0 with 0.1rc1

from ._core import GitHubContribs
from ._fetcher import Fetcher
28 changes: 18 additions & 10 deletions githubcontribs/_core.py → githubcontribs/_fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,27 @@
from dotenv import load_dotenv


class GitHubContribs:
class Fetcher:
"""Fetch GitHub contributions (commits, issues, PRs) for a given organization.

Usage::

fetcher = Fetcher(org_name="my-org")
df = contribs.fetch()
"""

def __init__(self, org_name: str, token: str = None):
"""Init.

Args:
org_name (str): Name of the GitHub organization
token (str): GitHub personal access token
org_name: Name of the GitHub organization.
token: GitHub personal access token. Read from `GITHUB_TOKEN` env var if `None`. Loads `.env` from the current working directory.
"""
load_dotenv()
token = token or os.getenv("GITHUB_TOKEN")
if token is None:
print(
"Warning: No GitHub token provided. Only public repositories will be accessible, and rate limits may apply."
raise ValueError(
"No GitHub token provided. Set env variable `GITHUB_TOKEN`, e.g. in `.env` in the current working directory."
)

self.org_name = org_name
Expand All @@ -49,7 +57,7 @@ def __init__(self, org_name: str, token: str = None):
self.session.mount("https://", adapter)
self.session.headers.update(self.headers)

def _get_contribs_as_dicts(
def _fetch_contribs_as_dicts(
self, repo_name: str, start_date: str | datetime | None = None
) -> tuple[list[dict], list[dict], list[dict]]:
"""Get commits, issues, and PRs for a specific repository since start_date as dicts."""
Expand Down Expand Up @@ -98,11 +106,11 @@ def paginate_results(endpoint: str) -> list[dict]:

return commits, issues, prs

def _get_contribs_per_repo(
def _fetch_contribs_per_repo(
self, repo_name: str, start_date: str | None = None
) -> pd.DataFrame:
"""Get commits, issues, and PRs for a specific repository since start_date as dataframes."""
commits, issues, prs = self._get_contribs_as_dicts(repo_name, start_date)
commits, issues, prs = self._fetch_contribs_as_dicts(repo_name, start_date)

data = []

Expand Down Expand Up @@ -152,7 +160,7 @@ def _get_contribs_per_repo(

return pd.DataFrame(data)

def get_contribs(
def run(
self, repo_names: str | list[str], *, start_date: str | None = None
) -> pd.DataFrame:
"""Get commits, issues, and PRs for all or specific repositories since start_date as a dataframe.
Expand All @@ -166,7 +174,7 @@ def get_contribs(

contribs = pd.DataFrame()
for repo_name in repo_names:
repo_contribs = self._get_contribs_per_repo(repo_name, start_date)
repo_contribs = self._fetch_contribs_per_repo(repo_name, start_date)
contribs = pd.concat([contribs, repo_contribs], ignore_index=True)

return contribs
12 changes: 3 additions & 9 deletions noxfile.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import nox
from laminci.nox import build_docs, login_testuser1, run_pre_commit, run_pytest
from laminci.nox import run_pre_commit, run_pytest

# we'd like to aggregate coverage information across sessions
# and for this the code needs to be located in the same
Expand All @@ -14,12 +14,6 @@ def lint(session: nox.Session) -> None:


@nox.session()
@nox.parametrize("group", ["unit", "docs"])
def build(session, group):
def build(session):
session.run(*"uv pip install --system -e .[dev]".split())
login_testuser1(session)

if group == "unit":
run_pytest(session)
elif group == "docs":
build_docs(session, strict=True)
run_pytest(session)
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ authors = [{name = "Lamin Labs", email = "open-source@lamin.ai"}]
readme = "README.md"
dynamic = ["version", "description"]
dependencies = [
"lamindb",
"pandas",
"requests",
"dotenv",
]

[project.urls]
Expand Down
7 changes: 0 additions & 7 deletions tests/test_base.py

This file was deleted.

Loading