redmine4go

package module
v0.0.0-...-11b522b Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2021 License: MIT Imports: 7 Imported by: 0

README

Redmine API in Go

This library (in progress) supports most if not all of the Redmine REST calls.

GoDoc lint

Redmine API Reference for details of parameters

Interfaces

API Coverage Functions Remark
Issues 100%
- GetIssues()
- GetIssue()
- CreateIssue()
- UpdateIssue()
- DeleteIssue()
- AddWatcher()
- RemoveWatcher()
Projects 100%
- GetProjects()
- GetProject()
- CreateProject()
- UpdateProject()
- ArchiveProject() Only available since Redmine 5.0
- UnarchiveProject() Only available since Redmine 5.0
- DeleteProject()
Project Memberships 20%
- GetProjectMemberships()

Installation

go get
$ go get -u github.com/emailquangto/redmine4go

Example


CRUD of issues using protocol scheme JSON
package main

import (
	"fmt"
	"os"

	"github.com/emailquangto/redmine4go"
	"github.com/joho/godotenv"
)

func main() {
	godotenv.Load("../.env")

	baseURL := os.Getenv("BASE_URL")
	apiKey := os.Getenv("API_KEY")
	apiFormat := os.Getenv("API_FORMAT")
	projectId := os.Getenv("PROJECT_ID")

	c := redmine4go.CreateClient(baseURL, apiKey, apiFormat)

	// default parameters of querying issues
	paras := &redmine4go.IssueListParameter{
		Offset:  nil, // = 0
		Limit:   nil, // = 25
		Sort:    "",  // Default
		Include: "",  // None
	}

	// get list of open issues
	// default filters of querying issues
	filters := &redmine4go.IssueListFilter{
		IssueId:      nil, // an integer
		ProjectId:    nil, // an integer or "project-name"
		SubprojectId: nil, // an integer or "sub-project-name"
		TrackerId:    nil, // an integer
		StatusId:     nil, // an integer or "status-name"
		AssignedToId: nil, // an integer or "member-name"
		ParentId:     nil, // an integer
	}
	issueList, error := c.GetIssues(paras, filters)
	if error == nil {
		fmt.Printf("%s\n", "=====get list of open issues=====")
		fmt.Printf("Number of issues = %d\n", issueList.TotalCount)
		if issueList.TotalCount > 0 {
			fmt.Printf("issue 1 - Project = %s\n", issueList.Issues[0].Project.Name)
			fmt.Printf("issue 1 - ID = %d\n", issueList.Issues[0].ID)
			fmt.Printf("issue 1 - Subject = %s\n", issueList.Issues[0].Subject)
			fmt.Printf("issue 1 - Status = %s\n", issueList.Issues[0].Status.Name)
			fmt.Printf("issue 1 - Author = %s\n", issueList.Issues[0].Author.Name)
			fmt.Printf("issue 1 - Assigned To = %s\n", issueList.Issues[0].AssignedTo.Name)
		}
	} else {
		fmt.Printf("%s\n", error)
	}

	// get list of open issues of a project
	// filters of querying issues
	filters = &redmine4go.IssueListFilter{
		IssueId:      nil,
		ProjectId:    projectId,
		SubprojectId: nil,
		TrackerId:    nil,
		StatusId:     nil,
		AssignedToId: nil,
		ParentId:     nil,
	}
	issueList, error = c.GetIssues(paras, filters)
	if error == nil {
		fmt.Printf("%s\n", "=====get list of open issues of a project=====")
		fmt.Printf("Number of issues = %d\n", issueList.TotalCount)
		if issueList.TotalCount > 0 {
			fmt.Printf("issue 1 - Project = %s\n", issueList.Issues[0].Project.Name)
			fmt.Printf("issue 1 - ID = %d\n", issueList.Issues[0].ID)
			fmt.Printf("issue 1 - Subject = %s\n", issueList.Issues[0].Subject)
			fmt.Printf("issue 1 - Status = %s\n", issueList.Issues[0].Status.Name)
			fmt.Printf("issue 1 - Author = %s\n", issueList.Issues[0].Author.Name)
			fmt.Printf("issue 1 - Assigned To = %s\n", issueList.Issues[0].AssignedTo.Name)
		}
	} else {
		fmt.Printf("%s\n", error)
	}

	// get details of an issue
	issueId := 13430
	include := "" // children, attachments, relations, changesets, journals, watchers, allowed_statuses
	issue, error := c.GetIssue(issueId, include)
	if error == nil {
		fmt.Printf("%s\n", "=====get details of an issue=====")
		fmt.Printf("issue - Project = %s\n", issue.Project.Name)
		fmt.Printf("issue - ID = %d\n", issue.ID)
		fmt.Printf("issue - Subject = %s\n", issue.Subject)
		fmt.Printf("issue - Status = %s\n", issue.Status.Name)
		fmt.Printf("issue - Author = %s\n", issue.Author.Name)
		fmt.Printf("issue - Assigned To = %s\n", issue.AssignedTo.Name)

	} else {
		fmt.Printf("%s\n", error)
	}

	// create a new issue
	issueNew := redmine4go.IssueToSend{
		Project:     16,
		Tracker:     1,
		Status:      1,
		Priority:    2,
		Subject:     "a new issue auto-posted from redmine4go",
		Description: "testing CreateIssue() of Redmine API in Go",
	}
	issueNewWrapper := redmine4go.IssueToSendWrapper{Issue: issueNew}
	issueNewReturn, error := c.CreateIssue(issueNewWrapper)
	if error == nil {
		fmt.Printf("%s\n", "=====create a new issue=====")
		fmt.Printf("issue - Project = %s\n", issueNewReturn.Project.Name)
		fmt.Printf("issue - ID = %d\n", issueNewReturn.ID)
		fmt.Printf("issue - Subject = %s\n", issueNewReturn.Subject)
		fmt.Printf("issue - Status = %s\n", issueNewReturn.Status.Name)
		fmt.Printf("issue - Author = %s\n", issueNewReturn.Author.Name)
		fmt.Printf("issue - Assigned To = %s\n", issueNewReturn.AssignedTo.Name)

	} else {
		fmt.Printf("%s\n", error)
	}

	// update an issue
	issueUpdateWrapper := redmine4go.IssueToSendWrapper{Issue: redmine4go.IssueToSend{
		Status:      2,
		Priority:    1,
		Subject:     "from code",
		Description: "code changed",
	}}
	error = c.UpdateIssue(issueNewReturn.ID, issueUpdateWrapper)
	if error == nil {
		fmt.Printf("%s\n", "=====update an issue=====")
		// get details of updated issue
		include := ""
		issue, error := c.GetIssue(issueNewReturn.ID, include)
		if error == nil {
			fmt.Printf("%s\n", "**details of updated issue**")
			fmt.Printf("issue - Project = %s\n", issue.Project.Name)
			fmt.Printf("issue - ID = %d\n", issue.ID)
			fmt.Printf("issue - Status updated = %s\n", issue.Status.Name)
			fmt.Printf("issue - Priority updated = %s\n", issue.Priority.Name)
			fmt.Printf("issue - Subject updated = %s\n", issue.Subject)
			fmt.Printf("issue - Description updated = %s\n", issue.Description)
			fmt.Printf("issue - Author = %s\n", issue.Author.Name)
			fmt.Printf("issue - Assigned To = %s\n", issue.AssignedTo.Name)
		} else {
			fmt.Printf("%s\n", error)
		}
	}

	// delete an issue
	error = c.DeleteIssue(issueNewReturn.ID)
	if error == nil {
		fmt.Printf("%s\n", "=====delete an issue=====")
		fmt.Printf("issue %d deleted", issueNewReturn.ID)
	} else {
		fmt.Printf("%s\n", error)
	}

}
See more examples under examples folder.

