def analyze(path, year, out): repositories = discover_repositories(os.path.expanduser(path)) logs = [] for repo in repositories: logs += generate_git_log(repo) log_by_year = sort_by_year(logs) max_commits = [] for y in log_by_year: data = process_log(log_by_year[y], y) max_commits.append(data['max_commits']) if not year: year = y else: year = int(year) global_max = max(max_commits) processed_logs = process_log(log_by_year[year], year) logger.info('Generating report for year {}'.format(year)) if out: with open(out, 'w') as fout: make_svg_report(processed_logs, global_max, fout) else: make_svg_report(processed_logs, global_max)
def generate_graph(json_input, year, email): """Generates an annual commit graph in .svg format.""" gitlogs = json.loads(json_input.read()) gitlogs = [(x, y, parse_datetime(z)) for x, y, z in gitlogs] gitlogs_by_year = sort_by_year(gitlogs) annual_data = {} for y, l in gitlogs_by_year.items(): annual_data[y] = get_annual_data(l, y, email) global_max = max([x['max_commits'] for x in annual_data.values()]) log.info('Generating report for year {}', year) make_svg_report(annual_data[year], global_max)
def test_sort_by_year(): """Ensures sort_by_year() works as intended.""" # Extract logs for the current repository logs = generate_git_log('.') sorted_logs = sort_by_year(logs) years = sorted_logs.keys() assert 2012 not in years assert 2013 in years assert 2014 not in years assert 2015 in years for year in (2013, 2015): for row in sorted_logs[year]: validate_log_row(row)