redmine

package module
v0.0.0-...-5614f12 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2025 License: MIT Imports: 10 Imported by: 0

README

redmine

Go module for Redmine API

Go Reference Go Report Card

Documentation

Overview

Package redmine implements the Redmine API *

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	ErrServerEmpty         = errors.New("server is empty")
	ErrUserEmpty           = errors.New("user is empty")
	ErrPasswordEmpty       = errors.New("password is empty")
	ErrLoginEmpty          = errors.New("login is empty")
	ErrFirstnameEmpty      = errors.New("firstname is empty")
	ErrLastnameEmpty       = errors.New("lastname is empty")
	ErrMailEmpty           = errors.New("mail is empty")
	ErrIDEmpty             = errors.New("id is empty")
	ErrForbidden           = errors.New("403 Forbidden")
	ErrUnprocessableEntity = errors.New("422 Unprocessable Entity")
)
View Source
var ErrProjectNotFound = errors.New("project not found")

Functions

func ParseParameters

func ParseParameters(params ...Parameter) string

Types

type AuthKey

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

AuthKey is authenticates to Redmine using the API key passed in as a username with a random password via HTTP Basic Auth

func (*AuthKey) Impersonate

func (ak *AuthKey) Impersonate(name string)

func (*AuthKey) Request

func (ak *AuthKey) Request(method string, url string, body any) (int, []byte, error)

type Authenticator

type Authenticator interface {

	// Request create and do a new request to url with method method.
	//
	// The body parameter is a pointer to any struct.
	// If body is not nil, then marshalled to JSON and use it in the new request's body.
	//
	// Returns the status code and the body bytes.
	Request(method string, url string, body any) (int, []byte, error)

	Impersonate(name string)
}

type Author

type Author struct {
	ID   int    `json:"id"`
	Name string `json:"name"`
}

type Category

type Category struct {
	ID   int    `json:"id"`
	Name string `json:"name"`
}

type CustomField

type CustomField struct {
	ID    int    `json:"id"`
	Name  string `json:"name"`
	Value string `json:"value"`
}

type Group

type Group struct {
	ID   int    `json:"id,omitempty" yaml:"id,omitempty"`
	Name string `json:"name,omitempty" yaml:"name,omitempty"`
}

type HeaderKey

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

HeaderKey is authenticates to Redmine using the API key passed in "X-Redmine-API-Key" HTTP header.

func (*HeaderKey) Impersonate

func (hk *HeaderKey) Impersonate(name string)

func (*HeaderKey) Request

func (hk *HeaderKey) Request(method string, url string, body any) (int, []byte, error)

type Issue

type Issue struct {
	ID                  int           `json:"id,omitempty" yaml:"id,omitempty"`
	Project             *Project      `json:"project,omitempty" yaml:"project,omitempty"`
	Tracker             *Tracker      `json:"tracker,omitempty" yaml:"tracker,omitempty"`
	Status              *IssueStatus  `json:"status,omitempty" yaml:"status,omitempty"`
	Priority            *Priority     `json:"priority,omitempty" yaml:"priority,omitempty"`
	Author              *Author       `json:"author,omitempty" yaml:"author,omitempty"`
	AssignedTo          *User         `json:"assigned_to,omitempty" yaml:"assigned_to,omitempty"`
	Category            *Category     `json:"category,omitempty" yaml:"category,omitempty"`
	Subject             string        `json:"subject,omitempty" yaml:"subject,omitempty"`
	Description         string        `json:"description,omitempty" yaml:"description,omitempty"`
	StartDate           string        `json:"start_date,omitempty" yaml:"start_date,omitempty"`
	DueDate             string        `json:"due_date,omitempty" yaml:"due_date,omitempty"`
	DoneRation          int           `json:"done_ratio,omitempty" yaml:"done_ratio,omitempty"`
	IsPrivate           bool          `json:"is_private,omitempty" yaml:"is_private,omitempty"`
	SpentHours          float64       `json:"spent_hours,omitempty" yaml:"spent_hours,omitempty"`
	TotalSpentHours     float64       `json:"total_spent_hours,omitempty" yaml:"total_spent_hours,omitempty"`
	CreatedOn           *time.Time    `json:"created_on,omitempty" yaml:"created_on,omitempty"`
	UpdatedOn           *time.Time    `json:"updated_on,omitempty" yaml:"updated_on,omitempty"`
	ClosedOn            *time.Time    `json:"closed_on,omitempty" yaml:",omitempty"`
	CustomFields        []CustomField `json:"custom_fields,omitempty" yaml:"custom_fields,omitempty"`
	EstimatedHours      float64       `json:"estimated_hours,omitempty" yaml:"estimated_hours,omitempty"`
	TotalEstimatedHours float64       `json:"total_estimated_hours,omitempty" yaml:"total_estimated_hours,omitempty"`
}