License


MIT License

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BriefInfo

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

type Client

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

A Client stores the client information and implement all the api functions to communicate with redmine

func CreateClient

func CreateClient(url, key, format string) (c *Client)

CreateClient returns a client with the given credential for the given redmine domain

func (*Client) AddWatcher

func (c *Client) AddWatcher(issueId int, watcher Watcher) error

AddWatcher() adds a watch to an issue from protocol scheme JSON Ref: https://www.redmine.org/projects/redmine/wiki/Rest_Issues#Adding-a-watcher

func (*Client) ArchiveProject

func (c *Client) ArchiveProject(projectIdOrName interface{}) error

ArchiveProject() archives the project of given id or identifier from protocol scheme JSON Ref: https://www.redmine.org/projects/redmine/wiki/Rest_Projects#Archiving-a-project

func (*Client) CreateIssue

func (c *Client) CreateIssue(issueNewWrapper IssueToSendWrapper) (Issue, error)

CreateIssue() creates a new issue with given parameters from protocol scheme JSON Ref: https://www.redmine.org/projects/redmine/wiki/Rest_Issues#Creating-an-issue

func (*Client) CreateProject

func (c *Client) CreateProject(projectNewWrapper ProjectToSendWrapper) (Project, error)

CreateProject() creates a new project with given parameters from protocol scheme JSON Ref: https://www.redmine.org/projects/redmine/wiki/Rest_Projects#Creating-a-project

