Ejemplo n.º 1
0
def test_deletion_remotes():
    repos = [
        'https://github.com/ishepard/pydriller',
        'https://github.com/ishepard/pydriller'
    ]
    paths = set()
    for commit in Repository(path_to_repo=repos).traverse_commits():
        paths.add(commit.project_path)

    for path in paths:
        assert os.path.exists(path) is False
Ejemplo n.º 2
0
    def visualizar_commits(self):
        for commit in Repository(
                "C:\\Users\\Leandro César\\Documents\\Nova pasta\\junit4"
        ).traverse_commits():
            print('O commit de número {} foi modificado pelo autor {}, '
                  'e comitado por {} na data {}'.format(
                      commit.hash, commit.author.name, commit.committer.name,
                      commit.committer_date))

        botao = input("Pressione qualquer botao para sair")
        print("\x1b[2J\x1b[1;1H")

        pass
Ejemplo n.º 3
0
    def get_merge_commits(self, commit_hash: str) -> Set[str]:
        merge = set()
        repo_mining = Repository(single=commit_hash, path_to_repo=self.repository_path).traverse_commits()
        for commit in repo_mining:
            try:
                if commit.merge:
                    merge.add(commit.hash)
            except Exception as e:
                log.error(f'unable to analyze commit: {self.repository_path} {commit.hash}')

        if len(merge) > 0:
            log.info(f'merge commits count: {len(merge)}')

        return merge
Ejemplo n.º 4
0
 def dictionaryWithAllCommmits(self):
     dictionaryAux = {}
     for commit in Repository(self.repository).traverse_commits():
         commitAuthorNameFormatted = '{}'.format(commit.author.name)
         commitAuthorDateFormatted = '{}'.format(commit.author_date)
         listFilesModifiedInCommit = []
         for modification in commit.modified_files:
             itemMofied = '{}'.format(modification.filename)
             listFilesModifiedInCommit.append(itemMofied)
         dictionaryAux[commit.hash] = [
             commitAuthorNameFormatted, commitAuthorDateFormatted,
             listFilesModifiedInCommit
         ]
     return dictionaryAux
Ejemplo n.º 5
0
def determine_commits_in_period(repository, start_date, end_date):
    """Determine the commits that are made in the period from start_date to end_date."""

    production_code_commit_count = 0
    test_code_commit_count = 0
    number_of_commits = 0
    for commit in Repository(repository, since=start_date,
                             to=end_date).traverse_commits():
        if commit_contains_test_code(commit):
            test_code_commit_count = test_code_commit_count + 1
        if commit_contains_production_code(commit):
            production_code_commit_count = production_code_commit_count + 1
        number_of_commits = number_of_commits + 1
    return number_of_commits, production_code_commit_count, test_code_commit_count
Ejemplo n.º 6
0
 def save_commits_and_authors_in_json(self, user_id):
     list_of_commits = list()
     list_of_authors = list()
     for commit in Repository(self.repository).traverse_commits():
         list_of_commits.append(commit.hash)
         list_of_authors.append(commit.author.name)
     authors = set(list_of_authors)
     authors = list(authors)
     dict_commits = {}
     dict_commits[self.name] = list_of_commits
     Util.save_dictionary_in_json_file(self.name, user_id, dict_commits,
                                       'commits')
     dict_authors = {}
     dict_authors[self.name] = authors
     Util.save_dictionary_in_json_file(self.name, user_id, dict_authors,
                                       'authors')
Ejemplo n.º 7
0
    def visualizar_arquivo_especifico(self):

        caminho = "C:\\Users\\Leandro César\\Documents\\Nova pasta\\junit4"
        caminho_do_arquivo = input(
            "Cole o caminho a partir do diretório src: "
        )  #"\\src\\test\\java\\junit\\tests\\AllTests.java"

        for commit in Repository(caminho,
                                 filepath=caminho +
                                 caminho_do_arquivo).traverse_commits():
            print(commit.hash)

        botao = input("Pressione qualquer botao para sair")

        print("\x1b[2J\x1b[1;1H")

        pass
