api

package
v2.10.0 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FetchAll

func FetchAll[T any](ctx context.Context, c *Client, path string, params url.Values, key string, maxResults int) ([]T, int, error)

FetchAll retrieves all pages of a resource. The key parameter is the JSON wrapper key (e.g., "issues", "projects"). If maxResults is 0, all results are fetched.

func FetchAllFiltered

func FetchAllFiltered[T any](ctx context.Context, c *Client, path string, params url.Values, key string, maxResults int, filter func(T) bool) ([]T, bool, error)

FetchAllFiltered retrieves pages of a resource, keeping only items that pass the filter. If maxResults is 0, all matching items are fetched. Returns the matched items and whether more matches may exist beyond what was collected.

Types

type APIError

type APIError struct {
	StatusCode int
	Errors     []string
	URL        string
}

APIError represents an error response from the Redmine API.

func (*APIError) Error

func (e *APIError) Error() string

func (*APIError) IsAuthError

func (e *APIError) IsAuthError() bool

IsAuthError returns true if the error is a 401.

func (*APIError) IsConflict added in v2.6.0

func (e *APIError) IsConflict() bool

IsConflict returns true if the error is a 409. Redmine surfaces 409 on optimistic-locking failures (e.g. updating a wiki page whose version has been bumped on the server since the client last fetched it).

func (*APIError) IsForbidden

func (e *APIError) IsForbidden() bool

IsForbidden returns true if the error is a 403.

func (*APIError) IsNotFound

func (e *APIError) IsNotFound() bool

IsNotFound returns true if the error is a 404.

func (*APIError) IsValidationError

func (e *APIError) IsValidationError() bool

IsValidationError returns true if the error is a 422.

type AttachmentService

type AttachmentService struct {
	// contains filtered or unexported fields
}

AttachmentService handles attachment metadata, upload, and download API calls.

func (*AttachmentService) Download added in v2.8.0

func (s *AttachmentService) Download(ctx context.Context, att *models.Attachment, w io.Writer) (int64, error)

Download streams the raw bytes of an attachment to w without buffering the whole file in memory. It returns the number of bytes written.

The download URL is resolved from the attachment's content_url when that URL is hosted on the configured Redmine server (so subdirectory installs keep working), and otherwise falls back to the canonical /attachments/download/:id/:filename path built from the base URL. This guard ensures the API key (added to every request by authTransport) is never sent to a host other than the configured server.

func (*AttachmentService) Get added in v2.8.0

Get retrieves the metadata for a single attachment by ID via GET /attachments/:id.json (filename, content type, size, author, content_url, ...).

func (*AttachmentService) Upload

func (s *AttachmentService) Upload(ctx context.Context, filename string, body io.Reader, size int64) (string, error)

Upload streams body (of known size) to Redmine's /uploads.json endpoint and returns the upload token. filename is sent as a query parameter per the Redmine REST docs so the server records the original name.

type CategoryService

type CategoryService struct {
	// contains filtered or unexported fields
}

CategoryService handles issue category-related API calls.

func (*CategoryService) List

func (s *CategoryService) List(ctx context.Context, projectID string) ([]models.IssueCategory, int, error)

List retrieves issue categories for a project.

type Client

type Client struct {
	Issues       *IssueService
	Projects     *ProjectService
	TimeEntries  *TimeEntryService
	Users        *UserService
	MyAccount    *MyAccountService
	Trackers     *TrackerService
	Statuses     *StatusService
	Roles        *RoleService
	Enumerations *EnumerationService
	Versions     *VersionService
	Categories   *CategoryService
	Groups       *GroupService
	Search       *SearchService
	Memberships  *MembershipService
	Attachments  *AttachmentService
	Wikis        *WikiService
	Queries      *QueryService
	CustomFields *CustomFieldService
	Files        *FileService
	Relations    *RelationService
	// contains filtered or unexported fields
}

Client is the Redmine API client.

func NewClient

func NewClient(cfg *config.Config, log *debug.Logger) (*Client, error)

NewClient creates a new Redmine API client from configuration.

func NewTestClient

func NewTestClient(httpClient *http.Client, baseURL string, log *debug.Logger) *Client

