Skip to content
Closed
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## 0.48.1 - Unreleased

- Tasks: make `tasks update --notes ''` and `--title ''` clear the field as their help says, instead of sending an empty PATCH that changed nothing, and reject `--status ''` with a usage error because a task is always `needsAction` or `completed`. (#1313) — thanks @saariuslystoned.

## 0.48.0 - 2026-11-05

**Highlights:** New backups stay local until you configure a remote; existing configurations keep working. Store service-account keys in the keyring, search Gmail IDs efficiently, and use environment-backed watch tokens, with Calendar fixes and security dependency updates.
Expand Down
2 changes: 1 addition & 1 deletion docs/commands/gog-tasks-update.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ gog tasks (task) update (edit,set) <tasklistId> <taskId> [flags]
| `--readonly` | `bool` | false | Block mutating API requests at runtime; auth add also requests read-only OAuth scopes |
| `--results-only` | `bool` | | In JSON mode, emit only the primary result (drops envelope fields like nextPageToken) |
| `--select`<br>`--pick`<br>`--project` | `string` | | In JSON mode, select comma-separated fields (best-effort; supports dot paths). Desire path: use --fields for most commands. |
| `--status` | `string` | | New status: needsAction\|completed (set empty to clear) |
| `--status` | `string` | | New status: needsAction\|completed |
| `--title` | `string` | | New title (set empty to clear) |
| `-v`<br>`--verbose` | `bool` | | Enable verbose logging |
| `--version` | `kong.VersionFlag` | | Print version and exit |
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/tasks_items.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ type TasksUpdateCmd struct {
Title string `name:"title" help:"New title (set empty to clear)"`
Notes string `name:"notes" help:"New notes (set empty to clear)"`
Due string `name:"due" help:"New due date (RFC3339 or YYYY-MM-DD; time may be ignored; set empty to clear)"`
Status string `name:"status" help:"New status: needsAction|completed (set empty to clear)"`
Status string `name:"status" help:"New status: needsAction|completed"`
}

func (c *TasksUpdateCmd) Run(ctx context.Context, kctx *kong.Context, flags *RootFlags) error {
Expand Down
67 changes: 67 additions & 0 deletions internal/cmd/tasks_update_clear_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package cmd

import (
"errors"
"io"
"net/http"
"net/http/httptest"
"strings"
"testing"
)

// runTasksUpdatePatch runs tasks update against a fake Tasks server and
// returns the PATCH body it sent ("" when no PATCH was sent).
func runTasksUpdatePatch(t *testing.T, args ...string) (string, error) {
t.Helper()
var patched string
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
switch {
case r.Method == http.MethodGet && r.URL.Path == "/tasks/v1/users/@me/lists":
w.Header().Set("Content-Type", "application/json")
_, _ = w.Write([]byte(`{"items":[{"id":"l1","title":"One"}]}`))
case r.Method == http.MethodPatch && r.URL.Path == "/tasks/v1/lists/l1/tasks/t1":
body, _ := io.ReadAll(r.Body)
patched = strings.TrimSpace(string(body))
w.Header().Set("Content-Type", "application/json")
_, _ = w.Write([]byte(`{"id":"t1","title":"Task","status":"needsAction"}`))
default:
http.NotFound(w, r)
}
}))
t.Cleanup(srv.Close)

ctx := withTasksTestService(newCmdRuntimeJSONOutputContext(t, io.Discard, io.Discard), newTasksServiceFromServer(t, srv))
err := runKong(t, &TasksUpdateCmd{}, append([]string{"l1", "t1"}, args...), ctx, &RootFlags{Account: "a@b.com"})
return patched, err
}

func TestTasksUpdateCmd_EmptyNotesAndTitleAreSent(t *testing.T) {
for _, tc := range []struct {
args []string
want string
}{
{args: []string{"--notes", ""}, want: `{"notes":""}`},
{args: []string{"--title", ""}, want: `{"title":""}`},
{args: []string{"--due", ""}, want: `{"due":null}`},
{args: []string{"--notes", "keep"}, want: `{"notes":"keep"}`},
} {
got, err := runTasksUpdatePatch(t, tc.args...)
if err != nil {
t.Fatalf("%v: %v", tc.args, err)
}
if got != tc.want {
t.Fatalf("%v sent PATCH %s, want %s", tc.args, got, tc.want)
}
}
}

func TestTasksUpdateCmd_EmptyStatusIsUsageError(t *testing.T) {
got, err := runTasksUpdatePatch(t, "--status", "")
var exitErr *ExitError
if !errors.As(err, &exitErr) || exitErr.Code != 2 {
t.Fatalf("err = %v, want usage error", err)
}
if got != "" {
t.Fatalf("sent PATCH %s before rejecting", got)
}
}
11 changes: 10 additions & 1 deletion internal/cmd/tasks_update_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,20 @@ func newTasksUpdatePlan(input tasksUpdateInput, fields tasksUpdateFields) (tasks
}

changed := false
// Title and Notes are omitempty in the API struct; force an explicit empty
// value into the PATCH so "set empty to clear" clears instead of sending {}.
if fields.Title {
plan.Patch.Title = strings.TrimSpace(input.Title)
if plan.Patch.Title == "" {
plan.Patch.ForceSendFields = append(plan.Patch.ForceSendFields, "Title")
}
changed = true
}
if fields.Notes {
plan.Patch.Notes = strings.TrimSpace(input.Notes)
if plan.Patch.Notes == "" {
plan.Patch.ForceSendFields = append(plan.Patch.ForceSendFields, "Notes")
}
changed = true
}
if fields.Due {
Expand All @@ -81,7 +89,8 @@ func newTasksUpdatePlan(input tasksUpdateInput, fields tasksUpdateFields) (tasks
if !changed {
return tasksUpdatePlan{}, usage("no fields to update (set at least one of: --title, --notes, --due, --status)")
}
if fields.Status && plan.Patch.Status != "" && plan.Patch.Status != taskStatusNeedsAction && plan.Patch.Status != taskStatusCompleted {
// A task is always needsAction or completed; there is no empty status to set.
if fields.Status && plan.Patch.Status != taskStatusNeedsAction && plan.Patch.Status != taskStatusCompleted {
return tasksUpdatePlan{}, usage("invalid --status (expected needsAction or completed)")
}
return plan, nil
Expand Down
Loading