in converter.py [0:0]
def build_gh_action(self, action, tag):
self.logger.log.info(f"Fetching Details on {action}")
gh_uri = f"https://api.github.com/repos/{action}"
tags = self.gh_fetch(f"{gh_uri}/git/refs/tags")
heads = self.gh_fetch(f"{gh_uri}/git/refs/heads")
if tags and heads:
nick = None
t = {}
self.logger.log.info(f"Parsing: {action}@{tag}")
if "*" in tag:
if len(tag.split()) > 1:
self.logger.log.info("Keeping globs around for now...")
sha = tag
# We need to keep the globs, don't set to HEAD
else:
# if globbed, set to hash of HEAD.
# self.logger.log.info("Pinning to the SHA of the current HEAD")
self.logger.log.info("Keeping globs around for now...")
#sha = max(tags, key=lambda x: x["ref"])["object"]["sha"]
sha = "*"
elif tag == "latest":
# set to the hash of 'refs/heads/latest'
self.logger.log.info("Pinning to the SHA of refs/heads/latest")
sha = [item for item in heads if item["ref"] == "refs/heads/latest"][0][
"object"
]["sha"]
elif len(tag) == 40:
# Lets pretend for now that any 40 character string is a SHA
# TODO Validate that the 40 character string is a valid SHA
self.logger.log.critical(
"Pretending that any 40 character string is a SHA..."
)
sha = tag
else:
# Check if the provided tag is valid, if so use it.
nick = tag
self.logger.log.info(f"Pinning to the SHA of refs/heads/{tag}")
sha = next(
(
item["object"]["sha"]
for item in tags
if item["ref"] == f"refs/tags/{tag}"
),
None,
)
if sha is None:
self.logger.log.error(
f"Tag: {tag} not found in https://api.github.com/repos/{action}/git/refs/tags"
)
self.logger.log.error(f"Skipping {action}@{tag}")
return None
# Expiration Date set as a GLOBAL
t[sha] = {"expires_at": f"{DEFAULT_EXPIRATION_DATE}"}
# TODO Don't keep globs
# Keep the globs for 6 months
if sha == "*":
t[sha]["keep"] = True
t[sha]["expires_at"] = DEFAULT_EXPIRATION_DATE
# TODO Don't keep tags
# Keep tags as nicknames for their associated version for 6 months
if nick:
t[nick] = {"expires_at": DEFAULT_EXPIRATION_DATE}
return t