Ejemplo n.º 8
0
    def get_meta_changes(self, commit_hash: str, current_file: str) -> Set[str]:
        meta_changes = set()
        repo_mining = Repository(path_to_repo=self.repository_path, single=commit_hash).traverse_commits()
        for commit in repo_mining:
            show_str = self.repository.git.show(commit.hash, '--summary').splitlines()
            if show_str and self._is_git_mode_change(show_str, current_file):
                log.info(f'exclude meta-change (file mode change): {current_file} {commit.hash}')
                meta_changes.add(commit.hash)
            else:
                try:
                    for m in commit.modified_files:
                        if (current_file == m.new_path or current_file == m.old_path) and (m.change_type in self.change_types_to_ignore):
                            log.info(f'exclude meta-change ({m.change_type}): {current_file} {commit.hash}')
                            meta_changes.add(commit.hash)
                except Exception as e:
                    log.error(f'unable to analyze commit: {self.repository_path} {commit.hash}')

        return meta_changes
def get_java_method_metrics(files, project_path, version):
    # 获取测试java文件的所有文件名
    file_names = get_all_name_of_files(files)
    num_of_add_method = 0
    num_of_sub_method = 0
    num_of_modify_method = 0

    def is_in(name, names):
        for index in range(0, len(names)):
            if name in names[index]:
                return index
        return -1

    for commit in Repository(project_path, single=version).traverse_commits():
        for m in commit.modified_files:
            # 查看提交文件的文件名是否属于测试文件
            index = is_in(m.filename, file_names)
            if index != -1:
                changed_methods = []
                for method in m.changed_methods:
                    changed_methods.append(method.name)
                num_of_modify_method += len(list(set(changed_methods)))
                # 得到所有修改了的方法名
                all_methods = []
                for method in m.methods:
                    all_methods.append(method.name)
                all_methods_before = []
                for method in m.methods_before:
                    all_methods_before.append(method.name)
                all_methods, all_methods_before = method_filter(
                    file_names, all_methods, all_methods_before)
                # 确定连续修改多个行数的修改块的第一个大括号前的语句是否包含在这些方法名中
                add, sub = judge_add_or_delete_method(all_methods,
                                                      all_methods_before)
                num_of_add_method += add
                num_of_sub_method += sub

    return [
        num_of_add_method, num_of_sub_method,
        num_of_modify_method - num_of_add_method - num_of_sub_method
    ]
Ejemplo n.º 10
0
    def process(self, force=False) -> Tuple[int, int]:
        filters = {}
        if self.author_name:
            filters['only_authors'] = [
                self.author_name,
            ]

        commits = Repository(self.repo_url, **filters).traverse_commits()

        self.get_entries().delete()

        entries_to_create = []
        for commit in commits:
            entries_to_create.append(
                Entry(title=commit.msg,
                      description=commit.hash,
                      date_on_timeline=commit.committer_date.astimezone(
                          pytz.UTC),
                      schema='commit',
                      source=self.entry_source,
                      extra_attributes={
                          'hash': commit.hash,
                          'url': self.get_commit_url(commit),
                          'author': {
                              'email': commit.author.email,
                              'name': commit.author.name,
                          },
                          'changes': {
                              'files': commit.files,
                              'insertions': commit.insertions,
                              'deletions': commit.deletions,
                          },
                          'repo': {
                              'name': self.get_repo_name()
                              or commit.project_name,
                              'url': self.get_repo_url(),
                          },
                      }))
        Entry.objects.bulk_create(entries_to_create)
        return len(entries_to_create), 0
Ejemplo n.º 11
0
def filter_commits(repo, commits):
    rels = []
    for commit_sha in commits:
        # has java not test
        if not list(
                filter(lambda x: x.is_java and not x.is_test,
                       commits[commit_sha])):
            continue
        c = next(
            Repository(repo.working_dir, single=commit_sha).traverse_commits())
        committed = list(
            map(
                lambda f: CommittedFile(commit_sha, f.new_path, f.added_lines,
                                        f.deleted_lines, f),
                filter(lambda f: f.language_supported and f.new_path,
                       c.modified_files)))
        if not list(
                filter(lambda x: x.is_java and not x.is_test and x.is_relevant,
                       committed)):
            continue
        rels.append(commit_sha)
    return rels
Ejemplo n.º 12
0
def test_badly_formatted_repo_url():
    with pytest.raises(Exception):
        list(Repository(path_to_repo=set('repo')).traverse_commits())
Ejemplo n.º 13
0
from pydriller import Repository

repo = Repository('https://github.com/schleising/python-tests')

for commit in repo.traverse_commits():
    print(f'{commit.committer_date.date()} - {commit.msg}')
Ejemplo n.º 14
0
def test_no_url():
    with pytest.raises(Exception):
        list(Repository().traverse_commits())