func (*Issue) JSON

func (i *Issue) JSON() string

func (*Issue) String

func (i *Issue) String() string

func (*Issue) YAML

func (i *Issue) YAML() string

type IssueStatus

type IssueStatus struct {
	ID          int    `json:"id,omitempty" yaml:"id,omitempty"`
	Name        string `json:"name,omitempty" yaml:"name,omitempty"`
	IsClosed    bool   `json:"is_closed,omitempty" yaml:"is_closed,omitempty"`
	Description string `json:"description,omitempty" yaml:"description,omitempty"`
}

type IssueStatuses

type IssueStatuses []IssueStatus

func (*IssueStatuses) Names

func (is *IssueStatuses) Names() []string

type Issues

type Issues struct {
	Issues     []Issue `json:"issues,omitempty" yaml:"issues,omitempty"`
	TotalCount int     `json:"total_count,omitempty" yaml:"total_count,omitempty"`
	Offset     int     `json:"offset,omitempty" yaml:"offset,omitempty"`
	Limit      int     `json:"limit,omitempty" yaml:"limit,omitempty"`
}
Example
package main

import (
	"fmt"

	"gorbe.io/go/redmine"
)

func main() {

	issues, err := redmine.NewPublic("https://www.redmine.org").Issues()
	if err != nil {
		// handle error
	}

	fmt.Printf("%#v", issues)
}
Example (WithParameter)
package main

import (
	"fmt"

	"gorbe.io/go/redmine"
)

func main() {

	issues, err := redmine.NewPublic("https://www.redmine.org").Issues(redmine.OffsetParameter(100), redmine.LimitParameter(100))
	if err != nil {
		// handle error
	}

	fmt.Printf("%#v", issues)
}

func (*Issues) JSON

func (i *Issues) JSON() string

JSON encodes Issues to JSON.

If marshaling fails for any reason, this function panics.

func (*Issues) String

func (i *Issues) String() string

func (*Issues) YAML

func (i *Issues) YAML() string

YAML encodes Issues to YAML.

If marshaling fails for any reason, this function panics.

type MailNotification

type MailNotification string
const (
	MailNotificationAll  MailNotification = "all"
	MailNotificationNone MailNotification = "none"
)

func (MailNotification) String

func (m MailNotification) String() string

type Membership

type Membership struct {
	Id      int      `json:"id,omitempty" yaml:"id,omitempty"`
	Project *Project `json:"project,omitempty" yaml:"project,omitempty"`
	User    *User    `json:"user,omitempty" yaml:"user,omitempty"`
	Roles   []Role   `json:"roles,omitempty" yaml:"roles,omitempty"`
}

type Parameter

type Parameter struct {
	Field string
	Value string
}

func GroupIDFilter

func GroupIDFilter(v int) Parameter

func IncludeParameter

func IncludeParameter(v []string) Parameter

func IssueIDFilter

func IssueIDFilter(v int) Parameter

func LimitParameter

func LimitParameter(v int) Parameter

func NameParameter

func NameParameter(v string) Parameter

func OffsetParameter

func OffsetParameter(v int) Parameter

