def test_fetch_unknown(self):
        """Test whether commits are properly processed"""

        cc = CoCom('http://example.com', self.git_path, self.worktree_path)

        with self.assertRaises(GraalError):
            _ = cc.fetch(category="unknown")
    def test_initialization(self):
        """Test whether attributes are initializated"""

        cc = CoCom('http://example.com', self.git_path, self.worktree_path, tag='test')
        self.assertEqual(cc.uri, 'http://example.com')
        self.assertEqual(cc.gitpath, self.git_path)
        self.assertEqual(cc.worktreepath, os.path.join(self.worktree_path, os.path.split(cc.gitpath)[1]))
        self.assertEqual(cc.origin, 'http://example.com')
        self.assertEqual(cc.tag, 'test')

        cc = CoCom('http://example.com', self.git_path, self.worktree_path, details=True, tag='test')
        self.assertEqual(cc.uri, 'http://example.com')
        self.assertEqual(cc.gitpath, self.git_path)
        self.assertEqual(cc.worktreepath, os.path.join(self.worktree_path, os.path.split(cc.gitpath)[1]))
        self.assertEqual(cc.origin, 'http://example.com')
        self.assertEqual(cc.tag, 'test')

        # When tag is empty or None it will be set to the value in uri
        cc = CoCom('http://example.com', self.git_path, self.worktree_path)
        self.assertEqual(cc.origin, 'http://example.com')
        self.assertEqual(cc.tag, 'http://example.com')

        cc = CoCom('http://example.com', self.git_path, self.worktree_path)
        self.assertEqual(cc.origin, 'http://example.com')
        self.assertEqual(cc.tag, 'http://example.com')
    def test_fetch_lizard_repository(self):
        """Test whether commits are properly processed via repository level"""

        cc = CoCom('http://example.com', self.git_path, self.worktree_path)
        commits = [commit for commit in cc.fetch(category="code_complexity_lizard_repository")]

        self.assertEqual(len(commits), 6)
        self.assertFalse(os.path.exists(cc.worktreepath))

        for commit in commits:
            self.assertEqual(commit['backend_name'], 'CoCom')
            self.assertEqual(commit['category'], CATEGORY_COCOM_LIZARD_REPOSITORY)
            self.assertTrue('Author' in commit['data'])
            self.assertTrue('Commit' in commit['data'])
            self.assertFalse('files' in commit['data'])
            self.assertFalse('parents' in commit['data'])
            self.assertFalse('refs' in commit['data'])
    def test_fetch_lizard_file(self):
        """Test whether commits are properly processed via file level"""

        cc = CoCom('http://example.com', self.git_path, self.worktree_path, in_paths=['perceval/backends/core/github.py'])
        commits = [commit for commit in cc.fetch()]

        self.assertEqual(len(commits), 1)
        self.assertFalse(os.path.exists(cc.worktreepath))

        for commit in commits:
            self.assertEqual(commit['backend_name'], 'CoCom')
            self.assertEqual(commit['category'], CATEGORY_COCOM_LIZARD_FILE)
            self.assertEqual(commit['data']['analysis'][0]['file_path'],
                             'perceval/backends/core/github.py')
            self.assertTrue('Author' in commit['data'])
            self.assertTrue('Commit' in commit['data'])
            self.assertFalse('files' in commit['data'])
            self.assertFalse('parents' in commit['data'])
            self.assertFalse('refs' in commit['data'])
    def test_metadata_category(self):
        """Test metadata_category"""
        item = {
            "Author": "Nishchith Shetty <*****@*****.**>",
            "AuthorDate": "Tue Feb 26 22:06:31 2019 +0530",
            "Commit": "Nishchith Shetty <*****@*****.**>",
            "CommitDate": "Tue Feb 26 22:06:31 2019 +0530",
            "analysis": [],
            "analyzer": "lizard_file",
            "commit": "5866a479587e8b548b0cb2d591f3a3f5dab04443",
            "message": "[copyright] Update copyright dates"
        }
        self.assertEqual(CoCom.metadata_category(item),
                         CATEGORY_COCOM_LIZARD_FILE)

        item = {
            "Author": "Nishchith Shetty <*****@*****.**>",
            "AuthorDate": "Tue Feb 26 22:06:31 2019 +0530",
            "Commit": "Nishchith Shetty <*****@*****.**>",
            "CommitDate": "Tue Feb 26 22:06:31 2019 +0530",
            "analysis": [],
            "analyzer": "lizard_repository",
            "commit": "5866a479587e8b548b0cb2d591f3a3f5dab04443",
            "message": "[copyright] Update copyright dates"
        }
        self.assertEqual(CoCom.metadata_category(item),
                         CATEGORY_COCOM_LIZARD_REPOSITORY)

        item = {
            "Author": "Nishchith Shetty <*****@*****.**>",
            "AuthorDate": "Tue Feb 26 22:06:31 2019 +0530",
            "Commit": "Nishchith Shetty <*****@*****.**>",
            "CommitDate": "Tue Feb 26 22:06:31 2019 +0530",
            "analysis": [],
            "analyzer": "unknown",
            "commit": "5866a479587e8b548b0cb2d591f3a3f5dab04443",
            "message": "[copyright] Update copyright dates"
        }
        with self.assertRaises(GraalError):
            _ = CoCom.metadata_category(item)
    def test_fetch_analysis(self):
        """Test whether commits have properly set values"""

        cc = CoCom('http://example.com', self.git_path, self.worktree_path, details=True)
        commits = [commit for commit in cc.fetch()]

        self.assertEqual(len(commits), 6)
        self.assertFalse(os.path.exists(cc.worktreepath))

        deleted_file_commit = commits[5]

        self.assertEqual(deleted_file_commit['data']['analysis'][0]['file_path'],
                         'perceval/backends/graal.py')
        self.assertEqual(deleted_file_commit['data']['analysis'][0]['blanks'], None)
        self.assertEqual(deleted_file_commit['data']['analysis'][0]['comments'], None)
        self.assertEqual(deleted_file_commit['data']['analysis'][0]['loc'], None)
        self.assertEqual(deleted_file_commit['data']['analysis'][0]['ccn'], None)
        self.assertEqual(deleted_file_commit['data']['analysis'][0]['avg_ccn'], None)
        self.assertEqual(deleted_file_commit['data']['analysis'][0]['avg_loc'], None)
        self.assertEqual(deleted_file_commit['data']['analysis'][0]['avg_tokens'], None)
        self.assertEqual(deleted_file_commit['data']['analysis'][0]['num_funs'], None)
        self.assertEqual(deleted_file_commit['data']['analysis'][0]['tokens'], None)
        self.assertEqual(deleted_file_commit['data']['analysis'][0]['funs'], [])
