zentao

package
v1.0.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 27, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package zentao implements a client for the ZenTaoPMS API, ported from the official PHP SDK shipped with zentaopms (zentaopms_21.7 sdk/php/zentao.php).

Auth flow (mirrors the PHP SDK constructor):

  1. GET ?m=api&f=getSessionID -> { sessionName, sessionID, rand }
  2. POST ?m=user&f=login&t=json (body: account, password)

Access modes:

  • GET (default): every request uses ?m=...&f=...&t=json query style.
  • PATH_INFO: POST requests go to /module-func.json instead.

List (GET) responses come back as {"status":"success","data":"<json string>"} where data is double-encoded; submit (POST) responses come back as {"result":"success"|"fail","message":...}. Both are unwrapped transparently.

Index

Constants

View Source
const (
	StatusAll    = "all"
	StatusActive = "active"
	StatusClosed = "closed"
	StatusWait   = "wait"
	StatusDoing  = "doing"
	StatusDone   = "done"
	OrderIDAsc   = "id_asc"
	OrderIDDesc  = "id_desc"
	OrderAsc     = "order_asc"
	OrderDesc    = "order_desc"
)

Common status constants.

View Source
const (
	AccessModeGET      = "GET"
	AccessModePathInfo = "PATH_INFO"
)

Access modes supported by the API, mirroring ztAccessMode in the PHP SDK.

Variables

View Source
var MethodPositionalOrder = map[string][]string{
	"my/todo":        {"type", "account", "status", "orderBy", "recTotal", "recPerPage", "pageID"},
	"my/task":        {"type", "param", "orderBy", "recTotal", "recPerPage", "pageID"},
	"my/bug":         {"type", "param", "orderBy", "recTotal", "recPerPage", "pageID"},
	"my/story":       {"type", "param", "orderBy", "recTotal", "recPerPage", "pageID"},
	"my/project":     {"status", "orderBy", "recTotal", "recPerPage", "pageID"},
	"my/execution":   {"type", "orderBy", "recTotal", "recPerPage", "pageID"},
	"my/dynamic":     {"type", "recTotal", "date", "direction"},
	"todo/delete":    {"todoID", "confirm"},
	"task/delete":    {"projectID", "taskID", "confirm"},
	"bug/delete":     {"bugID", "confirm"},
	"bug/browse":     {"productID", "branch", "browseType", "param", "orderBy", "recTotal", "recPerPage", "pageID"},
	"project/browse": {"programID", "browseType", "param", "orderBy", "recTotal", "recPerPage", "pageID"},
	"project/task":   {"projectID", "status", "param", "orderBy", "recTotal", "recPerPage", "pageID"},
	"execution/task": {"executionID", "status", "param", "orderBy", "recTotal", "recPerPage", "pageID"},
	"product/all":    {"browseType", "orderBy", "param", "recTotal", "recPerPage", "pageID", "programID"},
	"product/browse": {"productID", "branch", "browseType", "param", "storyType", "orderBy", "recTotal", "recPerPage", "pageID"},
	"company/browse": {"browseType", "param", "type", "orderBy", "recTotal", "recPerPage", "pageID"},
	"dept/browse":    {"deptID"},
}

