Skip to content

Commit

Permalink
Fix latest on stabilisation branch
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrunner committed Feb 11, 2022
1 parent 83847e8 commit fbd7b96
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
30 changes: 17 additions & 13 deletions c2cciutils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,22 @@ def merge(default_config: Any, config: Any) -> Any:
return config


def get_master_branch(repo: List[str]) -> Tuple[str, bool]:
"""Get the name of the master branch."""
master_branch = "master"
success = False
try:
default_branch_json = graphql(
"default_branch.graphql", {"name": repo[1], "owner": repo[0]}, default=False
)
success = default_branch_json is not False
master_branch = default_branch_json["repository"]["defaultBranchRef"]["name"] if success else "master"
except RuntimeError as runtime_error:
print(runtime_error)
print("Failback to master")
return master_branch, success


def get_config() -> c2cciutils.configuration.Configuration:
"""
Get the configuration, with project and autodetections.
Expand Down Expand Up @@ -109,19 +125,7 @@ def get_config() -> c2cciutils.configuration.Configuration:

repository = get_repository()
repo = repository.split("/")
master_branch = "master"
credentials = False
try:
default_branch_json = graphql(
"default_branch.graphql", {"name": repo[1], "owner": repo[0]}, default=False
)
credentials = default_branch_json is not False
master_branch = (
default_branch_json["repository"]["defaultBranchRef"]["name"] if credentials else "master"
)
except RuntimeError as runtime_error:
print(runtime_error)
print("Failback to master")
master_branch, credentials = get_master_branch(repo)

merge(
{
Expand Down
13 changes: 9 additions & 4 deletions c2cciutils/scripts/publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,14 @@ def main() -> None:
)
if docker_config:
latest = False
if os.path.exists("SECURITY.md") and docker_config["latest"] is True:
with open("SECURITY.md", encoding="utf-8") as security_file:
security = c2cciutils.security.Security(security_file.read())
repository = c2cciutils.get_repository()
full_repo = repository.split("/")
master_branch, _ = c2cciutils.get_master_branch(full_repo)
security_response = requests.get(
f"https://raw.githubusercontent.com/camptocamp/c2cciutils/{master_branch}/SECURITY.md"
)
if security_response.ok and docker_config["latest"] is True:
security = c2cciutils.security.Security(security_response.text)
version_index = security.headers.index("Version")
latest = security.data[-1][version_index] == version

Expand Down Expand Up @@ -223,7 +228,7 @@ def main() -> None:
with tarfile.open(fileobj=response.raw, mode="r:gz") as file:
file.extractall(path=os.path.expanduser("~/.local/bin"))

owner, repo = c2cciutils.get_repository().split("/")
owner, repo = full_repo.split("/")
commit_sha = (
subprocess.run(["git", "rev-parse", "HEAD"], check=True, stdout=subprocess.PIPE)
.stdout.strip()
Expand Down

0 comments on commit fbd7b96

Please sign in to comment.