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 creating labels #128

Merged
merged 2 commits into from
Mar 19, 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 @@ -169,6 +169,7 @@ def main(args=None):
[
"organizations", # all use method.add
"workspaces",
"labels",
"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 @@ -82,6 +82,7 @@ def parse_all_yaml(file_paths, destroy=False):
"organizations",
"teams",
"workspaces",
"labels",
"participants",
"credentials",
"compute-envs",
Expand Down
31 changes: 30 additions & 1 deletion seqerakit/overwrite.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ def __init__(self, sp):
"method_args": self._get_organization_args,
"name_key": "orgName",
},
"labels": {
"keys": ["name", "value", "workspace"],
"method_args": self._get_label_args,
"name_key": "name",
},
"teams": {
"keys": ["name", "organization"],
"method_args": self._get_team_args,
Expand Down Expand Up @@ -171,6 +176,15 @@ def _get_workspace_args(self, args):
workspace_id = self._find_workspace_id(args["organization"], args["name"])
return ("delete", "--id", str(workspace_id))

def _get_label_args(self, args):
"""
Returns a list of arguments for the delete() method for labels. The
label_id used to delete will be retrieved using the _find_label_id()
method.
"""
label_id = self._find_label_id(args["name"], args["value"])
return ("delete", "--id", str(label_id), "-w", args["workspace"])

def _get_generic_deletion_args(self, args):
"""
Returns a list of arguments for the delete() method for resources that
Expand Down Expand Up @@ -210,7 +224,10 @@ def _get_json_data(self, block, args, keys_to_get):
self.cached_jsondata = json_method(
block, "list", "-o", sp_args["organization"]
)
elif block in Overwrite.generic_deletion or block == "participants":
elif block in Overwrite.generic_deletion or block in {
"participants",
"labels",
}:
sp_args = self._get_values_from_cmd_args(args, keys_to_get)
self.cached_jsondata = json_method(
block, "list", "-w", sp_args["workspace"]
Expand Down Expand Up @@ -271,3 +288,15 @@ def _find_workspace_id(self, organization, workspace_name):
):
return workspace.get("workspaceId")
return None

def _find_label_id(self, label_name, label_value):
"""
Custom method to find a label ID in a nested dictionary with a given
workspace name. This ID will be used to delete the label.
"""
jsondata = json.loads(self.cached_jsondata)
labels = jsondata["labels"]
for label in labels:
if label.get("name") == label_name and label.get("value") == label_value:
return label.get("id")
return None
6 changes: 6 additions & 0 deletions templates/labels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
## To see the full list of options available run: "tw labels add"
labels:
- name: 'label_name' # required
value: 'label_value' # required
workspace: 'my_organization/my_workspace' # required
overwrite: True # optional
Loading