MethodPositionalOrder defines the exact parameter order expected by ZenTao controller action arguments. When constructing GET query strings, parameters matching these lists are placed FIRST in exact positional order. NOTE: Checked against ZenTao 21.7 source code in module/*/control.php.

Functions

This section is empty.

Types

type Bug

type Bug struct {
	ID             string `json:"id"`
	Product        string `json:"product"`
	Branch         string `json:"branch"`
	Module         string `json:"module"`
	Project        string `json:"project"`
	Story          string `json:"story"`
	StoryVersion   string `json:"storyVersion"`
	Task           string `json:"task"`
	ToTask         string `json:"toTask"`
	ToStory        string `json:"toStory"`
	Title          string `json:"title"`
	Keywords       string `json:"keywords"`
	Severity       string `json:"severity"`
	Pri            string `json:"pri"`
	Type           string `json:"type"`
	OS             string `json:"os"`
	Browser        string `json:"browser"`
	Hardware       string `json:"hardware"`
	Found          string `json:"found"`
	Steps          string `json:"steps"`
	Status         string `json:"status"`
	SubStatus      string `json:"subStatus"`
	Color          string `json:"color"`
	Confirmed      string `json:"confirmed"`
	ActivatedCount string `json:"activatedCount"`
	ActivatedDate  string `json:"activatedDate"`
	Mailto         string `json:"mailto"`
	OpenedBy       string `json:"openedBy"`
	OpenedDate     string `json:"openedDate"`
	OpenedBuild    string `json:"openedBuild"`
	AssignedTo     string `json:"assignedTo"`
	AssignedDate   string `json:"assignedDate"`
	Deadline       string `json:"deadline"`
	ResolvedBy     string `json:"resolvedBy"`
	Resolution     string `json:"resolution"`
	ResolvedBuild  string `json:"resolvedBuild"`
	ResolvedDate   string `json:"resolvedDate"`
	ClosedBy       string `json:"closedBy"`
	ClosedDate     string `json:"closedDate"`
	DuplicateBug   string `json:"duplicateBug"`
	LinkBug        string `json:"linkBug"`
	Case           string `json:"case"`
	CaseVersion    string `json:"caseVersion"`
	Result         string `json:"result"`
	Repo           string `json:"repo"`
	Entry          string `json:"entry"`
	Lines          string `json:"lines"`
	V1             string `json:"v1"`
	V2             string `json:"v2"`
	RepoType       string `json:"repoType"`
	Testtask       string `json:"testtask"`
	LastEditedBy   string `json:"lastEditedBy"`
	LastEditedDate string `json:"lastEditedDate"`
	Deleted        string `json:"deleted"`
}

Bug represents a ZenTao bug.

type Client

type Client struct {
	HTTP   *http.Client
	Cookie string // sessionName=sessionID, from getSessionID

	// OnSessionRefreshed callback triggered whenever the session is automatically refreshed.
	OnSessionRefreshed func(cookie, rand string)

	BaseURL    string
	Account    string
	Password   string
	AccessMode string
	// contains filtered or unexported fields
}

Client is a ZenTao API client. Create one with New, then call Login before any endpoint method (Login is also invoked once per CLI invocation).

func New

func New(cfg Config) *Client

New builds a Client from Config.

func (*Client) BugCreate

func (c *Client) BugCreate(ctx context.Context, params Params) (json.RawMessage, error)

BugCreate creates a bug (POST m=bug&f=create&productID=<id>).

func (*Client) BugCreateParams

func (c *Client) BugCreateParams(ctx context.Context, productID string, branch string) (json.RawMessage, error)

BugCreateParams returns parameters and schema needed to create a bug (m=bug&f=create&productID=<id>&branch=<branch>).

func (*Client) BugDelete

func (c *Client) BugDelete(ctx context.Context, bugID string) (json.RawMessage, error)

BugDelete deletes a bug by ID (GET/POST m=bug&f=delete&bugID=<id>&confirm=yes).

func (*Client) BugList

func (c *Client) BugList(ctx context.Context, params Params) (json.RawMessage, error)

BugList returns bugs (m=bug&f=browse).

func (*Client) BugResolve

func (c *Client) BugResolve(ctx context.Context, bugID string, params Params) (json.RawMessage, error)

BugResolve resolves a bug (POST m=bug&f=resolve&bugID=<id>). Common fields: resolution, resolvedBuild, comment.

func (*Client) BugResolveParams

func (c *Client) BugResolveParams(ctx context.Context, bugID string) (json.RawMessage, error)

BugResolveParams returns parameters and schema needed to resolve a bug (m=bug&f=resolve&bugID=<id>).

func (*Client) DeptAdd

func (c *Client) DeptAdd(ctx context.Context, params Params) (json.RawMessage, error)

DeptAdd creates a department (POST m=dept&f=manageChild).

func (*Client) DeptList

func (c *Client) DeptList(ctx context.Context, params Params) (json.RawMessage, error)

DeptList returns the department tree (m=dept&f=browse).

func (*Client) GetRand

func (c *Client) GetRand() string

GetRand returns the session rand value.

func (*Client) Login

func (c *Client) Login(ctx context.Context) error

Login performs the session handshake: getSessionID then user/login. It is safe to call once per process; every endpoint method assumes a valid session (mirrors the PHP SDK, which logs in in its constructor).

func (*Client) MyBugs

func (c *Client) MyBugs(ctx context.Context, params Params) (json.RawMessage, error)

MyBugs returns bugs for current user (m=my&f=bug). ZenTao 21.7 signature: bug(type='assignedTo', param=0, orderBy='id_desc', recTotal=0, recPerPage=20, pageID=1)

func (*Client) MyDynamics

func (c *Client) MyDynamics(ctx context.Context, params Params) (json.RawMessage, error)

MyDynamics returns recent activity stream for current user (m=my&f=dynamic). ZenTao 21.7 signature: dynamic(type='today', recTotal=0, date=”, direction='next')

func (*Client) MyProjects

func (c *Client) MyProjects(ctx context.Context, params Params) (json.RawMessage, error)

MyProjects returns projects for current user (m=my&f=project). ZenTao 21.7 signature: project(status='doing', orderBy='id_desc', recTotal=0, recPerPage=15, pageID=1)

func (*Client) MyStories

func (c *Client) MyStories(ctx context.Context, params Params) (json.RawMessage, error)

MyStories returns stories/requirements for current user (m=my&f=story). ZenTao 21.7 signature: story(type='assignedTo', param=0, orderBy='id_desc', recTotal=0, recPerPage=20, pageID=1)

func (*Client) MyTasks

func (c *Client) MyTasks(ctx context.Context, params Params) (json.RawMessage, error)

MyTasks returns tasks for current user (m=my&f=task). ZenTao 21.7 signature: task(type='assignedTo', param=0, orderBy='id_desc', recTotal=0, recPerPage=20, pageID=1)

func (*Client) MyTodos

func (c *Client) MyTodos(ctx context.Context, params Params) (json.RawMessage, error)

MyTodos returns todos for current user (m=my&f=todo). ZenTao 21.7 signature: todo(type='before', userID=”, status='all', orderBy='date_desc,status,begin', recTotal=0, recPerPage=20, pageID=1)

func (*Client) ProductAdd

func (c *Client) ProductAdd(ctx context.Context, params Params) (json.RawMessage, error)

ProductAdd creates a product (POST m=product&f=create). Common fields: name, code, PO, QD, RD, acl, status, desc.

func (*Client) ProductCreateParams added in v1.0.8

func (c *Client) ProductCreateParams(ctx context.Context, programID string) (json.RawMessage, error)

ProductCreateParams returns parameters and metadata needed to create a product (m=product&f=create&programID=<id>).

func (*Client) ProductList

func (c *Client) ProductList(ctx context.Context, params Params) (json.RawMessage, error)

ProductList returns products (m=product&f=all or m=product&f=browse).

func (*Client) ProjectAdd

func (c *Client) ProjectAdd(ctx context.Context, params Params) (json.RawMessage, error)

ProjectAdd creates a project (POST m=project&f=create). Common fields: name, code, begin, end, days, team, type, status, acl, PM, PO, QD, RD, desc.

func (*Client) ProjectCreateParams added in v1.0.8

func (c *Client) ProjectCreateParams(ctx context.Context, programID string) (json.RawMessage, error)

ProjectCreateParams returns parameters and metadata needed to create a project (m=project&f=create&programID=<id>).

func (*Client) ProjectList

func (c *Client) ProjectList(ctx context.Context, params Params) (json.RawMessage, error)

ProjectList returns projects.

func (*Client) SetRand

func (c *Client) SetRand(r string)

SetRand sets the session rand value (e.g. restored from session cache).

func (*Client) TaskCreate

func (c *Client) TaskCreate(ctx context.Context, params Params) (json.RawMessage, error)

TaskCreate creates a task (POST m=task&f=create&project=<id>). Common fields: name, type, pri, estimate, assignedTo, module, story, desc.

func (*Client) TaskCreateParams

func (c *Client) TaskCreateParams(ctx context.Context, projectID string) (json.RawMessage, error)

TaskCreateParams returns parameters and schema needed to create a task (m=task&f=create&project=<id>).

func (*Client) TaskDelete

func (c *Client) TaskDelete(ctx context.Context, projectID, taskID string) (json.RawMessage, error)

TaskDelete deletes a task by ID (GET/POST m=task&f=delete&taskID=<id>&confirm=yes).

func (*Client) TaskFinish

func (c *Client) TaskFinish(ctx context.Context, taskID string, params Params) (json.RawMessage, error)

TaskFinish completes a task (POST m=task&f=finish&taskID=<id>). Common fields: real (actual hours), comment.

func (*Client) TaskFinishParams

func (c *Client) TaskFinishParams(ctx context.Context, taskID string) (json.RawMessage, error)

TaskFinishParams returns parameters and current state needed to finish a task (m=task&f=finish&taskID=<id>).

func (*Client) TaskList

func (c *Client) TaskList(ctx context.Context, params Params) (json.RawMessage, error)

TaskList returns tasks of a project/execution.

func (*Client) TodoClose

func (c *Client) TodoClose(ctx context.Context, todoID string) (json.RawMessage, error)

TodoClose closes a todo (POST m=todo&f=close&todoID=<id>).

func (*Client) TodoCreate

func (c *Client) TodoCreate(ctx context.Context, params Params) (json.RawMessage, error)

TodoCreate creates a todo item (POST m=todo&f=create). Common fields: name, date (YYYY-MM-DD), begin, end, type (custom, task, bug, story), pri, desc.

func (*Client) TodoDelete

func (c *Client) TodoDelete(ctx context.Context, todoID string) (json.RawMessage, error)

TodoDelete deletes a todo by ID (GET/POST m=todo&f=delete&todoID=<id>&confirm=yes).

func (*Client) TodoFinish

func (c *Client) TodoFinish(ctx context.Context, todoID string) (json.RawMessage, error)

TodoFinish marks a todo as completed (POST m=todo&f=finish&todoID=<id>).

func (*Client) TodoList

func (c *Client) TodoList(ctx context.Context, params Params) (json.RawMessage, error)

TodoList queries todo items (m=todo&f=browse or m=my&f=todo).

func (*Client) TodoStart

func (c *Client) TodoStart(ctx context.Context, todoID string) (json.RawMessage, error)

TodoStart marks a todo as started/doing (POST m=todo&f=start&todoID=<id>).

func (*Client) UserAdd

func (c *Client) UserAdd(ctx context.Context, params Params) (json.RawMessage, error)

UserAdd creates a user (POST m=user&f=create&dept=<dept>), including the md5+session-rand password encryption from the PHP SDK addUser():

password1      = md5(pwd1) + rand
password2      = md5(pwd2) + rand
verifyPassword = md5(md5(masterPassword) + rand)

field "password" is treated as both password1 and password2; "verifyPassword" defaults to the master (login) password, like the SDK.

func (*Client) UserCreateParams added in v1.0.8

func (c *Client) UserCreateParams(ctx context.Context, deptID string) (json.RawMessage, error)

UserCreateParams returns parameters and schema needed to create a user (m=user&f=create&dept=<dept>).

func (*Client) UserList

func (c *Client) UserList(ctx context.Context, params Params) (json.RawMessage, error)

UserList returns users (m=company&f=browse). In ZenTao 21.7: browse(browseType='inside', param=0, type='bydept', orderBy='id_asc', recTotal=0, recPerPage=20, pageID=1)

type Config

type Config struct {
	URL        string        `json:"url"`
	Account    string        `json:"account"`
	Password   string        `json:"password,omitempty"`
	AccessMode string        `json:"accessMode,omitempty"`
	Timeout    time.Duration `json:"-"`
	Insecure   bool          `json:"-"`
}

Config holds connection settings. Resolution order: CLI flags > env vars > config file. See cmd config loading for details.

type Department

type Department struct {
	ID       string `json:"id"`
	Name     string `json:"name"`
	Parent   string `json:"parent"`
	Path     string `json:"path"`
	Grade    string `json:"grade"`
	Order    string `json:"order"`
	Position string `json:"position"`
	Function string `json:"function"`
	Manager  string `json:"manager"`
}

Department represents a ZenTao department.

type Params

type Params = url.Values

Params is an alias so command builders read naturally:

zentao.Params{"status": "all", "orderBy": "id_desc"}

type Product

type Product struct {
	ID             string `json:"id"`
	Name           string `json:"name"`
	Code           string `json:"code"`
	Line           string `json:"line"`
	Type           string `json:"type"`
	Status         string `json:"status"`
	Desc           string `json:"desc"`
	PO             string `json:"PO"`
	QD             string `json:"QD"`
	RD             string `json:"RD"`
	ACL            string `json:"acl"`
	Whitelist      string `json:"whitelist"`
	CreatedBy      string `json:"createdBy"`
	CreatedDate    string `json:"createdDate"`
	CreatedVersion string `json:"createdVersion"`
	Order          string `json:"order"`
	Deleted        string `json:"deleted"`
}

Product represents a ZenTao product.

type Project

type Project struct {
	ID            string `json:"id"`
	IsCat         string `json:"isCat"`
	CatID         string `json:"catID"`
	Type          string `json:"type"`
	Parent        string `json:"parent"`
	Name          string `json:"name"`
	Code          string `json:"code"`
	Begin         string `json:"begin"`
	End           string `json:"end"`
	Days          string `json:"days"`
	Status        string `json:"status"`
	Statge        string `json:"statge"`
	Pri           string `json:"pri"`
	Desc          string `json:"desc"`
	OpenedBy      string `json:"openedBy"`
	OpenedDate    string `json:"openedDate"`
	OpenedVersion string `json:"openedVersion"`
	ClosedBy      string `json:"closedBy"`
	ClosedDate    string `json:"closedDate"`
	CanceledBy    string `json:"canceledBy"`
	CanceledDate  string `json:"canceledDate"`
	PO            string `json:"PO"`
	PM            string `json:"PM"`
	QD            string `json:"QD"`
	RD            string `json:"RD"`
	Team          string `json:"team"`
	ACL           string `json:"acl"`
	Whitelist     string `json:"whitelist"`
	Order         string `json:"order"`
	Deleted       string `json:"deleted"`
}

Project represents a ZenTao project / execution.

type Task

type Task struct {
	ID             string `json:"id"`
	Parent         string `json:"parent"`
	Project        string `json:"project"`
	Module         string `json:"module"`
	Story          string `json:"story"`
	StoryVersion   string `json:"storyVersion"`
	FromBug        string `json:"fromBug"`
	Name           string `json:"name"`
	Type           string `json:"type"`
	Pri            string `json:"pri"`
	Estimate       string `json:"estimate"`
	Consumed       string `json:"consumed"`
	Left           string `json:"left"`
	Deadline       string `json:"deadline"`
	Status         string `json:"status"`
	Color          string `json:"color"`
	Mailto         string `json:"mailto"`
	Desc           string `json:"desc"`
	OpenedBy       string `json:"openedBy"`
	OpenedDate     string `json:"openedDate"`
	AssignedTo     string `json:"assignedTo"`
	AssignedDate   string `json:"assignedDate"`
	EstStarted     string `json:"estStarted"`
	RealStarted    string `json:"realStarted"`
	FinishedBy     string `json:"finishedBy"`
	FinishedDate   string `json:"finishedDate"`
	FinishedList   string `json:"finishedList"`
	CanceledBy     string `json:"canceledBy"`
	CanceledDate   string `json:"canceledDate"`
	ClosedBy       string `json:"closedBy"`
	ClosedDate     string `json:"closedDate"`
	ClosedReason   string `json:"closedReason"`
	LastEditedBy   string `json:"lastEditedBy"`
	LastEditedDate string `json:"lastEditedDate"`
	Deleted        string `json:"deleted"`
}

Task represents a ZenTao task.

type User

type User struct {
	ID       string `json:"id"`
	Dept     string `json:"dept"`
	Account  string `json:"account"`
	Realname string `json:"realname"`
	Role     string `json:"role"`
	Email    string `json:"email"`
	Gender   string `json:"gender"`
	Mobile   string `json:"mobile"`
	Phone    string `json:"phone"`
	QQ       string `json:"qq"`
	Address  string `json:"address"`
	Zipcode  string `json:"zipcode"`
	Join     string `json:"join"`
	Visits   string `json:"visits"`
	IP       string `json:"ip"`
	Last     string `json:"last"`
	Fails    string `json:"fails"`
	Locked   string `json:"locked"`
	Ranzhi   string `json:"ranzhi"`
	Deleted  string `json:"deleted"`
}

User represents a ZenTao user.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL