2023-10-23 20:40:24 +00:00
|
|
|
import datetime as dt
|
|
|
|
from perceval.backends.core.git import Git
|
2023-10-19 16:46:00 +00:00
|
|
|
|
2023-10-23 20:40:24 +00:00
|
|
|
#globals
|
|
|
|
repo_dir = '/tmp/perceval.git'
|
2023-10-19 16:46:00 +00:00
|
|
|
|
2023-10-23 20:40:24 +00:00
|
|
|
#main function for all subsequent tasks using perceval
|
|
|
|
def main(vcs_path, begin_date):
|
|
|
|
perceval_info = {}
|
|
|
|
perceval_info['list_of_commits'] = get_perceval_log(vcs_path, begin_date)
|
|
|
|
perceval_info['age_of_project'] = get_repo_age(perceval_info['list_of_commits'] )
|
|
|
|
return perceval_info
|
|
|
|
|
|
|
|
|
|
|
|
# this is the primary function for getting the list of commits from perceval
|
|
|
|
def get_perceval_log(vcs_path, begin_date):
|
|
|
|
repo = Git(uri=vcs_path[0], gitpath=repo_dir)
|
|
|
|
# this is a temporary date_from, will need to be more inclusive in the future
|
|
|
|
fetched_commits = repo.fetch(from_date=begin_date)
|
|
|
|
return list(fetched_commits)
|
|
|
|
|
|
|
|
#this function is just to evaluate the repository age, as defined by Tamburri and used by van Meijel
|
|
|
|
def get_repo_age(all_commits):
|
|
|
|
first_commit = all_commits[0]
|
|
|
|
last_commit = all_commits[-1]
|
|
|
|
first_date = dt.datetime.strptime(first_commit['data']["CommitDate"], '%c %z')
|
|
|
|
last_date = dt.datetime.strptime(last_commit['data']["CommitDate"], '%c %z')
|
|
|
|
print(first_date)
|
|
|
|
print("---------------------")
|
|
|
|
print(last_date)
|
|
|
|
#project life, as defined in YOSHI, unit is days
|
|
|
|
project_life = last_date - first_date
|
|
|
|
print(project_life)
|
|
|
|
return project_life
|
2023-10-19 16:46:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
manifest = '../kaylea_dissertation/lifecycle/package_metadata/woof_manifest.yaml'
|
|
|
|
main(manifest)
|