NewTestClient constructs a Client wired to a given http.Client and base URL without requiring a full config. It is exported only for use in tests of other packages (e.g. cmdutil) that need a working *Client.

func (*Client) DebugLog

func (c *Client) DebugLog() *debug.Logger

DebugLog returns the client's debug logger.

func (*Client) Delete

func (c *Client) Delete(ctx context.Context, path string) error

Delete performs a DELETE request.

func (*Client) DoRaw

func (c *Client) DoRaw(ctx context.Context, method, path string, params url.Values, body io.Reader) (*RawResponse, error)

DoRaw performs an HTTP request and returns the raw response without parsing.

func (*Client) Get

func (c *Client) Get(ctx context.Context, path string, params url.Values, out interface{}) error

Get performs a GET request and decodes the response into out.

func (*Client) Post

func (c *Client) Post(ctx context.Context, path string, body interface{}, out interface{}) error

Post performs a POST request with a JSON body.

func (*Client) Put

func (c *Client) Put(ctx context.Context, path string, body interface{}) error

Put performs a PUT request with a JSON body.

type CustomFieldService added in v2.6.0

type CustomFieldService struct {
	// contains filtered or unexported fields
}

CustomFieldService handles custom field definition API calls. Redmine only exposes the list endpoint (admin only), so Get resolves from the list.

func (*CustomFieldService) Get added in v2.6.0

Get retrieves a single custom field definition by ID by resolving it from the list endpoint, which is the only custom-field endpoint Redmine exposes.

func (*CustomFieldService) List added in v2.6.0

List retrieves all custom field definitions.

type EnumerationService

type EnumerationService struct {
	// contains filtered or unexported fields
}

EnumerationService handles enumeration-related API calls.

func (*EnumerationService) IssuePriorities

func (s *EnumerationService) IssuePriorities(ctx context.Context) ([]models.Enumeration, error)

IssuePriorities retrieves all issue priorities.

func (*EnumerationService) TimeEntryActivities

func (s *EnumerationService) TimeEntryActivities(ctx context.Context) ([]models.Enumeration, error)

TimeEntryActivities retrieves all time entry activities.

type ErrReadOnly added in v2.10.0

type ErrReadOnly struct {
	Method string
	Path   string
}

ErrReadOnly is returned when a mutating request is attempted while the client is in read-only mode. The request is never sent.

func (*ErrReadOnly) Error added in v2.10.0

func (e *ErrReadOnly) Error() string

type FileService added in v2.6.0

type FileService struct {
	// contains filtered or unexported fields
}

FileService handles project file API calls.

func (*FileService) Create added in v2.6.0

func (s *FileService) Create(ctx context.Context, projectID string, file models.ProjectFileCreate) error

Create uploads a file to a project using a previously obtained upload token. Redmine's POST /projects/:id/files.json returns 204 No Content on success and does not echo the created resource.

func (*FileService) List added in v2.6.0

func (s *FileService) List(ctx context.Context, projectID string, limit, offset int) ([]models.ProjectFile, int, error)

List retrieves the file list for a project. The Redmine endpoint does not honour pagination parameters, so all files are returned in a single response. limit/offset are still accepted for client-side trimming via FetchAll's fallback path.

type GroupService

type GroupService struct {
	// contains filtered or unexported fields
}

GroupService handles group-related API calls.

func (*GroupService) AddUser

func (s *GroupService) AddUser(ctx context.Context, groupID, userID int) error

AddUser adds a user to a group.

func (*GroupService) Create

func (s *GroupService) Create(ctx context.Context, group models.GroupCreate) (*models.Group, error)

Create creates a new group.

func (*GroupService) Delete

func (s *GroupService) Delete(ctx context.Context, id int) error

Delete deletes a group.

func (*GroupService) Get

func (s *GroupService) Get(ctx context.Context, id int, includes []string) (*models.Group, error)

Get retrieves a single group by ID. includes can contain "users" and/or "memberships".

func (*GroupService) List

func (s *GroupService) List(ctx context.Context, filter models.GroupFilter) ([]models.Group, int, error)

List retrieves groups matching the given filter.

func (*GroupService) RemoveUser

func (s *GroupService) RemoveUser(ctx context.Context, groupID, userID int) error

RemoveUser removes a user from a group.

