Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Github repo's default branch for up and github actions #98

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/containerapp/azext_containerapp/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def load_arguments(self, _):
with self.argument_context('containerapp github-action add') as c:
c.argument('repo_url', help='The GitHub repository to which the workflow file will be added. In the format: https://github.com/<owner>/<repository-name>')
c.argument('token', help='A Personal Access Token with write access to the specified repository. For more information: https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line')
c.argument('branch', options_list=['--branch', '-b'], help='The branch of the GitHub repo. Defaults to "main" if not specified.')
c.argument('branch', options_list=['--branch', '-b'], help='The branch of the Github repo. Assumed to be the Github repo\'s default branch if not specified.')
c.argument('login_with_github', help='Interactively log in with Github to retrieve the Personal Access Token')
c.argument('registry_url', help='The container registry server, e.g. myregistry.azurecr.io')
c.argument('registry_username', help='The username of the registry. If using Azure Container Registry, we will try to infer the credentials if not supplied')
Expand Down Expand Up @@ -236,7 +236,7 @@ def load_arguments(self, _):
with self.argument_context('containerapp up', arg_group='Github Repo') as c:
c.argument('repo', help='Create an app via Github Actions. In the format: https://github.com/<owner>/<repository-name> or <owner>/<repository-name>')
c.argument('token', help='A Personal Access Token with write access to the specified repository. For more information: https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line. If missing (and using --repo), a browser page will be opened to authenticate with Github.')
c.argument('branch', options_list=['--branch', '-b'], help='The branch of the GitHub repo. Defaults to "main"')
c.argument('branch', options_list=['--branch', '-b'], help='The branch of the Github repo. Assumed to be the Github repo\'s default branch if not specified.')
c.argument('context_path', help='Path in the repo from which to run the docker build. Defaults to "./". Dockerfile is assumed to be named "Dockerfile" and in this directory.')
c.argument('service_principal_client_id', help='The service principal client ID. Used by Github Actions to authenticate with Azure.', options_list=["--service-principal-client-id", "--sp-cid"])
c.argument('service_principal_client_secret', help='The service principal client secret. Used by Github Actions to authenticate with Azure.', options_list=["--service-principal-client-secret", "--sp-sec"])
Expand Down
2 changes: 2 additions & 0 deletions src/containerapp/azext_containerapp/_up_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,8 @@ def _get_dockerfile_content_from_repo(
repo = repo_url_to_name(repo_url)
try:
r = g.get_repo(repo)
if not branch:
branch = r.default_branch
except Exception as e:
raise ValidationError(f"Could not find repo {repo_url}") from e
try:
Expand Down
15 changes: 7 additions & 8 deletions src/containerapp/azext_containerapp/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -1043,6 +1043,8 @@ def _validate_github(repo, branch, token):
github_repo = None
try:
github_repo = g.get_repo(repo)
if not branch:
branch = github_repo.default_branch
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:
Expand All @@ -1062,6 +1064,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,
Expand All @@ -1071,7 +1074,7 @@ def create_or_update_github_action(cmd,
registry_url=None,
registry_username=None,
registry_password=None,
branch="main",
branch=None,
token=None,
login_with_github=False,
image=None,
Expand All @@ -1091,7 +1094,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 <user>/<repo> without the full github url

_validate_github(repo, branch, token)
branch = _validate_github(repo, branch, token)

source_control_info = None

Expand All @@ -1104,11 +1107,7 @@ def create_or_update_github_action(cmd,
source_control_info = SourceControlModel

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

Expand Down Expand Up @@ -2007,7 +2006,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,
Expand Down