func ProjectIDFilter

func ProjectIDFilter(v int) Parameter

func StatusAllFilter

func StatusAllFilter() Parameter

func StatusFilter

func StatusFilter(v int) Parameter

func StatusIDFilter

func StatusIDFilter(v int) Parameter

func (Parameter) String

func (p Parameter) String() string

type Priorities

type Priorities []Priority

func (*Priorities) Names

func (p *Priorities) Names() []string

type Priority

type Priority struct {
	ID        int    `json:"id"`
	Name      string `json:"name"`
	IsDefault bool   `json:"is_default"`
}

type Project

type Project struct {
	ID          int       `json:"id,omitempty" yaml:"id,omitempty"`
	Name        string    `json:"name,omitempty" yaml:"name,omitempty"`
	Identifier  string    `json:"identifier,omitempty" yaml:"identifier,omitempty"`
	Description string    `json:"description,omitempty" yaml:"description,omitempty"`
	CreatedOn   time.Time `json:"created_on,omitempty" yaml:"created_on,omitempty"`
	UpdatedOn   time.Time `json:"updated_on,omitempty" yaml:"updated_on,omitempty"`
	IsPublic    bool      `json:"is_public,omitempty" yaml:"is_public,omitempty"`
	Homepage    string    `json:"homepage,omitempty" yaml:"homepage,omitempty"`
}

TODO: Parent Project

type Projects

type Projects struct {
	Projects   []Project `json:"projects,omitempty" yaml:"projects,omitempty"`
	TotalCount int       `json:"total_count,omitempty" yaml:"total_count,omitempty"`
	Offset     int       `json:"offset,omitempty" yaml:"offset,omitempty"`
	Limit      int       `json:"limit,omitempty" yaml:"limit,omitempty"`
}
Example
package main

import (
	"fmt"

	"gorbe.io/go/redmine"
)

func main() {

	v, err := redmine.NewPublic("https://www.redmine.org").Projects()
	if err != nil {
		// handle error
	}

	fmt.Printf("%v\n", v.Identifiers())
}

func (*Projects) Identifiers

func (p *Projects) Identifiers() []string

Identifiers returns a slice of projects identifier.

type Public

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

Public is an instance of a public Redmine server (eg.: www.redmine.org).

func (*Public) Impersonate

func (p *Public) Impersonate(name string)

func (*Public) Request

func (p *Public) Request(method string, url string, body any) (int, []byte, error)

Request implements the Authenticator interface for Public.

type Redmine

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

func NewAuthKey

func NewAuthKey(server, key string) *Redmine
Example
package main

import (
	"gorbe.io/go/redmine"
)

func main() {

	_ = redmine.NewAuthKey("https://www.redmine.org", "apikey")

}

func NewHeaderKey

func NewHeaderKey(server, key string) *Redmine
Example
package main

import (
	"gorbe.io/go/redmine"
)

func main() {

	_ = redmine.NewHeaderKey("https://www.redmine.org", "apikey")

}

func NewPublic

func NewPublic(server string) *Redmine
Example
package main

import (
	"gorbe.io/go/redmine"
)

func main() {

	_ = redmine.NewPublic("https://www.redmine.org")

}

func NewRegularLogin

func NewRegularLogin(server, login, password string) *Redmine

NewRegularLogin creates a RegularLogin instance.

If the parameter "become" is set to a username, then the request includes the "X-Redmine-Switch-User: user" header to impersonate the given user.

Example
package main

import (
	"gorbe.io/go/redmine"
)

func main() {

	_ = redmine.NewRegularLogin("https://www.redmine.org", "admin1", "password")

}

func (*Redmine) CreateIssue

func (r *Redmine) CreateIssue(i *Issue) error

CreateIssue creates a new Issue.

If Issue is created, the underlying data of iss will be replaced by the returned Issue.

func (*Redmine) CreateUser

func (r *Redmine) CreateUser(u *User, notify bool) error

CreateUser creates a new user.

Required fields: Login, Firstname, Lastname and Mail