Ejemplo n.º 15
0
def test_clone_repo_to_not_existing():
    with pytest.raises(Exception):
        list(
            Repository("https://github.com/ishepard/pydriller",
                       clone_repo_to="NOTEXISTINGDIR").traverse_commits())
Ejemplo n.º 16
0
def test_projectname_multiple_repos_remote():
    repos = ['https://github.com/ishepard/pydriller', 'test-repos/pydriller']
    for commit in Repository(path_to_repo=repos).traverse_commits():
        assert commit.project_name == 'pydriller'
Ejemplo n.º 17
0
def repo(request):
    return list(Repository(path_to_repo=request.param).traverse_commits())
Ejemplo n.º 18
0
 def get_raw_github_data(self) -> List[GitCommit]:
     """Override :func:`~Entity.get_raw_github_data`."""
     return Repository(self.repository.clone_url).traverse_commits()
def test_deleted_files():
    deleted_commits = list(
        Repository('https://github.com/ishepard/pydriller',
                   filepath='.bettercodehub.yml',
                   include_deleted_files=True).traverse_commits())
    assert len(deleted_commits) > 0
from pydriller import Repository

rm = Repository("https://github.com/avandeursen/dmm-test-repo")
for commit in rm.traverse_commits():
    print("| {} | {} | {} | {} | {} |".format(commit.msg, commit.dmm_unit_size,
                                              commit.dmm_unit_complexity,
                                              commit.dmm_unit_interfacing,
                                              commit.parents))

rm = Repository(
    'https://github.com/avandeursen/dmm-test-repo',
    single='d7d62972125b33cf6e4ffdcccab5e7aac1014d62').traverse_commits()
from pydriller import Repository

for commit in Repository(
        'https://github.com/williamsartijose/Trabalho-Cadastro-de-Aluno.git'
).traverse_commits():
    print(commit.hash)
    print(commit.msg)
    print(commit.author.name)
    print("\n")

    for file in commit.modified_files:
        print(file.filename, ' has changed')
    print("\n\n")
def test_malformed_url():
    with pytest.raises(MalformedUrl):
        list(Repository("https://badurl.git/").traverse_commits())
Ejemplo n.º 23
0
    args = parser.parse_args()

    user = args.user
    working_tree_dir = args.working_tree_dir
    start_date = args.start_date
    end_date = args.end_date

    print(f'Using git working directory: {working_tree_dir}')
    print(f'List of {user}\'s commits since {start_date.date().isoformat()}' +
          (f' to {end_date.date().isoformat()}:'
           if end_date is not None else ':'))
    commits = list(
        Repository(working_tree_dir,
                   since=start_date,
                   to=end_date,
                   only_no_merge=True,
                   only_authors=[user]).traverse_commits())
    for idx, commit in enumerate(commits):
        print('{}: {}'.format(idx, commit.msg))

    print(
        'Enter lists of lists of commit numbers in json format (for example: [[0, 1], [2, 3]]):'
    )
    commits_str = input()

    try:
        commits_idxs_lists = json.loads(commits_str)
    except Exception as exc:
        raise Exception('Input is not a valid json.') from exc
Ejemplo n.º 24
0
def main(args):
    kwargs = {}
    for param in args.keys():
        if not param in [
                "outputfolder", "repo", "HCTI_API_USER_ID", "HCTI_API_KEY"
        ]:
            if args[param]:
                kwargs[param] = args[param]

    commits = []

    hti = Html2Image(output_path=args['outputfolder'])

    for commit in Repository(args['repo'], **kwargs).traverse_commits():
        print(commit.author.name, commit.msg)
        newcommit = {
            "author": commit.author.name,
            "msg": commit.msg,
            "date": commit.author_date,
            "modifications": []
        }

        if hasattr(commit, "modified_files"):
            for m in commit.modified_files:
                newmod = {
                    "filename": m.filename,
                    "change_type": m.change_type.name,
                    #"source_code":m.source_code
                    "hlcode": "",
                    "images": []
                }

                print(
                    m.change_type.name,
                    " modified {}".format(m.filename),
                )

                if m.filename.lower().endswith(
                    ('.png', '.jpg', '.jpeg', 'gif')) == False:
                    fragment = None
                    if m.change_type.name == "ADD":
                        lexer = guess_lexer(m.source_code)
                        fragment = highlight(
                            m.source_code, lexer,
                            HtmlFormatter(wrapcode=True, linenos=True))
                        newmod["hlcode"] = fragment
                        newmod["images"].append(
                            makeFragmentImage(fragment, hti, args))

                    if m.change_type.name == "MODIFY":
                        lexer = guess_lexer(m.source_code)
                        #print (m.changed_methods)
                        lines = str.splitlines(m.source_code)

                        for c in m.changed_methods:
                            code = "\n".join(lines[c.__dict__['start_line'] -
                                                   1:c.__dict__['start_line'] +
                                                   c.__dict__['nloc']])
                            fragment = highlight(
                                m.source_code, lexer,
                                HtmlFormatter(wrapcode=True, linenos=True))
                            newmod[
                                "hlcode"] += "<br /><br />" + fragment  #linenostart=c.__dict__['start_line'],wrapcode=True,linenos=True))
                            newmod["images"].append(
                                makeFragmentImage(fragment, hti, args))
                            #print(code)
                            #print(newmod["hlcode"])

                newcommit["modifications"].append(newmod)
        commits.append(newcommit)

    if not exists(args['outputfolder']):
        os.makedirs(args['outputfolder'])

    outputfile = os.path.join(args['outputfolder'], "index.html")
    of = open(outputfile, "w")

    template = env.get_template('pretty.html')

    content = {"commits": commits}
    output = template.render(content)
    #print(output)
    of.write(output)
    of.close()