func (*GroupService) Update

func (s *GroupService) Update(ctx context.Context, id int, update models.GroupUpdate) error

Update updates an existing group.

type IssueService

type IssueService struct {
	// contains filtered or unexported fields
}

IssueService handles issue-related API calls.

func (*IssueService) AddWatcher added in v2.6.0

func (s *IssueService) AddWatcher(ctx context.Context, issueID, userID int) error

AddWatcher adds a user as a watcher on the given issue.

func (*IssueService) Create

func (s *IssueService) Create(ctx context.Context, issue models.IssueCreate) (*models.Issue, error)

Create creates a new issue.

func (*IssueService) Delete

func (s *IssueService) Delete(ctx context.Context, id int) error

Delete deletes an issue.

func (*IssueService) Get

func (s *IssueService) Get(ctx context.Context, id int, includes []string) (*models.Issue, error)

Get retrieves a single issue by ID.

func (*IssueService) List

func (s *IssueService) List(ctx context.Context, filter models.IssueFilter) ([]models.Issue, int, error)

List retrieves issues matching the given filter.

func (*IssueService) ListWatchers added in v2.6.0

func (s *IssueService) ListWatchers(ctx context.Context, issueID int) ([]models.IDName, error)

ListWatchers returns the watchers on the given issue. Redmine has no dedicated list endpoint; the data is fetched via include=watchers on the issue itself.

func (*IssueService) RemoveWatcher added in v2.6.0

func (s *IssueService) RemoveWatcher(ctx context.Context, issueID, userID int) error

RemoveWatcher removes a user as a watcher from the given issue.

func (*IssueService) Update

func (s *IssueService) Update(ctx context.Context, id int, update models.IssueUpdate) error

Update updates an existing issue.

type MembershipService

type MembershipService struct {
	// contains filtered or unexported fields
}

MembershipService handles membership-related API calls.

func (*MembershipService) Create

func (s *MembershipService) Create(ctx context.Context, projectID string, membership models.MembershipCreate) (*models.Membership, error)

Create creates a new membership in a project.

func (*MembershipService) Delete

func (s *MembershipService) Delete(ctx context.Context, id int) error

Delete deletes a membership.

func (*MembershipService) Get

Get retrieves a single membership by ID.

func (*MembershipService) List

func (s *MembershipService) List(ctx context.Context, projectID string, limit, offset int) ([]models.Membership, int, error)

List retrieves memberships for a project.

func (*MembershipService) Update

func (s *MembershipService) Update(ctx context.Context, id int, update models.MembershipUpdate) error

Update updates an existing membership.

type MyAccountService added in v2.6.0

type MyAccountService struct {
	// contains filtered or unexported fields
}

