def metadata(self, default: str = None) -> Optional[str]: if concourse_context(): return json.load( open( os.path.join(self.path, ".git", "resource", "metadata.json"))) return default
def changed_files(self, default: str = None) -> Union[List[str], Optional[str]]: if concourse_context(): with open( os.path.join(self.path, ".git", "resource", "changed_files")) as f: lines = f.readlines() return [line.strip() for line in lines] return default
def __init__(self, name: str, uri: str, config: dict) -> None: self.name = name self.config = config self.uri = uri if concourse_context(): self.path = os.path.abspath(self.name) else: self.path = os.getenv("HOME", "") + "/workspace/" + os.path.splitext( os.path.basename(uri))[0]
def ref(self) -> str: if concourse_context(): with open(os.path.join(self.path, ".git/ref")) as f: return f.read().strip() try: return self.tag() except Exception: return subprocess.check_output( ["git", "rev-parse", "HEAD"], cwd=self.path).decode("utf-8").strip()
def tag(self, default: str = None) -> Optional[str]: if concourse_context(): with open(os.path.join(self.path, "tag")) as f: return f.read().strip() return default
def short_ref(self) -> str: if concourse_context(): with open(os.path.join(self.path, ".git/short_ref")) as f: return f.read().strip() return subprocess.check_output(["git", "rev-parse", "--short", "HEAD"], cwd=self.path).decode("utf-8").strip()
def version(self) -> str: if concourse_context(): with open(os.path.join(self.path, "version")) as f: return f.read().strip() return "0.0.1"
def digest(self) -> str: if concourse_context(): with open(os.path.join(self.path, "digest")) as f: return f.read().strip() return "latest"