If notify is true, sends account information to the user. If user created, the underlying data of u will be replaced by the returned user.

func (*Redmine) DeleteUser

func (r *Redmine) DeleteUser(id int) error

DeleteUser remves a user with the given id.

func (*Redmine) Impersonate

func (r *Redmine) Impersonate(name string)

func (*Redmine) Issue

func (r *Redmine) Issue(id int) (*Issue, error)

func (*Redmine) IssueStatusWithName

func (r *Redmine) IssueStatusWithName(name string) (*IssueStatus, error)

IssueStatusWithName returns the IssueStatus with the given Name. If no IssueStatus found with Name name, returns nil.

func (*Redmine) IssueStatuses

func (r *Redmine) IssueStatuses(params ...Parameter) (IssueStatuses, error)

func (*Redmine) Issues

func (r *Redmine) Issues(params ...Parameter) (*Issues, error)

func (*Redmine) Priorities

func (r *Redmine) Priorities(params ...Parameter) (Priorities, error)

func (*Redmine) PriorityWithName

func (r *Redmine) PriorityWithName(name string) (*Priority, error)

PriorityWithName returns the Priority with the given Name. If no Priority found with Name name, returns nil.

func (*Redmine) ProjectWithIdentifier

func (r *Redmine) ProjectWithIdentifier(identifier string) (*Project, error)

ProjectWithIdentifier returns the Project with the given Identifier identifier.

If no project found with the given identifier returns ErrProjectNotFound.

func (*Redmine) Projects

func (r *Redmine) Projects(params ...Parameter) (*Projects, error)

func (*Redmine) TrackerWithName

func (r *Redmine) TrackerWithName(name string) (*Tracker, error)

TrackerWithName returns the Tracker with the given Name. If no Tracker found with Name name, returns nil.

func (*Redmine) Trackers

func (r *Redmine) Trackers(params ...Parameter) (Trackers, error)

func (*Redmine) UpdateUser

func (r *Redmine) UpdateUser(u *User, notify bool) error

UpdateUser modify a user.

Required fields: ID, Login, Firstname, Lastname and Mail

If notify is true, sends account information to the user.

func (*Redmine) User

func (r *Redmine) User(id int, params ...Parameter) (User, error)

If id is 0, then returns the current user

func (*Redmine) UserWithLogin

func (r *Redmine) UserWithLogin(login string) (*User, error)

UserWithName returns the User with the given Name. If no User found with Name name, returns nil.

func (*Redmine) Users

func (r *Redmine) Users(params ...Parameter) (*Users, error)

type RegularLogin

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

RegularLogin is authenticates to Redmine with the user's login and password via HTTP Basic Auth.

func (*RegularLogin) Impersonate

func (rl *RegularLogin) Impersonate(name string)

func (*RegularLogin) Request

func (rl *RegularLogin) Request(method string, url string, body any) (int, []byte, error)

type Role

type Role struct {
	ID   int    `json:"id,omitempty" yaml:"id,omitempty"`
	Name string `json:"name,omitempty" yaml:"name,omitempty"`
}

type Tracker

type Tracker struct {
	ID                    int         `json:"id,omitempty" yaml:"id,omitempty"`
	Name                  string      `json:"name,omitempty" yaml:"name,omitempty"`
	DefaultStatus         IssueStatus `json:"default_status,omitempty" yaml:"default_status,omitempty"`
	Description           string      `json:"description,omitempty" yaml:"description,omitempty"`
	EnabledStandardFields []string    `json:"enabled_standard_fields,omitempty" yaml:"enabled_standard_fields,omitempty"`
}

type Trackers

type Trackers []Tracker

func (*Trackers) Names

func (t *Trackers) Names() []string

type User

