Skip to content

Commit c4d0b1b

Browse files
inishchithjgbarah
authored andcommitted
[graal] Add graal introduction and CoCom backend tutorial
Signed-off-by: inishchith <[email protected]>
1 parent c38dff1 commit c4d0b1b

2 files changed

Lines changed: 106 additions & 0 deletions

File tree

graal/cocom.md

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# Retrieving Code Complexity via CoCom Backend
2+
3+
- [CoCom](https://github.com/chaoss/grimoirelab-graal/blob/master/graal/backends/core/cocom.py) ( Code Complexity ) Backend based on supported languages and with the help of [Lizard](https://github.com/terryyin/lizard) retrieves various source code related analysis such as:
4+
- Cyclomatic Complexity and Average Cyclomatic Complexity
5+
- Lines of Code and Average Lines of Code
6+
- Number of functions in a module
7+
- Total number of tokens
8+
- ( and many more )
9+
10+
## Basic usage of the CoCom backend
11+
12+
Once you've successfully installed Graal, you can get started real quick with the command line interface as easy as -
13+
14+
```sh
15+
(graal) $ graal cocom --help
16+
```
17+
18+
**Note:** You can invoke other available backends in a similar way.
19+
20+
## Using Graal as a program
21+
22+
- Let's start our analysis with the host repository itself. As you can see the positional parameter is added with the repository url and `git-path` flag is used to define the path where the git repository will be cloned.
23+
24+
```sh
25+
(graal) $ graal cocom https://github.com/chaoss/grimoirelab-graal --git-path /tmp/graal-cocom
26+
[2019-03-27 21:32:03,719] - Starting the quest for the Graal.
27+
[2019-03-27 21:32:11,663] - Git worktree /tmp/worktrees/graal-cocom created!
28+
[2019-03-27 21:32:11,663] - Fetching commits: 'https://github.com/chaoss/grimoirelab-graal' git repository from 1970-01-01 00:00:00+00:00 to 2100-01-01 00:00:00+00:00; all branches
29+
[2019-03-27 21:32:13,276] - Git repository /tmp/graal-cocom checked out!
30+
...
31+
{
32+
"backend_name": "CoCom",
33+
"backend_version": "0.2.3",
34+
"category": "code_complexity",
35+
"data": {
36+
"Author": "Valerio Cosentino <[email protected]>",
37+
"AuthorDate": "Sun May 6 13:56:51 2018 +0200",
38+
"Commit": "Valerio Cosentino <[email protected]>",
39+
"CommitDate": "Sun May 6 13:56:51 2018 +0200",
40+
"analysis": [
41+
{
42+
"avg_ccn": 2.111111111111111,
43+
"avg_loc": 9.11111111111111,
44+
"avg_tokens": 64.0,
45+
"blanks": 48,
46+
"ccn": 19,
47+
"comments": 63,
48+
"ext": "py",
49+
"file_path": "graal/codecomplexity.py",
50+
"loc": 129,
51+
"num_funs": 9,
52+
"tokens": 786
53+
}
54+
],
55+
"commit": "a957488c9bd95e3b72a30611edc61496ee152430",
56+
"message": "[codecomplexity] Enable analysis with no file filtering\n\nThis patch allows to handle analysis without file filtering."
57+
},
58+
"graal_version": "0.1.0",
59+
"origin": "https://github.com/chaoss/grimoirelab-graal",
60+
"tag": "https://github.com/chaoss/grimoirelab-graal",
61+
"timestamp": 1553702540.824002,
62+
"updated_on": 1525607811.0,
63+
"uuid": "ce7c47568fd87100aff497dd7677b0736d85db1e"
64+
}
65+
...
66+
[2019-03-27 21:35:59,077] - Fetch process completed: 137 commits fetched
67+
[2019-03-27 21:35:59,089] - /tmp/worktrees/graal-cocom deleted!
68+
[2019-03-27 21:35:59,116] - Git worktree /tmp/worktrees/graal-cocom deleted!
69+
[2019-03-27 21:35:59,116] - Fetch process completed: 137 commits inspected
70+
[2019-03-27 21:35:59,117] - Quest completed.
71+
```
72+
73+
- In the above graal output, you can read one commit item obtained which contains "analysis" attribute under "data".
74+
75+
**Note:** Some of the intermediate output items are skipped for representational purposes.
76+
77+
## Using Graal as a Python script
78+
79+
- We can also use the backend provided by Graal in python scripts via importing the appropriate modules. Show below is using `cocom` backend in a python script. [ Example: [graal_cocom_1.py](./scripts/graal_cocom_1.py) ]
80+
81+
```python3
82+
#! /usr/bin/env python3
83+
from graal.backends.core.cocom import CoCom
84+
85+
# URL for the git repo to analyze
86+
repo_uri = "http://github.com/chaoss/grimoirelab-graal"
87+
88+
# directory where to mirror the repo
89+
repo_dir = "/tmp/graal-cocom"
90+
91+
# Cocom object initialization
92+
cc = CoCom(uri=repo_uri, git_path=repo_dir)
93+
94+
# fetch all commits
95+
commits = [commit for commit in cc.fetch()]
96+
```
97+
98+
- The above `commits` list contains commit items and can be used for further extraction of specific attributes.

graal/intro.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Graal
2+
3+
- [Graal](https://github.com/chaoss/grimoirelab-graal) [ Generic Repository AnALyzer ] with the help of Perceval's [Git backend](https://github.com/chaoss/grimoirelab-perceval/blob/master/perceval/backends/core/git.py) fetches commits from a Git repository and provides a mechanism to plug third party tools/libraries focused on source code analysis. As of now, Graal produces analysis related to code complexity, quality, dependencies, vulnerability and licensing. In this chapter, you will learn the basics of working with Graal, including how to retrieve source code related analysis with the help of some of it's backends.
4+
5+
- Before starting, ensure that you have Python3 ready, and the Graal module installed, as detailed in
6+
[Installing GrimoireLab Python modules](../basics/install.md).
7+
8+
**Note:** As of now, Graal is not integrated in Grimoirelab toolchain, it will soon be added to support source code related metrics.

0 commit comments

Comments
 (0)