Example #7
0
from graal.backends.core.cocom import CoCom, FileAnalyzer
from pprint import pprint
from datetime import datetime
import os

# URL for the git repo to analyze
REPOSITORY_URL = "http://github.com/inishchith/MeetInTheMiddle"

# directory where to mirror the repo
REPO_DIR = "MeetInTheMiddle"

# Cocom object initialization
cocom = CoCom(uri=REPOSITORY_URL, git_path=REPO_DIR)

from_date = datetime(2018, 12, 12)
to_date = datetime(2018, 12, 30)

# fetch all commits within range from_date <= date <= to_date
# uses perceval backend to fetch commits and performs analysis on the file present in worktreepath
commits = [
    commit for commit in cocom.fetch(from_date=from_date, to_date=to_date)
]

n_commits = len(commits)
print("Number of commits: ", n_commits)

first_commit = commits[0]
pprint(first_commit)
print(first_commit['data']['Author'])
print(first_commit['data']['CommitDate'])
print(first_commit['data']['message'])
Example #8
0
#! /usr/bin/env python3
from graal.backends.core.cocom import CoCom

# URL for the git repo to analyze
repo_uri = "http://github.com/chaoss/grimoirelab-graal"

# directory where to mirror the repo
repo_dir = "/tmp/graal-cocom"

# Cocom object initialization
cc = CoCom(uri=repo_uri, git_path=repo_dir)

# fetch all commits
commits = [commit for commit in cc.fetch()]
Example #9
0
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# Author:
#      Sumit Kumar Jangir <*****@*****.**>

#! /usr/bin/env python3
from graal.backends.core.cocom import CoCom
from graal.graal import GraalCommand

# setting graal argument parser
parser = GraalCommand.setup_cmd_parser()

arg = [
    'https://github.com/sumitskj/Prajawalan2019.git', '--git-path',
    '/tmp/graal-cocom'
]

args = parser.parse(*arg)

# Cocom object initialization
cc = CoCom(uri=args.uri, git_path=args.git_path)

# fetch all commits
for com in cc.fetch():
    print(com['data']['CommitDate'])