MyAccountService handles /my/account.json calls. Unlike /users/* it is the only user-write endpoint that does not require admin privileges, and its GET response includes api_key and custom_fields.

func (*MyAccountService) Get added in v2.6.0

func (s *MyAccountService) Get(ctx context.Context) (*models.User, error)

Get retrieves the authenticated user's account, including api_key and custom_fields.

func (*MyAccountService) Update added in v2.6.0

Update updates the authenticated user's own account.

type ProjectService

type ProjectService struct {
	// contains filtered or unexported fields
}

ProjectService handles project-related API calls.

func (*ProjectService) Archive added in v2.6.0

func (s *ProjectService) Archive(ctx context.Context, identifier string) error

Archive archives a project. Requires Redmine 5.0+.

func (*ProjectService) Create

func (s *ProjectService) Create(ctx context.Context, project models.ProjectCreate) (*models.Project, error)

Create creates a new project.

func (*ProjectService) Delete

func (s *ProjectService) Delete(ctx context.Context, identifier string) error

Delete deletes a project.

func (*ProjectService) Get

func (s *ProjectService) Get(ctx context.Context, identifier string, includes []string) (*models.Project, error)

Get retrieves a single project by identifier.

func (*ProjectService) List

func (s *ProjectService) List(ctx context.Context, includes []string, limit, offset int) ([]models.Project, int, error)

List retrieves all projects.

func (*ProjectService) Members

func (s *ProjectService) Members(ctx context.Context, identifier string, limit, offset int) ([]models.Membership, int, error)

Members retrieves project memberships.

func (*ProjectService) Unarchive added in v2.6.0

func (s *ProjectService) Unarchive(ctx context.Context, identifier string) error

Unarchive unarchives a previously-archived project. Requires Redmine 5.0+.

func (*ProjectService) Update

func (s *ProjectService) Update(ctx context.Context, identifier string, update models.ProjectUpdate) error

Update updates an existing project.

type QueryService added in v2.6.0

type QueryService struct {
	// contains filtered or unexported fields
}

QueryService handles saved-query API calls.

func (*QueryService) List added in v2.6.0

func (s *QueryService) List(ctx context.Context, limit, offset int) ([]models.SavedQuery, int, error)

List retrieves saved queries visible to the authenticated user. Redmine's /queries.json endpoint does not accept a project filter; callers receive every visible query (global plus project-specific) and can filter by the ProjectID field client-side if needed.

type RawResponse

type RawResponse struct {
	StatusCode int
	Status     string
	Headers    http.Header
	Body       []byte
}

RawResponse holds the unprocessed HTTP response from DoRaw.

type RelationService added in v2.6.0

type RelationService struct {
	// contains filtered or unexported fields
}

RelationService handles issue relation API calls.

func (*RelationService) Create added in v2.6.0

func (s *RelationService) Create(ctx context.Context, issueID int, payload models.IssueRelationCreate) (*models.IssueRelation, error)

Create creates a new relation on the given issue.

func (*RelationService) Delete added in v2.6.0

func (s *RelationService) Delete(ctx context.Context, relationID int) error

Delete removes a relation by its ID.

func (*RelationService) Get added in v2.6.0

func (s *RelationService) Get(ctx context.Context, relationID int) (*models.IssueRelation, error)

Get returns a single relation by its ID.

func (*RelationService) ListByIssue added in v2.6.0

func (s *RelationService) ListByIssue(ctx context.Context, issueID int) ([]models.IssueRelation, error)

ListByIssue returns relations attached to the given issue.

type RoleService added in v2.6.0

type RoleService struct {
	// contains filtered or unexported fields
}

RoleService handles role-related API calls.

func (*RoleService) Get added in v2.6.0

func (s *RoleService) Get(ctx context.Context, id int) (*models.Role, error)

Get retrieves a single role by ID.

func (*RoleService) List added in v2.6.0

func (s *RoleService) List(ctx context.Context) ([]models.Role, error)

List retrieves all roles.

type SearchParams

type SearchParams struct {
	Query       string
	ProjectID   string
	Scope       string // "all", "my_projects", "subprojects"
	AllWords    bool
	TitlesOnly  bool
	OpenIssues  bool
	Attachments string // "0", "1", "only"

	// Resource type filters
	Issues     bool
	News       bool
	Documents  bool
	Changesets bool
	WikiPages  bool
	Messages   bool
	Projects   bool

	Limit  int
	Offset int
}

SearchParams holds parameters for the search API call.

type SearchService

type SearchService struct {
	// contains filtered or unexported fields
}

SearchService handles the Redmine search API.

func (*SearchService) Search

func (s *SearchService) Search(ctx context.Context, params SearchParams) ([]models.SearchResult, int, error)

Search performs a search query against the Redmine search API.

type StatusService

type StatusService struct {
	// contains filtered or unexported fields
}

StatusService handles issue status API calls.

func (*StatusService) List

List retrieves all issue statuses.

type TimeEntryService

type TimeEntryService struct {
	// contains filtered or unexported fields
}

TimeEntryService handles time entry API calls.

func (*TimeEntryService) Create

Create creates a new time entry.

func (*TimeEntryService) Delete

func (s *TimeEntryService) Delete(ctx context.Context, id int) error

Delete deletes a time entry.

func (*TimeEntryService) Get

Get retrieves a single time entry.

func (*TimeEntryService) List

List retrieves time entries matching the given filter.

func (*TimeEntryService) Update

func (s *TimeEntryService) Update(ctx context.Context, id int, update models.TimeEntryUpdate) error

Update updates an existing time entry.

type TrackerService

type TrackerService struct {
	// contains filtered or unexported fields
}

TrackerService handles tracker-related API calls.

func (*TrackerService) Get added in v2.6.0

func (s *TrackerService) Get(ctx context.Context, id int) (*models.Tracker, error)

Get retrieves a single tracker by ID by resolving it from the tracker list endpoint, which is the only tracker endpoint Redmine exposes.

func (*TrackerService) List

func (s *TrackerService) List(ctx context.Context) ([]models.Tracker, error)

List retrieves all trackers.

type UserService

type UserService struct {
	// contains filtered or unexported fields
}

UserService handles user-related API calls.

func (*UserService) Create

func (s *UserService) Create(ctx context.Context, user models.UserCreate, sendInformation bool) (*models.User, error)

Create creates a new user. When sendInformation is true, the server emails the new account holder; the flag is encoded as a sibling of the "user" object, not nested inside it.

func (*UserService) Current

func (s *UserService) Current(ctx context.Context, includes []string) (*models.User, error)

Current retrieves the currently authenticated user via /users/current.json. Optional includes accept the same values as Get.

func (*UserService) Delete

func (s *UserService) Delete(ctx context.Context, id int) error

Delete deletes a user.

func (*UserService) Get

func (s *UserService) Get(ctx context.Context, id int, includes []string) (*models.User, error)

Get retrieves a single user by ID. Optional includes can request memberships and groups (Redmine 2.1+).

func (*UserService) List

func (s *UserService) List(ctx context.Context, filter models.UserFilter) ([]models.User, int, error)

List retrieves users matching the given filter.

func (*UserService) Update

func (s *UserService) Update(ctx context.Context, id int, update models.UserUpdate) error

Update updates an existing user.

type VersionService

type VersionService struct {
	// contains filtered or unexported fields
}

VersionService handles version-related API calls.

func (*VersionService) Create added in v2.4.0

func (s *VersionService) Create(ctx context.Context, projectID string, version models.VersionCreate) (*models.Version, error)

Create creates a version for a project.

func (*VersionService) Delete added in v2.4.0

func (s *VersionService) Delete(ctx context.Context, id int) error

Delete deletes a version.

func (*VersionService) Get

func (s *VersionService) Get(ctx context.Context, id int) (*models.Version, error)

Get retrieves a single version by ID.

func (*VersionService) List

func (s *VersionService) List(ctx context.Context, projectID string, limit, offset int) ([]models.Version, int, error)

List retrieves versions for a project. If limit is 0, all versions are fetched.

func (*VersionService) ListFiltered

func (s *VersionService) ListFiltered(ctx context.Context, projectID string, need int, filter func(models.Version) bool) ([]models.Version, bool, error)

ListFiltered pages through versions for a project, keeping only those that match the filter function, and returns once need results have been collected (or there are no more pages). If need is 0, all matching versions are returned. The hasMore return indicates whether additional matches may exist beyond what was collected.

func (*VersionService) Update added in v2.4.0

func (s *VersionService) Update(ctx context.Context, id int, update models.VersionUpdate) error

Update updates an existing version.

type WikiService

type WikiService struct {
	// contains filtered or unexported fields
}

WikiService handles wiki-related API calls.

func (*WikiService) Create

func (s *WikiService) Create(ctx context.Context, projectID, page string, wiki models.WikiPageCreate) (*models.WikiPage, error)

Create creates a new wiki page (or overwrites an existing one).

func (*WikiService) Delete

func (s *WikiService) Delete(ctx context.Context, projectID, page string) error

Delete deletes a wiki page.

func (*WikiService) Get

func (s *WikiService) Get(ctx context.Context, projectID, page string, includes []string) (*models.WikiPage, error)

Get retrieves a single wiki page by title.

func (*WikiService) GetVersion

func (s *WikiService) GetVersion(ctx context.Context, projectID, page string, version int) (*models.WikiPage, error)

GetVersion retrieves a specific version of a wiki page.

func (*WikiService) List

func (s *WikiService) List(ctx context.Context, projectID string, limit, offset int) ([]models.WikiPageIndex, int, error)

List retrieves the wiki page index for a project.

func (*WikiService) Update

func (s *WikiService) Update(ctx context.Context, projectID, page string, update models.WikiPageUpdate) error

Update updates an existing wiki page.

Jump to

Keyboard shortcuts

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