forked from opensearch-project/opensearch-build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
component.py
36 lines (30 loc) · 1.17 KB
/
component.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# SPDX-License-Identifier: Apache-2.0
#
# The OpenSearch Contributors require contributions made to
# this file be licensed under the Apache-2.0 license or a
# compatible open source license.
import re
import subprocess
from typing import Any, List
from git.git_repository import GitRepository
from manifests.manifest import Manifest
class Component:
def __init__(self, name: str, repo: GitRepository, snapshot: bool = False, checks: List = []) -> None:
self.name = name
self.git_repo = repo
self.snapshot = snapshot
self.checks = checks
@classmethod
def branches(self, url: str) -> List[str]:
"""Return main or any x.y branches."""
branches = ["main"]
remote_branches = subprocess.check_output(f"git ls-remote {url} refs/heads/* | cut -f2 | cut -d/ -f3", shell=True).decode().split("\n")
branches.extend(filter(lambda b: re.match(r"[\d]+.[\dx]*", b), remote_branches))
return branches
def to_dict(self) -> Any:
return Manifest.compact({
"name": self.name,
"repository": self.git_repo.url,
"ref": self.git_repo.ref,
"checks": self.checks
})