func (*Client) DeleteIssue

func (c *Client) DeleteIssue(issueId int) error

DeleteIssue() deletes an issue from protocol scheme JSON Ref: https://www.redmine.org/projects/redmine/wiki/Rest_Issues#Deleting-an-issue

func (*Client) DeleteProject

func (c *Client) DeleteProject(projectIdOrName interface{}) error

DeleteProject() deletes the project of given id or identifier from protocol scheme JSON Ref: https://www.redmine.org/projects/redmine/wiki/Rest_Projects#Deleting-a-project

func (*Client) GetIssue

func (c *Client) GetIssue(issueId int, parameters string) (Issue, error)

GetIssue() returns details of an issue with given parameters from protocol scheme JSON Ref: https://www.redmine.org/projects/redmine/wiki/Rest_Issues#Showing-an-issue

func (*Client) GetIssues

func (c *Client) GetIssues(para *IssueListParameter, filter *IssueListFilter) (IssueList, error)

GetIssues() returns a paginated list of issues with given parameters and filters. By default, it returns open issues only from protocol scheme JSON Ref: https://www.redmine.org/projects/redmine/wiki/Rest_Issues#Listing-issues

func (*Client) GetProject

func (c *Client) GetProject(projectIdOrName interface{}, parameters string) (Project, error)

GetProject() returns details of a project with given parameters from protocol scheme JSON Ref: https://www.redmine.org/projects/redmine/wiki/Rest_Projects#Showing-a-project

func (*Client) GetProjectMemberships

func (c *Client) GetProjectMemberships(projectIdOrName interface{}) (ProjectMembership, error)

GetProjects() Returns a paginated list of the project memberships project_id can be either the project numerical id or the project identifier from protocol scheme JSON Ref: https://www.redmine.org/projects/redmine/wiki/Rest_Memberships#Project-Memberships

func (*Client) GetProjects

func (c *Client) GetProjects(parameters string) (ProjectList, error)

GetProjects() returns all projects (all public projects and private projects where user have access to) with given parameters from protocol scheme JSON Ref: https://www.redmine.org/projects/redmine/wiki/Rest_Projects#Listing-projects

func (*Client) RemoveWatcher

func (c *Client) RemoveWatcher(issueId, userId int) error

RemoveWatcher() removes a watcher from an issue from protocol scheme JSON Ref: https://www.redmine.org/projects/redmine/wiki/Rest_Issues#Removing-a-watcher

func (*Client) UnarchiveProject

func (c *Client) UnarchiveProject(projectIdOrName interface{}) error

UnarchiveProject() unarchives the project of given id or identifier from protocol scheme JSON Ref: https://www.redmine.org/projects/redmine/wiki/Rest_Projects#Unarchiving-a-project

func (*Client) UpdateIssue

func (c *Client) UpdateIssue(issueId int, issueUpdateWrapper IssueToSendWrapper) error

UpdateIssue() updates an issue with given parameters from protocol scheme JSON Ref: https://www.redmine.org/projects/redmine/wiki/Rest_Issues#Updating-an-issue

func (*Client) UpdateProject

func (c *Client) UpdateProject(projectIdOrName interface{}, projectWrapper ProjectWrapper) error

UpdateProject() updates a project with given parameters from protocol scheme JSON Ref: https://www.redmine.org/projects/redmine/wiki/Rest_Projects#Updating-a-project

type CustomFields

type CustomFields struct {
	ID       int         `json:"id"`
	Name     string      `json:"name"`
	Value    interface{} `json:"value"`
	Multiple bool        `json:"multiple,omitempty"`
}

type Issue

