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

feat: add support for members #131

Merged
merged 1 commit into from
Mar 20, 2024
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
1 change: 1 addition & 0 deletions seqerakit/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ def main(args=None):
"organizations", # all use method.add
"workspaces",
"labels",
"members",
"credentials",
"secrets",
"actions",
Expand Down
1 change: 1 addition & 0 deletions seqerakit/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ def parse_all_yaml(file_paths, destroy=False):
"teams",
"workspaces",
"labels",
"members",
"participants",
"credentials",
"compute-envs",
Expand Down
25 changes: 25 additions & 0 deletions seqerakit/overwrite.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ def __init__(self, sp):
"method_args": self._get_label_args,
"name_key": "name",
},
"members": {
"keys": ["user", "organization"],
"method_args": self._get_members_args,
"name_key": "email",
},
"teams": {
"keys": ["name", "organization"],
"method_args": self._get_team_args,
Expand Down Expand Up @@ -106,6 +111,9 @@ def handle_overwrite(self, block, args, overwrite=False, destroy=False):
self.block_operations["participants"]["name_key"] = "teamName"
else:
self.block_operations["participants"]["name_key"] = "email"
elif block == "members":
# Rename the user key to name to correctly index JSON data
sp_args["name"] = sp_args.pop("user")
if self.check_resource_exists(operation["name_key"], sp_args):
# if resource exists and overwrite is true, delete
if overwrite:
Expand Down Expand Up @@ -150,6 +158,18 @@ def _get_team_args(self, args):
)
return ("delete", "--id", str(team_id), "--organization", args["organization"])

def _get_members_args(self, args):
"""
Returns a list of arguments for the delete() method for members.
"""
return (
"delete",
"--user",
args["name"],
"--organization",
args["organization"],
)

def _get_participant_args(self, args):
"""
Returns a list of arguments for the delete() method for participants.
Expand Down Expand Up @@ -235,6 +255,11 @@ def _get_json_data(self, block, args, keys_to_get):
self.cached_jsondata = json_method(
block, "list", "-w", sp_args["workspace"]
)
elif block == "members": # TODO
sp_args = self._get_values_from_cmd_args(args, keys_to_get)
self.cached_jsondata = json_method(
block, "list", "-o", sp_args["organization"]
)
else:
sp_args = self._get_values_from_cmd_args(args, keys_to_get)
self.cached_jsondata = json_method(block, "list")
Expand Down
5 changes: 5 additions & 0 deletions templates/members.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## To see the full list of options available run: "tw members add"
participants:
- user: '[email protected]' # required
organization: 'myorg' # required
overwrite: True # optional
22 changes: 21 additions & 1 deletion tests/unit/test_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def test_create_mock_pipeline_add_yaml(mock_yaml_file):
assert result["pipelines"] == expected_block_output


def test_mock_teams_yaml(mock_yaml_file):
def test_create_mock_teams_yaml(mock_yaml_file):
test_data = {
"teams": [
{
Expand Down Expand Up @@ -312,6 +312,26 @@ def test_mock_teams_yaml(mock_yaml_file):
assert result["teams"] == expected_block_output


def test_create_mock_members_yaml(mock_yaml_file):
test_data = {"members": [{"user": "[email protected]", "organization": "myorg"}]}
expected_block_output = [
{
"cmd_args": [
"--organization",
"myorg",
"--user",
"[email protected]",
],
"overwrite": False,
}
]
file_path = mock_yaml_file(test_data)
result = helper.parse_all_yaml([file_path])

assert "members" in result
assert result["members"] == expected_block_output


def test_empty_yaml_file(mock_yaml_file):
test_data = {}
file_path = mock_yaml_file(test_data)
Expand Down
Loading