Skip to content

Commit

Permalink
Merge pull request #17 from fabianhe/dev
Browse files Browse the repository at this point in the history
Add JSONL output and stdin commits
  • Loading branch information
fabianhe authored May 10, 2021
2 parents ae4bbd5 + 028a6d9 commit f7265f9
Show file tree
Hide file tree
Showing 26 changed files with 818 additions and 312 deletions.
8 changes: 8 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,11 @@ repos:
rev: v0.812
hooks:
- id: mypy
- repo: local
hooks:
- id: typerdocs
name: Make typer docs
language: system
pass_filenames: false
always_run: true
entry: poetry run typer pyrepositoryminer.main utils docs --name pyrepositoryminer --output DOCS.md
104 changes: 104 additions & 0 deletions DOCS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# `pyrepositoryminer`

Efficient Repository Mining in Python.

**Usage**:

```console
$ pyrepositoryminer [OPTIONS] COMMAND [ARGS]...
```

**Options**:

* `--install-completion`: Install completion for the current shell.
* `--show-completion`: Show completion for the current shell, to copy it or customize the installation.
* `--help`: Show this message and exit.

**Commands**:

* `analyze`: Analyze commits of a repository.
* `branch`: Get the branches of a repository.
* `clone`: Clone a repository to a path.
* `commits`: Get the commit ids of a repository.

## `pyrepositoryminer analyze`

Analyze commits of a repository.

**Usage**:

```console
$ pyrepositoryminer analyze [OPTIONS] REPOSITORY [METRICS]:[complexity|filecount|halstead|halstead_total|linelength|loc|maintainability|nesting|raw]...
```

**Arguments**:

* `REPOSITORY`: [required]
* `[METRICS]:[complexity|filecount|halstead|halstead_total|linelength|loc|maintainability|nesting|raw]...`

**Options**:

* `--commits FILENAME`
* `--help`: Show this message and exit.

## `pyrepositoryminer branch`

Get the branches of a repository.

**Usage**:

```console
$ pyrepositoryminer branch [OPTIONS] PATH
```

**Arguments**:

* `PATH`: [required]

**Options**:

* `--local / --no-local`: [default: True]
* `--remote / --no-remote`: [default: True]
* `--help`: Show this message and exit.

## `pyrepositoryminer clone`

Clone a repository to a path.

**Usage**:

```console
$ pyrepositoryminer clone [OPTIONS] URL PATH
```

**Arguments**:

* `URL`: [required]
* `PATH`: [required]

**Options**:

* `--help`: Show this message and exit.

## `pyrepositoryminer commits`

Get the commit ids of a repository.

**Usage**:

```console
$ pyrepositoryminer commits [OPTIONS] REPOSITORY
```

**Arguments**:

* `REPOSITORY`: [required]

**Options**:

* `--branches FILENAME`
* `--simplify-first-parent / --no-simplify-first-parent`: [default: True]
* `--drop-duplicates / --no-drop-duplicates`: [default: False]
* `--sort [topological|time]`
* `--sort-reverse / --no-sort-reverse`: [default: False]
* `--help`: Show this message and exit.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# pyrepositoryminer

[![CI workflow](https://github.com/fabianhe/pyrepositoryminer/actions/workflows/test.yaml/badge.svg)](https://github.com/fabianhe/pyrepositoryminer/actions/workflows/test.yaml)
![PyPI](https://img.shields.io/pypi/v/pyrepositoryminer?color=%23000)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)

Efficient Repository Mining in Python
Expand Down
55 changes: 54 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[tool.poetry]
name = "pyrepositoryminer"
version = "0.1.0"
version = "0.2.0"
description = "Efficient Repository Mining in Python"
license = "GPL-3.0-or-later"
authors = ["Fabian Heseding <[email protected]>"]
readme = "README.md"
homepage = "https://github.com/fabianhe/pyrepositoryminer"
repository = "https://github.com/fabianhe/pyrepositoryminer"
documentation = "https://github.com/fabianhe/pyrepositoryminer"
documentation = "https://github.com/fabianhe/pyrepositoryminer/blob/master/DOCS.md"

[tool.poetry.scripts]
pyrepositoryminer = "pyrepositoryminer.main:app"
Expand All @@ -25,6 +25,7 @@ mypy = "^0.812"
flake8 = "^3.9.1"
isort = "^5.8.0"
pre-commit = "^2.12.1"
typer-cli = "^0.0.11"

[build-system]
requires = ["poetry-core>=1.0.0"]
Expand Down
2 changes: 1 addition & 1 deletion pyrepositoryminer/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.1.0"
__version__ = "0.2.0"
74 changes: 74 additions & 0 deletions pyrepositoryminer/helper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
from json import dumps
from typing import Any, Iterable, List, TypedDict

from pygit2 import Commit, Signature


class Metric(TypedDict):
name: str
value: Any


class ObjectOutput(TypedDict):
id: str


class UnitOutput(ObjectOutput):
metrics: List[Metric]


class BlobOutput(ObjectOutput):
metrics: List[Metric]
units: List[UnitOutput]


class SignatureOutput(TypedDict):
email: str
name: str
time_offset: int
time: int


class CommitBase(ObjectOutput):
author: SignatureOutput
commit_time: int
commit_time_offset: int
committer: SignatureOutput
message: str
parent_ids: List[str]


class CommitOutput(CommitBase, total=False):
metrics: List[Metric]
blobs: List[BlobOutput]


def parse_signature(signature: Signature) -> SignatureOutput:
return SignatureOutput(
email=str(signature.email),
name=str(signature.name),
time_offset=int(signature.offset),
time=int(signature.time),
)


def parse_commit(
commit: Commit,
metrics: Iterable[Metric],
blobs: Iterable[BlobOutput],
) -> CommitOutput:
return CommitOutput(
id=str(commit.id),
author=parse_signature(commit.author),
commit_time=int(commit.commit_time),
commit_time_offset=int(commit.commit_time_offset),
committer=parse_signature(commit.committer),
message=str(commit.message),
parent_ids=[str(id) for id in commit.parent_ids],
metrics=list(metrics),
blobs=list(blobs),
)


def format_output(output: CommitOutput) -> str:
return dumps(output, separators=(",", ":"), indent=None)
Loading

0 comments on commit f7265f9

Please sign in to comment.