You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+92-1Lines changed: 92 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,7 +24,7 @@ See more examples: [gitevo-examples](https://github.com/andrehora/gitevo-example
24
24
pip install gitevo
25
25
```
26
26
27
-
## Usage
27
+
## Usage via command-line
28
28
29
29
Analyzing the evolution of a Git repository:
30
30
@@ -80,3 +80,94 @@ options:
80
80
-m, --month Set to analyze commits by month.
81
81
-v, --version Show the GitEvo version.
82
82
```
83
+
84
+
## Defining Custom Metrics
85
+
86
+
GitEvo can be used to define custom code evolution metrics at the level of the concrete syntax tree (CST).
87
+
GitEvo provides three key classes that can be used in the scripts: `GitEvo`, `ParsedCommit`, and `ParsedFile`.
88
+
89
+
-`GitEvo` is the main class, the entry point to use the tool.
90
+
It receives as input the repository, file extension, date unit for analysis, and start/end year for analysis.
91
+
92
+
- Metrics are defined in functions decorated with `@evo.metric()`.
93
+
94
+
-`ParsedCommit` represents a parsed commit and contains (1) a list of `ParsedFile` and (2) a list of [`tree_sitter.Node`](https://tree-sitter.github.io/py-tree-sitter/classes/tree_sitter.Node.html).
95
+
96
+
-`ParsedFile` represents a parsed file in a commit, including properties as name, path, and tree-sitter nodes.
97
+
98
+
### Examples
99
+
100
+
#### Basic metrics
101
+
102
+
```python
103
+
from gitevo import GitEvo, ParsedCommit
104
+
105
+
remote ='https://github.com/pallets/flask'
106
+
evo = GitEvo(repo=remote, extension='.py')
107
+
108
+
@evo.metric('Lines of code (LOC)')
109
+
defloc(commit: ParsedCommit):
110
+
return commit.loc
111
+
112
+
@evo.metric('Python files')
113
+
defpython_files(commit: ParsedCommit):
114
+
returnlen(commit.parsed_files)
115
+
116
+
@evo.metric('Test files')
117
+
deftest_files(commit: ParsedCommit):
118
+
test_files = [f for f in commit.parsed_files if'test_'in f.name.lower()]
0 commit comments