Documentation
¶
Overview ¶
Package targetprocess provides a typed Go client for the Targetprocess REST API.
The package offers three layers of type safety:
- Generic functions with known entity types for full compile-time safety
- Generic functions with user-defined structs for typed v2 queries
- Untyped Client methods returning map[string]any for dynamic use
Quick start:
c, err := targetprocess.NewClient("yourcompany.tpondemand.com", "your-token")
story, err := targetprocess.Get[targetprocess.UserStory](ctx, c, 12345)
fmt.Println(story.Name, story.EntityState.Name)
Index ¶
- func Create[T Typed](ctx context.Context, c *Client, fields Entity) (*T, error)
- func DefaultConfigPath() string
- func Get[T Typed](ctx context.Context, c *Client, id int, include ...string) (*T, error)
- func NormalizeType(input string) string
- func Search[T Typed](ctx context.Context, c *Client, where string, opts ...SearchOption) ([]T, error)
- func Update[T Typed](ctx context.Context, c *Client, id int, fields Entity) (*T, error)
- type APIError
- type BaseEntity
- type Bug
- type Client
- func (c *Client) Create(ctx context.Context, entityType string, fields Entity) (Entity, error)
- func (c *Client) Delete(ctx context.Context, entityType string, id int) error
- func (c *Client) Get(ctx context.Context, entityType string, id int, include ...string) (Entity, error)
- func (c *Client) MetaFields(ctx context.Context, entityType string) ([]FieldInfo, error)
- func (c *Client) MetaTypes(ctx context.Context) ([]TypeInfo, error)
- func (c *Client) Query(ctx context.Context, entityType string, params QueryParams) (json.RawMessage, error)
- func (c *Client) QueryEntity(ctx context.Context, entityType string, id int, selectExpr string) (json.RawMessage, error)
- func (c *Client) Raw(ctx context.Context, method, path string, body io.Reader) ([]byte, error)
- func (c *Client) ResolveType(ctx context.Context, id int) (string, error)
- func (c *Client) Search(ctx context.Context, entityType, where string, opts ...SearchOption) ([]Entity, error)
- func (c *Client) Update(ctx context.Context, entityType string, id int, fields Entity) (Entity, error)
- type Comment
- type Config
- type CustomField
- type Entity
- type EntityStateRef
- type Epic
- type Feature
- type FieldInfo
- type FieldKind
- type Identifiable
- type Option
- type PriorityRef
- type QueryParams
- type Ref
- type Request
- type Result
- type SearchOption
- type Task
- type TypeInfo
- type Typed
- type UserRef
- type UserStory
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultConfigPath ¶
func DefaultConfigPath() string
DefaultConfigPath returns the default config file path (~/.config/tp/config.yaml).
func Get ¶
Get retrieves a single entity by ID with full type safety. The entity type is inferred from T (e.g., Get[UserStory] hits /api/v1/UserStorys/{id}). Optional include fields control which nested objects are returned.
func NormalizeType ¶
NormalizeType resolves a user-provided entity type string to its canonical Targetprocess API form. It handles case-insensitive matching, plural stripping, and common aliases (e.g., "stories" -> "UserStory", "bug" -> "Bug").
Unknown types pass through unchanged.
Types ¶
type APIError ¶
APIError represents an HTTP error response from the Targetprocess API. Use errors.As to extract it from returned errors:
var apiErr *targetprocess.APIError
if errors.As(err, &apiErr) {
fmt.Println(apiErr.StatusCode, apiErr.Body)
}
type BaseEntity ¶
type BaseEntity struct {
ID int `json:"Id"`
Name string `json:"Name,omitempty"`
Description string `json:"Description,omitempty"`
ResourceType string `json:"ResourceType,omitempty"`
EntityState *EntityStateRef `json:"EntityState,omitempty"`
EntityType *Ref `json:"EntityType,omitempty"`
Project *Ref `json:"Project,omitempty"`
Priority *PriorityRef `json:"Priority,omitempty"`
Owner *UserRef `json:"Owner,omitempty"`
Creator *UserRef `json:"Creator,omitempty"`
LastEditor *UserRef `json:"LastEditor,omitempty"`
Team *Ref `json:"Team,omitempty"`
TeamIteration *Ref `json:"TeamIteration,omitempty"`
Iteration *Ref `json:"Iteration,omitempty"`
Release *Ref `json:"Release,omitempty"`
ResponsibleTeam *Ref `json:"ResponsibleTeam,omitempty"`
Tags string `json:"Tags,omitempty"`
CreateDate string `json:"CreateDate,omitempty"`
ModifyDate string `json:"ModifyDate,omitempty"`
StartDate string `json:"StartDate,omitempty"`
EndDate string `json:"EndDate,omitempty"`
PlannedStartDate string `json:"PlannedStartDate,omitempty"`
PlannedEndDate string `json:"PlannedEndDate,omitempty"`
LastStateChangeDate string `json:"LastStateChangeDate,omitempty"`
Effort float64 `json:"Effort,omitempty"`
EffortCompleted float64 `json:"EffortCompleted,omitempty"`
EffortToDo float64 `json:"EffortToDo,omitempty"`
TimeSpent float64 `json:"TimeSpent,omitempty"`
TimeRemain float64 `json:"TimeRemain,omitempty"`
Progress float64 `json:"Progress,omitempty"`
NumericPriority float64 `json:"NumericPriority,omitempty"`
EntityVersion int64 `json:"EntityVersion,omitempty"`
Units string `json:"Units,omitempty"`
CustomFields []CustomField `json:"CustomFields,omitempty"`
}
BaseEntity contains fields common to most Targetprocess work items. Known entity types embed this struct.
type Bug ¶
type Bug struct {
BaseEntity
Severity *Ref `json:"Severity,omitempty"`
UserStory *Ref `json:"UserStory,omitempty"`
}
Bug represents a Targetprocess bug.
func (Bug) TPResourceType ¶
TPResourceType returns the canonical Targetprocess resource type name.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the Targetprocess API client.
func NewClient ¶
NewClient creates a new Targetprocess API client. The domain should be your Targetprocess subdomain (e.g., "yourcompany.tpondemand.com").
func NewClientFromConfig ¶
NewClientFromConfig creates a Client using configuration from disk/environment. It loads config from the default path, consulting env vars and keyring.
func (*Client) Get ¶
func (c *Client) Get(ctx context.Context, entityType string, id int, include ...string) (Entity, error)
Get retrieves a single entity by type and ID. Optional include fields control which nested objects are returned (v1 API).
func (*Client) MetaFields ¶
MetaFields returns the fields/properties of an entity type.
func (*Client) MetaTypes ¶
MetaTypes returns all entity types available in the Targetprocess instance.
func (*Client) Query ¶
func (c *Client) Query(ctx context.Context, entityType string, params QueryParams) (json.RawMessage, error)
Query executes a v2 API query and returns raw JSON bytes.
func (*Client) QueryEntity ¶
func (c *Client) QueryEntity(ctx context.Context, entityType string, id int, selectExpr string) (json.RawMessage, error)
QueryEntity queries a single entity by ID via the v2 API.
func (*Client) Raw ¶
Raw makes a raw API request. The path should start with / and can include query parameters. This is an escape hatch for endpoints not covered by other methods.
func (*Client) ResolveType ¶
ResolveType determines the entity type for a given ID via the API.
type Comment ¶
type Comment struct {
ID int `json:"Id"`
Description string `json:"Description,omitempty"`
CreateDate string `json:"CreateDate,omitempty"`
Owner *UserRef `json:"Owner,omitempty"`
General *Ref `json:"General,omitempty"`
ResourceType string `json:"ResourceType,omitempty"`
}
Comment represents a Targetprocess comment on an entity.
func (Comment) TPResourceType ¶
TPResourceType returns the canonical Targetprocess resource type name.
type Config ¶
Config holds Targetprocess connection settings.
func LoadConfig ¶
LoadConfig loads configuration from the given path (or default if empty). Environment variables TP_DOMAIN and TP_TOKEN override file values. The OS keyring is also consulted for the token.
type CustomField ¶
type CustomField struct {
Name string `json:"Name"`
Type string `json:"Type,omitempty"`
Value any `json:"Value"`
}
CustomField represents a custom field value on an entity.
type EntityStateRef ¶
type EntityStateRef struct {
ID int `json:"Id"`
Name string `json:"Name,omitempty"`
NumericPriority int `json:"NumericPriority,omitempty"`
ResourceType string `json:"ResourceType,omitempty"`
}
EntityStateRef is a reference to an entity's workflow state.
type Epic ¶
type Epic struct {
BaseEntity
}
Epic represents a Targetprocess epic.
func (Epic) TPResourceType ¶
TPResourceType returns the canonical Targetprocess resource type name.
type Feature ¶
type Feature struct {
BaseEntity
Epic *Ref `json:"Epic,omitempty"`
}
Feature represents a Targetprocess feature.
func (Feature) TPResourceType ¶
TPResourceType returns the canonical Targetprocess resource type name.
type FieldInfo ¶
type FieldInfo struct {
Name string
Type string
Kind FieldKind
Required bool
Readable bool
Writable bool
Description string
}
FieldInfo describes a field/property of an entity type.
type FieldKind ¶
type FieldKind string
FieldKind categorizes a field as a value, reference, or collection.
type Identifiable ¶
type Identifiable interface {
GetID() int
}
Identifiable is implemented by any entity that has a numeric ID.
type Option ¶
type Option func(*clientConfig)
Option configures a Client.
func WithHTTPClient ¶
WithHTTPClient sets a custom HTTP client for the API client.
type PriorityRef ¶
type PriorityRef struct {
ID int `json:"Id"`
Name string `json:"Name,omitempty"`
Importance int `json:"Importance,omitempty"`
ResourceType string `json:"ResourceType,omitempty"`
}
PriorityRef is a reference to a priority level.
type QueryParams ¶
QueryParams holds parameters for a v2 API query.
type Ref ¶
type Ref struct {
ID int `json:"Id"`
Name string `json:"Name,omitempty"`
ResourceType string `json:"ResourceType,omitempty"`
}
Ref is a lightweight reference to a related entity.
type Request ¶
type Request struct {
BaseEntity
}
Request represents a Targetprocess request.
func (Request) TPResourceType ¶
TPResourceType returns the canonical Targetprocess resource type name.
type Result ¶
Result wraps a v2 API response containing a paginated collection of items.
func Query ¶
func Query[T any](ctx context.Context, c *Client, entityType string, params QueryParams) (*Result[T], error)
Query executes a v2 query and deserializes items into the provided type T. T can be any struct — use struct tags matching the v2 select expression. Unlike other generic functions, entityType must be passed explicitly because T may be a user-defined struct that does not implement Typed.
Example:
type SprintItem struct {
ID int `json:"id"`
Name string `json:"name"`
State string `json:"state"`
}
result, err := targetprocess.Query[SprintItem](ctx, c, "UserStory", targetprocess.QueryParams{
Where: "TeamIteration.Name=='Sprint 42'",
Select: "id,name,entityState.name as state",
})
type SearchOption ¶
type SearchOption func(*searchOpts)
SearchOption configures a Search request.
func WithOrderBy ¶
func WithOrderBy(expr string) SearchOption
WithOrderBy sets the sort expression (e.g., "createDate desc").
func WithSelect ¶
func WithSelect(fields ...string) SearchOption
WithSelect sets the fields to return in the v2 query select clause. Example: WithSelect("id", "name", "entityState.name as state")
func WithTake ¶
func WithTake(n int) SearchOption
WithTake sets the maximum number of results to return.
type Task ¶
type Task struct {
BaseEntity
UserStory *Ref `json:"UserStory,omitempty"`
}
Task represents a Targetprocess task.
func (Task) TPResourceType ¶
TPResourceType returns the canonical Targetprocess resource type name.
type Typed ¶
type Typed interface {
Identifiable
TPResourceType() string
}
Typed is implemented by entities that know their Targetprocess resource type. Generic functions use this to infer the API path automatically.
type UserRef ¶
type UserRef struct {
ID int `json:"Id"`
FirstName string `json:"FirstName,omitempty"`
LastName string `json:"LastName,omitempty"`
FullName string `json:"FullName,omitempty"`
Login string `json:"Login,omitempty"`
ResourceType string `json:"ResourceType,omitempty"`
}
UserRef is a reference to a Targetprocess user.
type UserStory ¶
type UserStory struct {
BaseEntity
Feature *Ref `json:"Feature,omitempty"`
}
UserStory represents a Targetprocess user story.
func (UserStory) TPResourceType ¶
TPResourceType returns the canonical Targetprocess resource type name.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
tp
command
|
|
|
tp-capture
command
Command tp-capture records real Targetprocess API responses for use as test fixtures.
|
Command tp-capture records real Targetprocess API responses for use as test fixtures. |
|
internal
|
|