redmine

package module
v0.0.0-...-5c1d091 Latest Latest
Warning

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

Go to latest
Published: May 1, 2024 License: MIT Imports: 9 Imported by: 0

README

go-redmine

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")
)

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) 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)
}

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"`
	Name string `json:"name"`
}

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) Request

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

type Issue

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

func (*Issue) String

func (i *Issue) String() 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)
}
Output:

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)
}
Output:

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 {
	Project Project `json:"project"`
	Roles   []Role  `json:"roles"`
}

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 StatusFilter

func StatusFilter(v int) Parameter

func StatusIDFilter

func StatusIDFilter(v int) Parameter

func (Parameter) String

func (p Parameter) String() string

type Priority

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

type Project

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

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())
}
Output:

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) 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, become string) *Redmine
Example
package main

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

func main() {

	// User of apikey impersonates admin2 if user is admin
	_ = redmine.NewAuthKey("https://www.redmine.org", "apikey", "admin2")

}
Output:

func NewHeaderKey

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

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

func main() {

	// User of apikey impersonates admin2 if user is admin
	_ = redmine.NewHeaderKey("https://www.redmine.org", "apikey", "admin2")

}
Output:

func NewPublic

func NewPublic(server string) *Redmine
Example
package main

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

func main() {

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

}
Output:

func NewRegularLogin

func NewRegularLogin(server, login, password, become 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() {

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

}
Output:

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) Issue

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

func (*Redmine) Issues

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

func (*Redmine) ProjectWithIdentifier

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

ProjectWithIdentifier returns the Project with the given Identifier identifier. If no project found, returns nil.

func (*Redmine) Projects

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

func (*Redmine) Trackers

func (r *Redmine) Trackers() (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) (User, error)

If id is 0, then returns the current user

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) Request

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

type Role

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

type Status

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

type Tracker

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

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"`

	// 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)
}
Output:

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)
}
Output:

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