Skip to content

Commit

Permalink
Use sha instead of date to match patches with deploys
Browse files Browse the repository at this point in the history
  • Loading branch information
Neppord committed Jan 25, 2019
1 parent f9a53c9 commit 3f70c54
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 36 deletions.
17 changes: 5 additions & 12 deletions calculate_four_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import docopt

from git_metrics_release_lead_time import commit_author_time_tag_author_time_and_from_to_tag_name, \
fetch_tags_and_author_dates, fetch_tags_and_commit_dates
fetch_tags_and_author_dates, fetch_tags_and_sha
from process import mk_run
from recovery_time import Deployment, find_is_patch, find_outages

Expand Down Expand Up @@ -69,24 +69,17 @@ def main():

def calculate_MTTR(path_to_git_repo, deploy_pattern, patch_pattern, start_date):
run = mk_run(path_to_git_repo)
match_deploy = partial(fnmatch, pat=deploy_pattern)
deploy_tags_author_date = fetch_tags_and_author_dates(
run,
partial(fnmatch, pat=deploy_pattern),
match_deploy,
start_date,
)
deploy_tags_commit_date = dict(fetch_tags_and_commit_dates(
run,
partial(fnmatch, pat=deploy_pattern),
start_date,
))
deploy_tags_commit_date = dict(fetch_tags_and_sha(run, match_deploy))
patch_dates = set(
date
for _tag, date
in fetch_tags_and_commit_dates(
run,
partial(fnmatch, pat=patch_pattern),
start_date,
)
in fetch_tags_and_sha(run, partial(fnmatch, pat=patch_pattern))
)
deployments = []
for deploy_tag, deploy_date in deploy_tags_author_date:
Expand Down
25 changes: 2 additions & 23 deletions git_metrics_release_lead_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@
sort='taggerdate'
)

TAGS_WITH_COMMIT_DATE_CMD = for_each_ref(
'refs/tags/**',
format='%(refname:short) %(*authordate:unix)',
)

TAGS_WITH_COMMIT_SHA_CMD = for_each_ref(
'refs/tags/**',
format='%(refname:short) %(*objectname)',
Expand All @@ -31,12 +26,6 @@ def tags_with_author_date(run) -> Iterable[Tuple[str, int]]:
return parse_tags_with_date(stdout)


def tags_with_commit_date(run) -> Iterable[Tuple[str, int]]:
proc = run(TAGS_WITH_COMMIT_DATE_CMD)
stdout = proc_to_stdout(proc)
return parse_tags_with_date(stdout)


def parse_tags_with_date(lines: Iterable[str]) -> Iterable[Tuple[str, int]]:
return ((tag_and_maybe_date[0], int(tag_and_maybe_date[1])) for tag_and_maybe_date in columns(lines) if len(tag_and_maybe_date) > 1)

Expand Down Expand Up @@ -77,27 +66,17 @@ def fetch_tags_and_author_dates(run, match_tag, earliest_date=0):
return filtered_on_tags_date


def fetch_tags_and_sha(run):
def fetch_tags_and_sha(run, match_tag):
proc = run(TAGS_WITH_COMMIT_SHA_CMD)
stdout = proc_to_stdout(proc)
return (
(tag_and_maybe_sha[0], tag_and_maybe_sha[1])
for tag_and_maybe_sha
in columns(stdout)
if len(tag_and_maybe_sha) > 1
if len(tag_and_maybe_sha) > 1 and match_tag(tag_and_maybe_sha[0])
)



def fetch_tags_and_commit_dates(run, match_tag, earliest_date=0):
tags_and_date = tags_with_commit_date(run)
filtered_on_tags_date = filter(
lambda p: match_tag(p[0]) and p[1] > earliest_date,
tags_and_date
)
return filtered_on_tags_date


def plot_release_lead_time_metrics(data):
import matplotlib.pyplot as plt
from pandas import DataFrame
Expand Down
2 changes: 1 addition & 1 deletion test_release_lead_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def test_fetch_tags_and_sha():
result = fetch_tags_and_sha(lambda _: stdout([
"annotated-tag sha",
"lightweight-tag"
]))
]), lambda _: True)
assert list(result) == [
("annotated-tag", "sha")
]

0 comments on commit 3f70c54

Please sign in to comment.