-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat: expose compact task fields #2109
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
base: main
Are you sure you want to change the base?
Changes from all commits
b768631
14004c5
ef1de3a
71a0599
8a79806
7d065c0
7c7ad7d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| // Copyright (c) 2026 Lark Technologies Pte. Ltd. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| package task | ||
|
|
||
| type taskOutputField string | ||
|
|
||
| const ( | ||
| taskOutputSummary taskOutputField = "summary" | ||
| taskOutputMembers taskOutputField = "members" | ||
| taskOutputStart taskOutputField = "start" | ||
| taskOutputDue taskOutputField = "due" | ||
| taskOutputStatus taskOutputField = "status" | ||
| ) | ||
|
|
||
| var standardTaskOutputFields = []taskOutputField{ | ||
| taskOutputSummary, | ||
| taskOutputMembers, | ||
| taskOutputStart, | ||
| taskOutputDue, | ||
| taskOutputStatus, | ||
| } | ||
|
|
||
| func projectTaskFields(dst, task map[string]interface{}, fields ...taskOutputField) { | ||
| for _, field := range fields { | ||
| key := string(field) | ||
| if value, ok := task[key]; ok { | ||
| dst[key] = value | ||
| } | ||
| } | ||
| } | ||
|
Comment on lines
+24
to
+31
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📐 Maintainability & Code Quality | 🟠 Major | 🏗️ Heavy lift Project from a typed task-output shape. This new shared path accepts raw As per coding guidelines, “Parse 🤖 Prompt for AI AgentsSource: Coding guidelines |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,144 @@ | ||
| // Copyright (c) 2026 Lark Technologies Pte. Ltd. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| package task | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "net/http" | ||
| "reflect" | ||
| "testing" | ||
|
|
||
| "github.com/larksuite/cli/internal/httpmock" | ||
| "github.com/larksuite/cli/shortcuts/common" | ||
| ) | ||
|
|
||
| func TestProjectTaskFields(t *testing.T) { | ||
| task := map[string]interface{}{ | ||
| "summary": "Ship compact fields", | ||
| "members": []interface{}{map[string]interface{}{ | ||
| "id": "ou_owner", "name": "Owner", "type": "user", "role": "assignee", | ||
| }}, | ||
| "start": map[string]interface{}{"timestamp": "1000", "is_all_day": false}, | ||
| "due": map[string]interface{}{"timestamp": "2000", "is_all_day": false}, | ||
| "status": "todo", | ||
| } | ||
| out := map[string]interface{}{"guid": "task-1"} | ||
|
|
||
| projectTaskFields(out, task, standardTaskOutputFields...) | ||
|
|
||
| for _, field := range standardTaskOutputFields { | ||
| key := string(field) | ||
| if !reflect.DeepEqual(out[key], task[key]) { | ||
| t.Fatalf("%s = %#v, want %#v", key, out[key], task[key]) | ||
| } | ||
| } | ||
| if out["guid"] != "task-1" { | ||
| t.Fatalf("existing guid changed: %#v", out) | ||
| } | ||
| } | ||
|
|
||
| func TestProjectTaskFieldsOmitsAbsentFields(t *testing.T) { | ||
| out := map[string]interface{}{} | ||
| projectTaskFields(out, map[string]interface{}{"summary": "Only title"}, standardTaskOutputFields...) | ||
|
|
||
| if out["summary"] != "Only title" { | ||
| t.Fatalf("summary = %#v, want Only title", out["summary"]) | ||
| } | ||
| for _, key := range []string{"members", "start", "due", "status"} { | ||
| if _, ok := out[key]; ok { | ||
| t.Fatalf("%s unexpectedly projected: %#v", key, out) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| func TestTaskRootOutputFields(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| shortcut common.Shortcut | ||
| method string | ||
| url string | ||
| args []string | ||
| }{ | ||
| { | ||
| name: "create", shortcut: CreateTask, method: http.MethodPost, | ||
| url: "/open-apis/task/v2/tasks", | ||
| args: []string{"+create", "--summary", "Requested title", "--as", "bot", "--format", "json"}, | ||
| }, | ||
| { | ||
| name: "reopen", shortcut: ReopenTask, method: http.MethodPatch, | ||
| url: "/open-apis/task/v2/tasks/task-1", | ||
| args: []string{"+reopen", "--task-id", "task-1", "--as", "bot", "--format", "json"}, | ||
| }, | ||
| { | ||
| name: "assign", shortcut: AssignTask, method: http.MethodPost, | ||
| url: "/open-apis/task/v2/tasks/task-1/add_members", | ||
| args: []string{"+assign", "--task-id", "task-1", "--add", "ou_owner", "--as", "bot", "--format", "json"}, | ||
| }, | ||
| { | ||
| name: "followers", shortcut: FollowersTask, method: http.MethodPost, | ||
| url: "/open-apis/task/v2/tasks/task-1/add_members", | ||
| args: []string{"+followers", "--task-id", "task-1", "--add", "ou_follower", "--as", "bot", "--format", "json"}, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| f, stdout, _, reg := taskShortcutTestFactory(t) | ||
| warmTenantToken(t, f, reg) | ||
| reg.Register(&httpmock.Stub{ | ||
| Method: tt.method, | ||
| URL: tt.url, | ||
| Body: map[string]interface{}{ | ||
| "code": 0, | ||
| "msg": "success", | ||
| "data": map[string]interface{}{"task": fullTaskOutputFixture()}, | ||
| }, | ||
| }) | ||
|
|
||
| shortcut := tt.shortcut | ||
| shortcut.AuthTypes = []string{"bot", "user"} | ||
| if err := runMountedTaskShortcut(t, shortcut, tt.args, f, stdout); err != nil { | ||
| t.Fatalf("runMountedTaskShortcut() error = %v", err) | ||
| } | ||
|
|
||
| assertStandardTaskFields(t, decodeTaskOutputData(t, stdout.Bytes())) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func fullTaskOutputFixture() map[string]interface{} { | ||
| return map[string]interface{}{ | ||
| "guid": "task-1", | ||
| "url": "https://example.com/task-1&suite_entity_num=t1", | ||
| "summary": "Server title", | ||
| "members": []interface{}{ | ||
| map[string]interface{}{"id": "ou_owner", "name": "Owner", "type": "user", "role": "assignee"}, | ||
| }, | ||
| "start": map[string]interface{}{"timestamp": "1000", "is_all_day": false}, | ||
| "due": map[string]interface{}{"timestamp": "2000", "is_all_day": false}, | ||
| "status": "todo", | ||
| } | ||
| } | ||
|
|
||
| func decodeTaskOutputData(t *testing.T, raw []byte) map[string]interface{} { | ||
| t.Helper() | ||
| var envelope map[string]interface{} | ||
| if err := json.Unmarshal(raw, &envelope); err != nil { | ||
| t.Fatalf("decode output: %v\n%s", err, raw) | ||
| } | ||
| data, ok := envelope["data"].(map[string]interface{}) | ||
| if !ok { | ||
| t.Fatalf("data = %#v, want object", envelope["data"]) | ||
| } | ||
| return data | ||
| } | ||
|
|
||
| func assertStandardTaskFields(t *testing.T, data map[string]interface{}) { | ||
| t.Helper() | ||
| for _, key := range []string{"summary", "members", "start", "due", "status"} { | ||
| if _, ok := data[key]; !ok { | ||
| t.Errorf("data missing %q: %#v", key, data) | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -77,7 +77,9 @@ var ReminderTask = common.Shortcut{ | |
|
|
||
| if runtime.Bool("remove") { | ||
| if len(reminders) == 0 { | ||
| runtime.OutFormat(map[string]interface{}{"guid": taskId}, nil, func(w io.Writer) { | ||
| outData := map[string]interface{}{"guid": taskId} | ||
| projectTaskFields(outData, taskObj, standardTaskOutputFields...) | ||
| runtime.OutFormat(outData, nil, func(w io.Writer) { | ||
| fmt.Fprintln(w, "No existing reminders to remove.") | ||
| }) | ||
| return nil | ||
|
|
@@ -169,6 +171,7 @@ var ReminderTask = common.Shortcut{ | |
| "guid": taskId, | ||
| "url": urlVal, | ||
| } | ||
| projectTaskFields(outData, taskObj, standardTaskOutputFields...) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win Add a contract test for the successful update path. The new test only exercises 🤖 Prompt for AI AgentsSource: Coding guidelines |
||
|
|
||
| runtime.OutFormat(outData, nil, func(w io.Writer) { | ||
| fmt.Fprintf(w, "✅ Task reminders updated successfully!\n") | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Include standardized
dueandstatushere.Line 225 only projects
membersandstart; JSON still exposes aliasesdue_atandcompleted, but omits the new standarddueandstatusfields. Preserve those aliases, but also projectdueand project or derivestatusfromcompleted. Add direct JSON assertions for both fields.🤖 Prompt for AI Agents