From f67faf78aa8ebd3386764069378701b06db3d9fd Mon Sep 17 00:00:00 2001 From: Haroon Feisal Date: Mon, 25 Apr 2022 17:00:18 -0400 Subject: [PATCH] Added prototype for new feature. --- src/containerapp/azext_containerapp/_up_utils.py | 2 ++ src/containerapp/azext_containerapp/_utils.py | 1 + src/containerapp/azext_containerapp/custom.py | 13 ++++++------- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/containerapp/azext_containerapp/_up_utils.py b/src/containerapp/azext_containerapp/_up_utils.py index df9108250d4..727864f9b46 100644 --- a/src/containerapp/azext_containerapp/_up_utils.py +++ b/src/containerapp/azext_containerapp/_up_utils.py @@ -380,6 +380,8 @@ def _get_dockerfile_content_from_repo( # pylint: disable=inconsistent-return-st context_path = context_path or "." repo = repo_url_to_name(repo_url) r = g.get_repo(repo) + if not branch: + branch = r.default_branch files = r.get_contents(context_path, ref=branch) for f in files: if f.path == dockerfile or f.path.endswith(f"/{dockerfile}"): diff --git a/src/containerapp/azext_containerapp/_utils.py b/src/containerapp/azext_containerapp/_utils.py index 1965a3e40d5..2ee66b84801 100644 --- a/src/containerapp/azext_containerapp/_utils.py +++ b/src/containerapp/azext_containerapp/_utils.py @@ -189,6 +189,7 @@ def await_github_action(cmd, token, repo, branch, name, resource_group_name, tim animation.flush() animation.tick() animation.flush() + sleep(3) # adding sleep until there is a way of verifying index[0] is latest workflow run based on id/time runs = workflow.get_runs() while runs is None or runs.totalCount < 1: runs = workflow.get_runs() diff --git a/src/containerapp/azext_containerapp/custom.py b/src/containerapp/azext_containerapp/custom.py index 79406478b3d..1856b3b93a2 100644 --- a/src/containerapp/azext_containerapp/custom.py +++ b/src/containerapp/azext_containerapp/custom.py @@ -1043,6 +1043,8 @@ def _validate_github(repo, branch, token): if not github_repo.permissions.push or not github_repo.permissions.maintain: raise ValidationError("The token does not have appropriate access rights to repository {}.".format(repo)) try: + if not branch: + branch = github_repo.default_branch github_repo.get_branch(branch=branch) except GithubException as e: error_msg = "Encountered GitHub error when accessing {} branch in {} repo.".format(branch, repo) @@ -1059,7 +1061,7 @@ def _validate_github(repo, branch, token): if e.data and e.data['message']: error_msg += " Error: {}".format(e.data['message']) raise CLIInternalError(error_msg) from e - + return branch def create_or_update_github_action(cmd, name, @@ -1088,7 +1090,7 @@ def create_or_update_github_action(cmd, repo = repo_url_to_name(repo_url) repo_url = f"https://github.com/{repo}" # allow specifying repo as / without the full github url - _validate_github(repo, branch, token) + branch = _validate_github(repo, branch, token) source_control_info = None @@ -1102,10 +1104,7 @@ def create_or_update_github_action(cmd, source_control_info["properties"]["repoUrl"] = repo_url - if branch: - source_control_info["properties"]["branch"] = branch - if not source_control_info["properties"]["branch"]: - source_control_info["properties"]["branch"] = "main" + source_control_info["properties"]["branch"] = branch azure_credentials = None @@ -1995,7 +1994,7 @@ def containerapp_up(cmd, logs_key=None, repo=None, token=None, - branch="main", + branch=None, browse=False, context_path=None, service_principal_client_id=None,