Ejemplo n.º 25
0
def repo_to(request):
    path, to = request.param
    return list(Repository(path_to_repo=path, to=to).traverse_commits())
Ejemplo n.º 26
0
from pydriller import Repository
import os
import datetime
os.system("cp examples/speedtest.py examples/speedtest2.py"
          )  # the file has to be outside of git
for idx, commit in enumerate(
        Repository('.', from_tag="v0.6.0").traverse_commits()):
    name = commit.msg.replace('\n', ' ').replace('\r', ' ')
    print(idx, commit.hash, name)

for commit in Repository('.', from_tag="v0.6.0").traverse_commits():

    name = commit.msg.replace('\n', ' ').replace('\r', ' ')
    print(commit.hash, name)

    os.system(f"git checkout {commit.hash}; rm -rf build; ")
    print("\n\n--------------------\n\n")
    ret = os.system("python -m pip install .")
    print(ret)

    if ret != 0:
        print("build failed!!!!")
        print("build failed!!!!")
        print("build failed!!!!")
        print("build failed!!!!")
        continue

    os.system(f'python examples/speedtest2.py -n "{name}" -d 4 -t 1')
    os.system(f'python examples/speedtest2.py -n "{name}" -d 64 -t 1')
    os.system(f'python examples/speedtest2.py -n "{name}" -d 128 -t 1')
    os.system(f'python examples/speedtest2.py -n "{name}" -d 4 -t 24')
Ejemplo n.º 27
0
from pydriller import Repository

url = 'C:\\Users\\Leandro César\\eclipse-workspace\\Analise_Git\\Junit4'

for commit in Repository(
        url,
        filepath=
        'C:\\Users\\Leandro César\\eclipse-workspace\\Analise_Git\\Junit4\\src\\test\\java\\junit\\samples\\AllTests.java'
).traverse_commits():
    print(commit.hash)
Ejemplo n.º 28
0
from pydriller import Repository

for commit in Repository(
        'C:\\Users\\Leandro César\\eclipse-workspace\\Analise_Git\\Junit4'
).traverse_commits():
    print('The commit {} has been modified by {}, '
          'committed by {} in date {}'.format(commit.hash, commit.author.name,
                                              commit.committer.name,
                                              commit.committer_date))
Ejemplo n.º 29
0
        new_path = os.path.normpath(os.path.join(path, '..'))
        if new_path != path:
            path = new_path
        else:
            return None

    return None


if __name__ == '__main__':
    current_repo()

from datetime import datetime

if __name__ == '__main__':
    book_miner = Repository(current_repo(), to=datetime(2020, 10, 1))

DEBUGGINGBOOK_REMOTE_REPO = 'https://github.com/uds-se/debuggingbook.git'
# book_miner = Repository(DEBUGGINGBOOK_REMOTE_REPO)

if __name__ == '__main__':
    if 'CI' in os.environ:
        # The CI git clone is shallow, so access full repo remotely
        book_miner = Repository(DEBUGGINGBOOK_REMOTE_REPO,
                                to=datetime(2020, 10, 1))

if __name__ == '__main__':
    book_commits = book_miner.traverse_commits()
    book_first_commit = next(book_commits)

if __name__ == '__main__':