type Issue struct {
	ID                  int         `json:"id"`
	Project             BriefInfo   `json:"project"`
	Tracker             BriefInfo   `json:"tracker"`
	Status              BriefInfo   `json:"status"`
	Priority            BriefInfo   `json:"priority"`
	Author              BriefInfo   `json:"author"`
	AssignedTo          BriefInfo   `json:"assigned_to,omitempty"`
	Parent              Parent      `json:"parent,omitempty"`
	Subject             string      `json:"subject"`
	Description         string      `json:"description"`
	StartDate           string      `json:"start_date"`
	DueDate             string      `json:"due_date"`
	DoneRatio           int         `json:"done_ratio"`
	IsPrivate           bool        `json:"is_private"`
	EstimatedHours      interface{} `json:"estimated_hours"`
	TotalEstimatedHours interface{} `json:"total_estimated_hours"`
	SpentHours          interface{} `json:"spent_hours"`
	TotalSpentHours     interface{} `json:"total_spent_hours"`
	CreatedOn           time.Time   `json:"created_on"`
	UpdatedOn           time.Time   `json:"updated_on"`
	ClosedOn            interface{} `json:"closed_on"`
}

type IssueList

type IssueList struct {
	Issues     []Issue `json:"issues"`
	TotalCount int     `json:"total_count"`
	Offset     int     `json:"offset"`
	Limit      int     `json:"limit"`
}

type IssueListFilter

type IssueListFilter struct {
	IssueId      interface{}
	ProjectId    interface{}
	SubprojectId interface{}
	TrackerId    interface{}
	StatusId     interface{}
	AssignedToId interface{}
	ParentId     interface{}
}

type IssueListParameter

type IssueListParameter struct {
	Offset  interface{}
	Limit   interface{}
	Sort    string
	Include string
}

type IssueToSend

type IssueToSend struct {
	Project     int    `json:"project_id"`
	Tracker     int    `json:"tracker_id"`
	Status      int    `json:"status_id"`
	Priority    int    `json:"priority_id"`
	Subject     string `json:"subject"`
	Description string `json:"description"`
}

type IssueToSendWrapper

type IssueToSendWrapper struct {
	Issue IssueToSend `json:"issue"`
}

type IssueWrapper

type IssueWrapper struct {
	Issue Issue `json:"issue"`
}

type Membership

type Membership struct {
	ID      int         `json:"id"`
	Project BriefInfo   `json:"project"`
	User    BriefInfo   `json:"user"`
	Roles   []BriefInfo `json:"roles"`
}

type Parent

type Parent struct {
	ID int `json:"id"`
}

type Project

type Project struct {
	ID             int            `json:"id"`
	Name           string         `json:"name"`
	Identifier     string         `json:"identifier"`
	Description    string         `json:"description"`
	Status         int            `json:"status"`
	IsPublic       bool           `json:"is_public"`
	InheritMembers bool           `json:"inherit_members"`
	CustomFields   []CustomFields `json:"custom_fields"`
	CreatedOn      time.Time      `json:"created_on"`
	UpdatedOn      time.Time      `json:"updated_on"`
}

type ProjectList

type ProjectList struct {
	Projects   []Project `json:"projects"`
	TotalCount int       `json:"total_count"`
	Offset     int       `json:"offset"`
	Limit      int       `json:"limit"`
}

type ProjectMembership

type ProjectMembership struct {
	Memberships []Membership `json:"memberships"`
	TotalCount  int          `json:"total_count"`
	Offset      int          `json:"offset"`
	Limit       int          `json:"limit"`
}

type ProjectToSend

type ProjectToSend struct {
	Name                string        `json:"name"`
	Identifier          string        `json:"identifier"`
	Description         string        `json:"description"`
	IsPublic            bool          `json:"is_public"`
	ParentId            interface{}   `json:"parent_id"`
	InheritMembers      bool          `json:"inherit_members"`
	DefaultAssignedToId interface{}   `json:"default_assigned_to_id"`
	DefaultVersionId    interface{}   `json:"default_version_id"`
	TrackerIds          []interface{} `json:"tracker_ids"`
	EnabledModuleNames  []interface{} `json:"enabled_module_names"`
	IssueCustomFieldIds []interface{} `json:"issue_custom_field_ids"`
}

type ProjectToSendWrapper

type ProjectToSendWrapper struct {
	Project ProjectToSend `json:"project"`
}

type ProjectWrapper

type ProjectWrapper struct {
	Project Project `json:"project"`
}

type Watcher

type Watcher struct {
	ID int `json:"user_id"`
}

Directories

Path Synopsis
examples
issues command
memberships command
projects command

Jump to

Keyboard shortcuts

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