def get_git_shas_for_service(service, deploy_groups, soa_dir): """Returns a dictionary of 2-tuples of the form (timestamp, deploy_group) for each deploy sha""" if service is None: return [] git_url = get_git_url(service=service, soa_dir=soa_dir) all_deploy_groups = list_deploy_groups( service=service, soa_dir=soa_dir, ) deploy_groups, _ = validate_given_deploy_groups(all_deploy_groups, deploy_groups) previously_deployed_shas = {} for ref, sha in list_remote_refs(git_url).items(): regex_match = extract_tags(ref) try: deploy_group = regex_match['deploy_group'] tstamp = regex_match['tstamp'] except KeyError: pass else: # Now we filter and dedup by picking the most recent sha for a deploy group # Note that all strings are greater than '' if deploy_group in deploy_groups: tstamp_so_far = previously_deployed_shas.get(sha, ('all', ''))[1] if tstamp > tstamp_so_far: previously_deployed_shas[sha] = (tstamp, deploy_group) return previously_deployed_shas
def get_versions_for_service( service: str, deploy_groups: Collection[str], soa_dir: str) -> Mapping[DeploymentVersion, Tuple[str, str]]: """Returns a dictionary of 2-tuples of the form (timestamp, deploy_group) for each version tuple of (deploy sha, image_version)""" if service is None: return {} git_url = get_git_url(service=service, soa_dir=soa_dir) all_deploy_groups = list_deploy_groups(service=service, soa_dir=soa_dir) deploy_groups, _ = validate_given_deploy_groups(all_deploy_groups, deploy_groups) previously_deployed_versions: Dict[DeploymentVersion, Tuple[str, str]] = {} for ref, sha in list_remote_refs(git_url).items(): regex_match = extract_tags(ref) try: deploy_group = regex_match["deploy_group"] tstamp = regex_match["tstamp"] image_version = regex_match["image_version"] except KeyError: pass else: # Now we filter and dedup by picking the most recent sha for a deploy group # Note that all strings are greater than '' if deploy_group in deploy_groups: version = DeploymentVersion(sha=sha, image_version=image_version) tstamp_so_far = previously_deployed_versions.get( version, ("all", ""))[1] if tstamp > tstamp_so_far: previously_deployed_versions[version] = (tstamp, deploy_group) return previously_deployed_versions
def get_git_shas_for_service(service, deploy_groups, soa_dir): """Returns a list of 2-tuples of the form (sha, timestamp) for each deploy tag in a service's git repository""" if service is None: return [] git_url = get_git_url(service=service, soa_dir=soa_dir) all_deploy_groups = { config.get_deploy_group() for config in get_instance_config_for_service( service=service, soa_dir=soa_dir, ) } deploy_groups, _ = validate_given_deploy_groups(all_deploy_groups, deploy_groups) previously_deployed_shas = {} for ref, sha in list_remote_refs(git_url).items(): regex_match = extract_tags(ref) try: deploy_group = regex_match['deploy_group'] tstamp = regex_match['tstamp'] except KeyError: pass else: # note that all strings are greater than '' if deploy_group in deploy_groups and tstamp > previously_deployed_shas.get( sha, ''): previously_deployed_shas[sha] = tstamp return previously_deployed_shas.items()
def get_git_shas_for_service(service, deploy_groups, soa_dir): """Returns a dictionary of 2-tuples of the form (timestamp, deploy_group) for each deploy sha""" if service is None: return [] git_url = get_git_url(service=service, soa_dir=soa_dir) all_deploy_groups = list_deploy_groups( service=service, soa_dir=soa_dir, ) deploy_groups, _ = validate_given_deploy_groups(all_deploy_groups, deploy_groups) previously_deployed_shas = {} for ref, sha in list_remote_refs(git_url).items(): regex_match = extract_tags(ref) try: deploy_group = regex_match['deploy_group'] tstamp = regex_match['tstamp'] except KeyError: pass else: # note that all strings are greater than '' if deploy_group in deploy_groups and tstamp > previously_deployed_shas.get(sha, ''): previously_deployed_shas[sha] = (tstamp, deploy_group) return previously_deployed_shas.items()
def get_git_shas_for_service(service, deploy_groups, soa_dir): """Returns a list of 2-tuples of the form (sha, timestamp) for each deploy tag in a service's git repository""" if service is None: return [] git_url = get_git_url(service=service, soa_dir=soa_dir) all_deploy_groups = {config.get_deploy_group() for config in get_instance_config_for_service( service=service, soa_dir=soa_dir, )} deploy_groups, _ = validate_given_deploy_groups(all_deploy_groups, deploy_groups) previously_deployed_shas = {} for ref, sha in list_remote_refs(git_url).items(): regex_match = extract_tags(ref) try: deploy_group = regex_match['deploy_group'] tstamp = regex_match['tstamp'] except KeyError: pass else: # note that all strings are greater than '' if deploy_group in deploy_groups and tstamp > previously_deployed_shas.get(sha, ''): previously_deployed_shas[sha] = tstamp return previously_deployed_shas.items()
def test_extract_tags(tag, expected_result): assert extract_tags(tag) == expected_result