-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from fabianhe/dev
Add JSONL output and stdin commits
- Loading branch information
Showing
26 changed files
with
818 additions
and
312 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
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,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. |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,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" | ||
|
@@ -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"] | ||
|
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 +1 @@ | ||
__version__ = "0.1.0" | ||
__version__ = "0.2.0" |
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,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) |
Oops, something went wrong.