Skip to content

Commit 4e2d480

Browse files
authored
Merge pull request #32 from taskbadger/sk/update-client
update client + add tag support
2 parents 9c3f1b5 + c3af22a commit 4e2d480

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1221
-957
lines changed

generator_config.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
project_name_override: taskbadger-python
22
package_name_override: taskbadger/internal
33
post_hooks:
4-
- "autoflake -i -r --remove-all-unused-imports --remove-unused-variables --ignore-init-module-imports ."
5-
- "isort ."
6-
- "black ."
4+
- "ruff format ."
5+
- "ruff check . --fix"

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,6 @@ quote-style = "double"
9595
indent-style = "space"
9696
skip-magic-trailing-comma = false
9797
line-ending = "auto"
98+
99+
[tool.ruff.lint.per-file-ignores]
100+
"taskbadger/internal/*" = ["E501"]

taskbadger.yaml

Lines changed: 64 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,23 @@ paths:
4747
examples:
4848
ListResponse:
4949
value:
50-
previous: string
51-
next: string
50+
next: http://api.example.org/accounts/?cursor=cD00ODY%3D"
51+
previous: http://api.example.org/accounts/?cursor=cj0xJnA9NDg3
5252
results:
53-
- id: 57ae8eVBrH7jbDgmYj6Ut2vR9S
54-
organization: example_org
55-
project: example_org
56-
name: example task
57-
status: processing
58-
value: 63
59-
value_percent: 63
60-
data:
61-
property1: customValue
62-
created: '2022-08-24T14:15:22Z'
63-
updated: '2022-08-24T16:15:22Z'
53+
- previous: string
54+
next: string
55+
results:
56+
- id: 57ae8eVBrH7jbDgmYj6Ut2vR9S
57+
organization: example_org
58+
project: example_org
59+
name: example task
60+
status: processing
61+
value: 63
62+
value_percent: 63
63+
data:
64+
property1: customValue
65+
created: '2022-08-24T14:15:22Z'
66+
updated: '2022-08-24T16:15:22Z'
6467
summary: List Response
6568
description: ''
6669
post:
@@ -100,6 +103,9 @@ paths:
100103
status: pending
101104
data:
102105
property1: customValue
106+
tags:
107+
project: demo
108+
user: admin
103109
summary: Create Payload
104110
required: true
105111
security:
@@ -601,9 +607,7 @@ components:
601607
status:
602608
type: string
603609
readOnly: true
604-
config:
605-
type: object
606-
additionalProperties: {}
610+
config: {}
607611
created:
608612
type: string
609613
format: date-time
@@ -631,21 +635,25 @@ components:
631635
type: string
632636
minLength: 1
633637
maxLength: 50
634-
config:
635-
type: object
636-
additionalProperties: {}
638+
config: {}
637639
required:
638640
- integration
639641
- trigger
640642
PaginatedTaskList:
641643
type: object
644+
required:
645+
- results
642646
properties:
643647
next:
644648
type: string
645649
nullable: true
650+
format: uri
651+
example: http://api.example.org/accounts/?cursor=cD00ODY%3D"
646652
previous:
647653
type: string
648654
nullable: true
655+
format: uri
656+
example: http://api.example.org/accounts/?cursor=cj0xJnA9NDg3
649657
results:
650658
type: array
651659
items:
@@ -661,9 +669,7 @@ components:
661669
type: string
662670
minLength: 1
663671
maxLength: 50
664-
config:
665-
type: object
666-
additionalProperties: {}
672+
config: {}
667673
PatchedTaskRequest:
668674
type: object
669675
properties:
@@ -675,15 +681,6 @@ components:
675681
status:
676682
allOf:
677683
- $ref: '#/components/schemas/StatusEnum'
678-
description: |-
679-
* `pending` - pending
680-
* `pre_processing` - pre_processing
681-
* `processing` - processing
682-
* `post_processing` - post_processing
683-
* `success` - success
684-
* `error` - error
685-
* `cancelled` - cancelled
686-
* `stale` - stale
687684
default: pending
688685
value:
689686
type: integer
@@ -699,8 +696,6 @@ components:
699696
format: int64
700697
description: Maximum value of the task. Defaults to 100.
701698
data:
702-
type: object
703-
additionalProperties: {}
704699
nullable: true
705700
description: Custom metadata
706701
start_time:
@@ -728,7 +723,15 @@ components:
728723
minimum: 1
729724
nullable: true
730725
description: Maximum time to allow between task updates before considering
731-
the task stale. Only applies when task is in a running state. (seconds)
726+
the task stale. (seconds)
727+
tags:
728+
type: object
729+
additionalProperties:
730+
type: string
731+
minLength: 2
732+
maxLength: 255
733+
description: Tags for the task represented as a mapping from 'namespace'
734+
to 'value'.
732735
StatusEnum:
733736
enum:
734737
- pending
@@ -740,6 +743,15 @@ components:
740743
- cancelled
741744
- stale
742745
type: string
746+
description: |-
747+
* `pending` - pending
748+
* `pre_processing` - pre_processing
749+
* `processing` - processing
750+
* `post_processing` - post_processing
751+
* `success` - success
752+
* `error` - error
753+
* `cancelled` - cancelled
754+
* `stale` - stale
743755
Task:
744756
type: object
745757
properties:
@@ -760,15 +772,6 @@ components:
760772
status:
761773
allOf:
762774
- $ref: '#/components/schemas/StatusEnum'
763-
description: |-
764-
* `pending` - pending
765-
* `pre_processing` - pre_processing
766-
* `processing` - processing
767-
* `post_processing` - post_processing
768-
* `success` - success
769-
* `error` - error
770-
* `cancelled` - cancelled
771-
* `stale` - stale
772775
default: pending
773776
value:
774777
type: integer
@@ -788,8 +791,6 @@ components:
788791
readOnly: true
789792
nullable: true
790793
data:
791-
type: object
792-
additionalProperties: {}
793794
nullable: true
794795
description: Custom metadata
795796
created:
@@ -825,13 +826,21 @@ components:
825826
minimum: 1
826827
nullable: true
827828
description: Maximum time to allow between task updates before considering
828-
the task stale. Only applies when task is in a running state. (seconds)
829+
the task stale. (seconds)
829830
url:
830831
type: string
831832
readOnly: true
832833
public_url:
833834
type: string
834835
readOnly: true
836+
tags:
837+
type: object
838+
additionalProperties:
839+
type: string
840+
maxLength: 255
841+
minLength: 2
842+
description: Tags for the task represented as a mapping from 'namespace'
843+
to 'value'.
835844
required:
836845
- created
837846
- id
@@ -853,15 +862,6 @@ components:
853862
status:
854863
allOf:
855864
- $ref: '#/components/schemas/StatusEnum'
856-
description: |-
857-
* `pending` - pending
858-
* `pre_processing` - pre_processing
859-
* `processing` - processing
860-
* `post_processing` - post_processing
861-
* `success` - success
862-
* `error` - error
863-
* `cancelled` - cancelled
864-
* `stale` - stale
865865
default: pending
866866
value:
867867
type: integer
@@ -877,8 +877,6 @@ components:
877877
format: int64
878878
description: Maximum value of the task. Defaults to 100.
879879
data:
880-
type: object
881-
additionalProperties: {}
882880
nullable: true
883881
description: Custom metadata
884882
start_time:
@@ -906,7 +904,15 @@ components:
906904
minimum: 1
907905
nullable: true
908906
description: Maximum time to allow between task updates before considering
909-
the task stale. Only applies when task is in a running state. (seconds)
907+
the task stale. (seconds)
908+
tags:
909+
type: object
910+
additionalProperties:
911+
type: string
912+
minLength: 2
913+
maxLength: 255
914+
description: Tags for the task represented as a mapping from 'namespace'
915+
to 'value'.
910916
required:
911917
- name
912918
securitySchemes:

