mirror of
https://gitea.com/gitea/tea.git
synced 2026-06-05 18:58:43 +02:00
06e4d16bf3
## Summary Add first-class `tea wiki` commands backed by the existing Gitea wiki API and SDK support. ## What this adds - `tea wiki list` - `tea wiki view <page>` - `tea wiki revisions <page>` - `tea wiki create` - `tea wiki edit <page>` - `tea wiki delete <page>` ## Implementation details - registers a new top-level `wiki` entity command - keeps command logic under `cmd/wiki/` - adds wiki-specific renderers in `modules/print/wiki.go` - adds wiki task helpers in `modules/task/wiki.go` - reuses existing repo/login/output/pagination patterns used elsewhere in `tea` - base64-encodes wiki content for create/edit API calls - requires explicit `--confirm` for delete - preserves the current page title during edit when `--title` is omitted ## Test coverage The PR is intentionally split into two commits: 1. `feat: add wiki CLI commands` 2. `test: add wiki integration coverage` Validation performed: - focused command, task, and print tests for the new wiki functionality - integration coverage for the wiki command lifecycle - `make lint` - `make fmt-check` - `make docs-check` - `make build` - upstream PR CI passed: - `check-and-test / Integration Test` - `check-and-test / Lint Build And Unit Coverage` ## Motivation This makes `tea` a better interface for both human and agent-driven workflows by exposing wiki operations as stable first-class CLI commands instead of requiring ad-hoc API calls or custom wrappers. --- Generated by Hermes Agent with GPT-5.4 --------- Co-authored-by: nitro <nitro@nitroui-Macmini.local> Reviewed-on: https://gitea.com/gitea/tea/pulls/998 Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: kuil09 <202447+kuil09@noreply.gitea.com> Co-committed-by: kuil09 <202447+kuil09@noreply.gitea.com>
84 lines
2.5 KiB
Go
84 lines
2.5 KiB
Go
// Copyright 2026 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package task
|
|
|
|
import (
|
|
stdctx "context"
|
|
"testing"
|
|
|
|
"gitea.dev/sdk"
|
|
teaContext "gitea.dev/tea/modules/context"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
type fakeWikiWriteClient struct {
|
|
owner string
|
|
repo string
|
|
pageName string
|
|
create gitea.CreateWikiPageOptions
|
|
edit gitea.CreateWikiPageOptions
|
|
created *gitea.WikiPage
|
|
edited *gitea.WikiPage
|
|
deleted bool
|
|
}
|
|
|
|
func (f *fakeWikiWriteClient) CreatePage(_ stdctx.Context, owner, repo string, opt gitea.CreateWikiPageOptions) (*gitea.WikiPage, *gitea.Response, error) {
|
|
f.owner = owner
|
|
f.repo = repo
|
|
f.create = opt
|
|
return f.created, nil, nil
|
|
}
|
|
|
|
func (f *fakeWikiWriteClient) EditPage(_ stdctx.Context, owner, repo, pageName string, opt gitea.CreateWikiPageOptions) (*gitea.WikiPage, *gitea.Response, error) {
|
|
f.owner = owner
|
|
f.repo = repo
|
|
f.pageName = pageName
|
|
f.edit = opt
|
|
return f.edited, nil, nil
|
|
}
|
|
|
|
func (f *fakeWikiWriteClient) DeletePage(_ stdctx.Context, owner, repo, pageName string) (*gitea.Response, error) {
|
|
f.owner = owner
|
|
f.repo = repo
|
|
f.pageName = pageName
|
|
f.deleted = true
|
|
return nil, nil
|
|
}
|
|
|
|
func newWikiTaskContext() *teaContext.TeaContext {
|
|
return &teaContext.TeaContext{Owner: "octo", Repo: "tea"}
|
|
}
|
|
|
|
func TestCreateWikiPageCallsSDK(t *testing.T) {
|
|
client := &fakeWikiWriteClient{created: &gitea.WikiPage{Title: "Home"}}
|
|
page, err := CreateWikiPage(newWikiTaskContext(), client, gitea.CreateWikiPageOptions{Title: "Home", ContentBase64: "IyBIb21l"})
|
|
require.NoError(t, err)
|
|
assert.Equal(t, "octo", client.owner)
|
|
assert.Equal(t, "tea", client.repo)
|
|
assert.Equal(t, "Home", client.create.Title)
|
|
assert.Equal(t, "Home", page.Title)
|
|
}
|
|
|
|
func TestEditWikiPageCallsSDK(t *testing.T) {
|
|
client := &fakeWikiWriteClient{edited: &gitea.WikiPage{Title: "Home"}}
|
|
page, err := EditWikiPage(newWikiTaskContext(), client, "Home", gitea.CreateWikiPageOptions{ContentBase64: "IyBVcGRhdGVk"})
|
|
require.NoError(t, err)
|
|
assert.Equal(t, "octo", client.owner)
|
|
assert.Equal(t, "tea", client.repo)
|
|
assert.Equal(t, "Home", client.pageName)
|
|
assert.Equal(t, "IyBVcGRhdGVk", client.edit.ContentBase64)
|
|
assert.Equal(t, "Home", page.Title)
|
|
}
|
|
|
|
func TestDeleteWikiPageCallsSDK(t *testing.T) {
|
|
client := &fakeWikiWriteClient{}
|
|
err := DeleteWikiPage(newWikiTaskContext(), client, "Home")
|
|
require.NoError(t, err)
|
|
assert.Equal(t, "octo", client.owner)
|
|
assert.Equal(t, "tea", client.repo)
|
|
assert.Equal(t, "Home", client.pageName)
|
|
assert.True(t, client.deleted)
|
|
}
|