Skip to content
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 tools/cfl/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

### Added

- `page edit --message`/`-m` sets the page version comment, which was always "Updated via cfl". Omitting the flag keeps that default; an empty value sends no comment. Thanks to @dmoruzzi for the feature. ([#473](https://github.com/open-cli-collective/atlassian-cli/pull/473))
- Service account support with bearer auth (`--auth-method bearer`) for scoped API tokens ([#171](https://github.com/open-cli-collective/atlassian-cli/pull/171))
- Wiki-link syntax `[[Page Title]]` and `[[SPACE:Page Title]]` for internal Confluence page links ([#129](https://github.com/open-cli-collective/atlassian-cli/pull/129))
- `space view`, `space create`, `space update`, `space delete` commands for full space management ([#151](https://github.com/open-cli-collective/atlassian-cli/issues/151))
Expand Down
4 changes: 4 additions & 0 deletions tools/cfl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,9 @@ cfl page edit 12345 --parent 67890
# Move page and rename in one command
cfl page edit 12345 --parent 67890 --title "New Title"

# Update with a custom version comment
cfl page edit 12345 --file content.md -m "Fixed typos"

# Edit using legacy storage format (for pages created in legacy editor)
cfl page edit 12345 --file content.md --legacy

Expand All @@ -442,6 +445,7 @@ cfl page view 12345 --body-format xhtml --content-only | \
| `--title` | `-t` | | New page title (keeps existing if not specified) |
| `--parent` | `-p` | | Move page to new parent page ID |
| `--file` | `-f` | | Read content from file |
| `--message` | `-m` | `Updated via cfl` | Version comment for the update; an empty value sends none |
| `--editor` | | `false` | Force open in $EDITOR |
| `--body-format` | | `markdown` | Input/editor format: `markdown`, exact `adf` JSON, or exact storage `xhtml` |
| `--legacy` | | `false` | Convert Markdown to storage XHTML instead of ADF; invalid with `adf` or `xhtml` |
Expand Down
15 changes: 14 additions & 1 deletion tools/cfl/internal/cmd/page/edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ type editOptions struct {
bodyFormatExplicit bool
legacy bool
parent string
message string
messageExplicit bool
noVerify bool
allowLossy bool
}
Expand Down Expand Up @@ -88,6 +90,9 @@ skipped. Use --no-verify to skip the read.`,
# Move page to a new parent
cfl page edit 12345 --parent 67890

# Update with a custom version comment
cfl page edit 12345 --file content.md -m "Fixed typos"

# Move page and update title
cfl page edit 12345 --parent 67890 --title "New Title"

Expand All @@ -110,13 +115,15 @@ skipped. Use --no-verify to skip the read.`,
RunE: func(cmd *cobra.Command, args []string) error {
opts.pageID = args[0]
opts.bodyFormatExplicit = cmd.Flags().Changed("body-format")
opts.messageExplicit = cmd.Flags().Changed("message")
return runEdit(cmd.Context(), opts)
},
}

cmd.Flags().StringVarP(&opts.title, "title", "t", "", "New page title")
cmd.Flags().StringVarP(&opts.file, "file", "f", "", "Read content from file")
cmd.Flags().StringVarP(&opts.parent, "parent", "p", "", "Move page to new parent page ID")
cmd.Flags().StringVarP(&opts.message, "message", "m", "", "Version comment for the update")
Comment thread
monit-reviewer marked this conversation as resolved.
cmd.Flags().BoolVar(&opts.editor, "editor", false, "Open editor for content")
cmd.Flags().StringVar(&opts.bodyFormat, "body-format", bodyFormatMarkdown, "Input format: markdown, adf, or xhtml")
cmd.Flags().BoolVar(&opts.legacy, "legacy", false, "Edit page in legacy editor format (Markdown input only)")
Expand Down Expand Up @@ -254,13 +261,19 @@ func runEdit(ctx context.Context, opts *editOptions) error {
}
}

// Backwards compatibility
versionMessage := "Updated via cfl"
if opts.messageExplicit {
versionMessage = opts.message
}

req := &api.UpdatePageRequest{
ID: opts.pageID,
Status: "current",
Title: newTitle,
Version: &api.Version{
Number: existingPage.Version.Number + 1,
Message: "Updated via cfl",
Message: versionMessage,
},
}

Expand Down
64 changes: 64 additions & 0 deletions tools/cfl/internal/cmd/page/edit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,70 @@ func TestRunEdit_TitleOnly(t *testing.T) {
testutil.Equal(t, "<p>Keep this</p>", storage["value"])
}

func TestRunEdit_VersionMessage(t *testing.T) {
t.Parallel()
tests := []struct {
name string
message string
messageExplicit bool
wantMessage any
}{
{name: "default when flag absent", wantMessage: "Updated via cfl"},
{name: "custom message", message: "Fixed typos", messageExplicit: true, wantMessage: "Fixed typos"},
{name: "explicit empty omits field", message: "", messageExplicit: true, wantMessage: nil},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
var receivedBody map[string]any
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
switch {
case r.Method == "GET" && strings.Contains(r.URL.Path, "/pages/12345"):
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte(`{
"id": "12345",
"title": "Old Title",
"version": {"number": 3},
"body": {"storage": {"representation": "storage", "value": "<p>Keep this</p>"}},
"_links": {"webui": "/pages/12345"}
}`))
case r.Method == "PUT" && strings.Contains(r.URL.Path, "/pages/12345"):
body, _ := io.ReadAll(r.Body)
_ = json.Unmarshal(body, &receivedBody)
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte(`{
"id": "12345",
"title": "Old Title",
"version": {"number": 4},
"_links": {"webui": "/pages/12345"}
}`))
default:
w.WriteHeader(http.StatusNotFound)
}
}))
defer server.Close()

rootOpts := newEditTestRootOptions()
client := api.NewClient(server.URL, "test@example.com", "token")
rootOpts.SetAPIClient(client)
rootOpts.Stdin = nil
opts := &editOptions{
Options: rootOpts,
pageID: "12345",
title: "Old Title",
message: tt.message,
messageExplicit: tt.messageExplicit,
}

err := runEdit(context.Background(), opts)
testutil.RequireNoError(t, err)

version := receivedBody["version"].(map[string]any)
testutil.Equal(t, version["message"], tt.wantMessage)
})
}
}

func TestRunEdit_PageNotFound(t *testing.T) {
t.Parallel()
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
Expand Down
Loading