taskbadger/cli/basics.py

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
configure_api,
1212
err_console,
1313
get_actions,
14-
get_metadata,
14+
merge_kv_json,
1515
)
1616

1717

@@ -69,12 +69,23 @@ def create(
6969
show_default=False,
7070
help="Metadata to associate with the task. Must be valid JSON.",
7171
),
72+
tag: list[str] = typer.Option(
73+
None,
74+
show_default=False,
75+
help="Metadata 'key=value' pair to associate with the task. Can be specified multiple times.",
76+
),
77+
tags_json: str = typer.Option(
78+
None,
79+
show_default=False,
80+
help="Tags to associate with the task. Must be valid JSON mapping name -> value.",
81+
),
7282
quiet: bool = typer.Option(False, "--quiet", "-q", help="Minimal output. Only the Task ID."),
7383
):
7484
"""Create a task."""
7585
configure_api(ctx)
7686
actions = get_actions(action_def)
77-
metadata = get_metadata(metadata, metadata_json)
87+
metadata = merge_kv_json(metadata, metadata_json)
88+
tags = merge_kv_json(tag, tags_json)
7889

7990
try:
8091
task = create_task(
@@ -84,6 +95,7 @@ def create(
8495
data=metadata,
8596
actions=actions,
8697
monitor_id=monitor_id,
98+
tags=tags,
8799
)
88100
except Exception as e:
89101
err_console.print(f"Error creating task: {e}")
@@ -119,12 +131,23 @@ def update(
119131
show_default=False,
120132
help="Metadata to associate with the task. Must be valid JSON.",
121133
),
134+
tag: list[str] = typer.Option(
135+
None,
136+
show_default=False,
137+
help="Metadata 'key=value' pair to associate with the task. Can be specified multiple times.",
138+
),
139+
tags_json: str = typer.Option(
140+
None,
141+
show_default=False,
142+
help="Tags to associate with the task. Must be valid JSON mapping name -> value.",
143+
),
122144
quiet: bool = typer.Option(False, "--quiet", "-q", help="No output."),
123145
):
124146
"""Update a task."""
125147
configure_api(ctx)
126148
actions = get_actions(action_def)
127-
metadata = get_metadata(metadata, metadata_json)
149+
metadata = merge_kv_json(metadata, metadata_json)
150+
tags = merge_kv_json(tag, tags_json)
128151