type User struct {
	ID              int           `json:"id,omitempty" yaml:"id,omitempty"`
	Login           string        `json:"login,omitempty" yaml:"login,omitempty"`
	Password        string        `json:"password,omitempty" yaml:"password,omitempty"`
	Admin           bool          `json:"admin,omitempty" yaml:"admin,omitempty"`
	FirstName       string        `json:"firstname,omitempty" yaml:"firstname,omitempty"`
	LastName        string        `json:"lastname,omitempty" yaml:"lastname,omitempty"`
	Mail            string        `json:"mail,omitempty" yaml:"mail,omitempty"`
	CreatedOn       time.Time     `json:"created_on,omitempty" yaml:"created_on,omitempty"`
	UpdatedOn       time.Time     `json:"updated_on,omitempty" yaml:"updated_on,omitempty"`
	LastLoginOn     time.Time     `json:"last_login_on,omitempty" yaml:"last_login_on,omitempty"`
	PasswdChangedOn time.Time     `json:"passwd_changed_on,omitempty" yaml:"passwd_changed_on,omitempty"`
	TwoFAScheme     string        `json:"twofa_scheme,omitempty" yaml:"twofa_scheme,omitempty"`
	ApiKey          string        `json:"api_key,omitempty" yaml:"api_key,omitempty"`
	AvatarURL       string        `json:"avatar_url,omitempty" yaml:"avatar_url,omitempty"`
	Status          UserStatus    `json:"status,omitempty" yaml:"status,omitempty"`
	CustomField     []CustomField `json:"custom_fields,omitempty" yaml:"custom_fields,omitempty"`
	Groups          []Group       `json:"groups,omitempty" yaml:"groups,omitempty"`
	Memberships     []Membership  `json:"memberships,omitempty" yaml:"memberships,omitempty"`

	// CreateUser fields
	AuthSourceId       int              `json:"auth_source_id,omitempty" yaml:"auth_source_id,omitempty"`
	MailNotification   MailNotification `json:"mail_notification,omitempty" yaml:"mail_notification,omitempty"`
	MustChangePassword bool             `json:"must_change_passwd,omitempty" yaml:"must_change_passwd,omitempty"`
	GeneratePassword   bool             `json:"generate_password,omitempty" yaml:"generate_password,omitempty"`
}

func (User) JSON

func (u User) JSON() string

func (User) String

func (u User) String() string

func (User) YAML

func (u User) YAML() string

type UserStatus

type UserStatus int
const (
	UserActive     UserStatus = 1
	UserRegistered UserStatus = 2
	UserLocked     UserStatus = 3
)

func ParseUserStatus

func ParseUserStatus(v string) UserStatus

ParseUserStatus converts user status string v to UserStatus. Returns -1 if v is not a valid user status.

func (UserStatus) String

func (us UserStatus) String() string

type Users

type Users struct {
	Users      []User `json:"users,omitempty" yaml:"users,omitempty"`
	TotalCount int    `json:"total_count,omitempty" yaml:"total_count,omitempty"`
	Offset     int    `json:"offset,omitempty" yaml:"offset,omitempty"`
	Limit      int    `json:"limit,omitempty" yaml:"limit,omitempty"`
}
Example
package main

import (
	"fmt"

	"gorbe.io/go/redmine"
)

func main() {

	users, err := redmine.NewPublic("https://www.redmine.org").Users()
	if err != nil {
		// handle error
	}

	fmt.Printf("%#v", users)
}
Example (WithParams)
package main

import (
	"fmt"

	"gorbe.io/go/redmine"
)

func main() {

	users, err := redmine.NewPublic("https://www.redmine.org").Users(redmine.NameParameter("tester"))
	if err != nil {
		// handle error
	}

	fmt.Printf("%#v", users)
}

func (*Users) JSON

func (u *Users) JSON() string

JSON encodes Users to JSON.

If marshaling fails for any reason, this function panics.

func (*Users) Logins

func (u *Users) Logins() []string

Logins returns a slice of users login names.

func (*Users) String

func (u *Users) String() string

func (*Users) YAML

func (u *Users) YAML() string

YAML encodes Users to YAML.

If marshaling fails for any reason, this function panics.

Jump to

Keyboard shortcuts

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