Skip to content

Commit

Permalink
apply mutually_exclusive_group functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
fran-tirapu committed Aug 16, 2024
1 parent 3c2b70b commit 9857ae6
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 18 deletions.
8 changes: 6 additions & 2 deletions docs/firebase-app-distribution/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@ firebase-app-distribution
### Usage
```bash
firebase-app-distribution [-h] [--log-stream STREAM] [--no-color] [--version] [-s] [-v]
--project-number PROJECT_NUMBER
(--project-id PROJECT_ID | --project-number PROJECT_NUMBER)
[--credentials FIREBASE_SERVICE_ACCOUNT_CREDENTIALS]
ACTION
```
### Required arguments for command `firebase-app-distribution`
### Required mutually exclusive arguments for command `firebase-app-distribution`

##### `--project-id=PROJECT_ID`


Deprecated on version 0.53.5. Use `--project-number` instead.
##### `--project-number, -p=PROJECT_NUMBER`


Expand Down
8 changes: 6 additions & 2 deletions docs/firebase-app-distribution/get-latest-build-version.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ get-latest-build-version
### Usage
```bash
firebase-app-distribution get-latest-build-version [-h] [--log-stream STREAM] [--no-color] [--version] [-s] [-v]
--project-number PROJECT_NUMBER
(--project-id PROJECT_ID | --project-number PROJECT_NUMBER)
[--credentials FIREBASE_SERVICE_ACCOUNT_CREDENTIALS]
--app-id APP_ID
```
Expand All @@ -17,8 +17,12 @@ firebase-app-distribution get-latest-build-version [-h] [--log-stream STREAM] [-


Application ID in Firebase. For example `1:228333310124:ios:5e439e0d0231a788ac8f09`
### Required arguments for command `firebase-app-distribution`
### Required mutually exclusive arguments for command `firebase-app-distribution`

##### `--project-id=PROJECT_ID`


Deprecated on version 0.53.5. Use `--project-number` instead.
##### `--project-number, -p=PROJECT_NUMBER`


Expand Down
8 changes: 6 additions & 2 deletions docs/firebase-app-distribution/releases.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@ releases
### Usage
```bash
firebase-app-distribution releases [-h] [--log-stream STREAM] [--no-color] [--version] [-s] [-v]
--project-number PROJECT_NUMBER
(--project-id PROJECT_ID | --project-number PROJECT_NUMBER)
[--credentials FIREBASE_SERVICE_ACCOUNT_CREDENTIALS]
ACTION
```
### Required arguments for command `firebase-app-distribution`
### Required mutually exclusive arguments for command `firebase-app-distribution`

##### `--project-id=PROJECT_ID`


Deprecated on version 0.53.5. Use `--project-number` instead.
##### `--project-number, -p=PROJECT_NUMBER`


Expand Down
10 changes: 7 additions & 3 deletions docs/firebase-app-distribution/releases/list.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ list
### Usage
```bash
firebase-app-distribution releases list [-h] [--log-stream STREAM] [--no-color] [--version] [-s] [-v]
--project-number PROJECT_NUMBER
(--project-id PROJECT_ID | --project-number PROJECT_NUMBER)
[--credentials FIREBASE_SERVICE_ACCOUNT_CREDENTIALS]
[--limit LIMIT]
[--order-by ORDER_BY]
Expand All @@ -34,12 +34,16 @@ Sort resources in the specified order. Default: `createTimeDesc`


Whether to show the request response in JSON format
### Required arguments for command `firebase-app-distribution`
### Required mutually exclusive arguments for command `firebase-app-distribution`

##### `--project-id=PROJECT_ID`


Deprecated on version 0.53.5. Use `--project-number` instead.
##### `--project-number, -p=PROJECT_NUMBER`


Project ID in Firebase. For example `228333310124`
Project Number in Firebase. For example `228333310124`
### Optional arguments for command `firebase-app-distribution`

##### `--credentials, -c=FIREBASE_SERVICE_ACCOUNT_CREDENTIALS`
Expand Down
13 changes: 12 additions & 1 deletion src/codemagic/tools/firebase_app_distribution/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,24 @@

from .argument_types import CredentialsArgument

select_project_group = cli.MutuallyExclusiveGroup(
name="select project",
required=True,
)


class FirebaseArgument(cli.Argument):
PROJECT_ID = cli.ArgumentProperties(
key="project_id",
flags=("--project-id",),
description=f'Deprecated on version 0.53.5. Use `{Colors.BRIGHT_BLUE("--project-number")}` instead.',
mutually_exclusive_group=select_project_group,
)
PROJECT_NUMBER = cli.ArgumentProperties(
key="project_number",
flags=("--project-number", "-p"),
description=f'Project Number in Firebase. For example `{Colors.WHITE("228333310124")}`',
argparse_kwargs={"required": True},
mutually_exclusive_group=select_project_group,
)
FIREBASE_SERVICE_ACCOUNT_CREDENTIALS = cli.ArgumentProperties(
key="credentials",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import argparse
from typing import Dict
from typing import Optional

from codemagic import cli
from codemagic.google.firebase_client import FirebaseClient
Expand All @@ -13,7 +14,11 @@
from .arguments import FirebaseArgument


@cli.common_arguments(FirebaseArgument.PROJECT_NUMBER, FirebaseArgument.FIREBASE_SERVICE_ACCOUNT_CREDENTIALS)
@cli.common_arguments(
FirebaseArgument.PROJECT_ID,
FirebaseArgument.PROJECT_NUMBER,
FirebaseArgument.FIREBASE_SERVICE_ACCOUNT_CREDENTIALS,
)
class FirebaseAppDistribution(
cli.CliApp,
GetLatestBuildVersionAction,
Expand All @@ -23,13 +28,25 @@ class FirebaseAppDistribution(
Utility to list releases and retrieve the latest release build version number from Firebase
"""

def __init__(self, credentials: Dict, project_number: str, **kwargs):
def __init__(self, credentials: Dict, project_number: Optional[str], project_id: Optional[str], **kwargs):
super().__init__(**kwargs)
self.client = FirebaseClient(credentials)
if not project_id and not project_number:
raise FirebaseArgument.PROJECT_NUMBER.raise_argument_error()
self._project_id = project_id
self._project_number = project_number

@property
def project_number(self):
if not self._project_number:
message = (
"Deprecation warning! "
'Flag "--project-id" was deprecated in version 0.53.5 '
"and is subject for removal in future releases. "
'Use "--project-number" instead.'
)
self.logger.warning(cli.Colors.YELLOW(message))
return self._project_id
return self._project_number

@classmethod
Expand All @@ -38,13 +55,10 @@ def from_cli_args(cls, cli_args: argparse.Namespace) -> FirebaseAppDistribution:
if credentials_argument is None:
raise FirebaseArgument.FIREBASE_SERVICE_ACCOUNT_CREDENTIALS.raise_argument_error()

project_number_argument = FirebaseArgument.PROJECT_NUMBER.from_args(cli_args)
if project_number_argument is None:
raise FirebaseArgument.PROJECT_NUMBER.raise_argument_error()

return FirebaseAppDistribution(
credentials_argument.value,
project_number_argument,
FirebaseArgument.PROJECT_NUMBER.from_args(cli_args),
FirebaseArgument.PROJECT_ID.from_args(cli_args),
**cls._parent_class_kwargs(cli_args),
)

Expand Down
4 changes: 3 additions & 1 deletion tests/tools/test_firebase_app_distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

credentials_argument = FirebaseArgument.FIREBASE_SERVICE_ACCOUNT_CREDENTIALS
project_number_argument = FirebaseArgument.PROJECT_NUMBER
project_id_argument = FirebaseArgument.PROJECT_ID


@pytest.fixture
Expand All @@ -42,6 +43,7 @@ def namespace_kwargs():
ns_kwargs = {
credentials_argument.key: CredentialsArgument('{"type":"service_account"}'),
project_number_argument.key: "228333310124",
project_id_argument.key: None,
}
for arg in FirebaseAppDistribution.CLASS_ARGUMENTS:
if not hasattr(arg.type, "environment_variable_key"):
Expand Down Expand Up @@ -158,7 +160,7 @@ def app_identifier():

@pytest.fixture
def firebase_app_distribution(app_identifier):
return FirebaseAppDistribution({"type": "service_account"}, app_identifier.project_id)
return FirebaseAppDistribution({"type": "service_account"}, app_identifier.project_id, None)


def test_list_releases(firebase_app_distribution, mock_releases_list, releases, app_identifier):
Expand Down

0 comments on commit 9857ae6

Please sign in to comment.