129152
try:
130153
task = update_task(
@@ -135,6 +158,7 @@ def update(
135158
value_max=value_max,
136159
data=metadata,
137160
actions=actions,
161+
tags=tags,
138162
)
139163
except Exception as e:
140164
err_console.print(f"Error creating task: {e}")

taskbadger/cli/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def get_actions(action_def: tuple[str, str, str]) -> list[Action]:
2828
return []
2929

3030

31-
def get_metadata(metadata_kv: list[str], metadata_json: str) -> dict:
31+
def merge_kv_json(metadata_kv: list[str], metadata_json: str) -> dict:
3232
metadata = {}
3333
for kv in metadata_kv:
3434
k, v = kv.strip().split("=", 1)

taskbadger/cli/wrapper.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from rich import print
33

44
from taskbadger import DefaultMergeStrategy, Session, StatusEnum, Task
5-
from taskbadger.cli.utils import configure_api, err_console, get_actions
5+
from taskbadger.cli.utils import configure_api, err_console, get_actions, merge_kv_json
66
from taskbadger.process import ProcessRunner
77

88

@@ -19,6 +19,11 @@ def run(
1919
show_default=False,
2020
help="Action definition e.g. 'success,error email to:me@email.com'",
2121
),
22+
tag: list[str] = typer.Option(
23+
None,
24+
show_default=False,
25+
help="Tags: 'name=value' pair to associate with the task. Can be specified multiple times.",
26+
),
2227
capture_output: bool = typer.Option(False, help="Capture stdout and stderr."),
2328
):
2429
"""Execute a command using the CLI and create a Task to track its outcome.
@@ -34,6 +39,7 @@ def run(
3439
"""
3540
configure_api(ctx)
3641
actions = get_actions(action_def)
42+
tags = merge_kv_json(tag, "")
3743
stale_timeout = update_frequency * 2
3844
with Session():
3945
try:
@@ -43,6 +49,7 @@ def run(
4349
stale_timeout=stale_timeout,
4450
actions=actions,
4551
monitor_id=monitor_id,
52+
tags=tags,
4653
)
4754
except Exception as e:
4855
err_console.print(f"Error creating task: {e}")

0 commit comments

Comments
 (0)