1
0
mirror of https://github.com/interviewstreet/go-jira.git synced 2024-12-02 08:51:43 +02:00
go-jira/board.go

155 lines
5.0 KiB
Go
Raw Normal View History

2016-06-01 20:18:33 +02:00
package jira
2016-06-01 20:23:27 +02:00
import (
"fmt"
"time"
)
2016-06-01 20:23:27 +02:00
// BoardService handles Agile Boards for the JIRA instance / API.
//
// JIRA API docs: https://docs.atlassian.com/jira-software/REST/server/
2016-06-01 20:23:27 +02:00
type BoardService struct {
client *Client
}
// BoardsList reflects a list of agile boards
2016-06-01 20:23:27 +02:00
type BoardsList struct {
MaxResults int `json:"maxResults"`
StartAt int `json:"startAt"`
Total int `json:"total"`
IsLast bool `json:"isLast"`
2016-06-16 09:52:16 +02:00
Values []Board `json:"values"`
2016-06-01 20:23:27 +02:00
}
// Board represents a JIRA agile board
2016-06-16 09:52:16 +02:00
type Board struct {
ID int `json:"id,omitempty"`
Self string `json:"self,omitempty"`
Name string `json:"name,omitempty"`
Type string `json:"type,omitempty"`
FilterID int `json:"filterId,omitempty"`
}
2016-06-01 20:23:27 +02:00
// BoardListOptions specifies the optional parameters to the BoardService.GetList
type BoardListOptions struct {
// BoardType filters results to boards of the specified type.
// Valid values: scrum, kanban.
BoardType string `url:"boardType,omitempty"`
// Name filters results to boards that match or partially match the specified name.
Name string `url:"name,omitempty"`
// ProjectKeyOrID filters results to boards that are relevant to a project.
// Relevance meaning that the JQL filter defined in board contains a reference to a project.
ProjectKeyOrID string `url:"projectKeyOrId,omitempty"`
SearchOptions
}
2016-06-01 20:23:27 +02:00
// Wrapper struct for search result
type sprintsResult struct {
Sprints []Sprint `json:"values"`
}
// Sprint represents a sprint on JIRA agile board
type Sprint struct {
ID int `json:"id"`
Name string `json:"name"`
CompleteDate *time.Time `json:"completeDate"`
EndDate *time.Time `json:"endDate"`
StartDate *time.Time `json:"startDate"`
OriginBoardID int `json:"originBoardId"`
Self string `json:"self"`
State string `json:"state"`
}
// GetAllBoards will returns all boards. This only includes boards that the user has permission to view.
2016-06-01 20:23:27 +02:00
//
// JIRA API docs: https://docs.atlassian.com/jira-software/REST/cloud/#agile/1.0/board-getAllBoards
func (s *BoardService) GetAllBoards(opt *BoardListOptions) (*BoardsList, *Response, error) {
2016-06-16 09:52:16 +02:00
apiEndpoint := "rest/agile/1.0/board"
url, err := addOptions(apiEndpoint, opt)
req, err := s.client.NewRequest("GET", url, nil)
2016-06-01 20:23:27 +02:00
if err != nil {
return nil, nil, err
}
boards := new(BoardsList)
resp, err := s.client.Do(req, boards)
if err != nil {
return nil, resp, err
}
return boards, resp, err
2016-06-01 20:23:27 +02:00
}
2016-06-16 09:52:16 +02:00
// GetBoard will returns the board for the given boardID.
// This board will only be returned if the user has permission to view it.
//
// JIRA API docs: https://docs.atlassian.com/jira-software/REST/cloud/#agile/1.0/board-getBoard
func (s *BoardService) GetBoard(boardID int) (*Board, *Response, error) {
2016-06-16 11:20:47 +02:00
apiEndpoint := fmt.Sprintf("rest/agile/1.0/board/%v", boardID)
2016-06-16 09:52:16 +02:00
req, err := s.client.NewRequest("GET", apiEndpoint, nil)
if err != nil {
return nil, nil, err
}
board := new(Board)
resp, err := s.client.Do(req, board)
if err != nil {
return nil, resp, err
}
return board, resp, nil
}
// Create creates a new board. Board name, type and filter Id is required.
2016-06-16 09:52:16 +02:00
// name - Must be less than 255 characters.
// type - Valid values: scrum, kanban
// filterId - Id of a filter that the user has permissions to view.
// Note, if the user does not have the 'Create shared objects' permission and tries to create a shared board, a private
// board will be created instead (remember that board sharing depends on the filter sharing).
2016-06-16 11:20:47 +02:00
//
2016-06-16 09:52:16 +02:00
// JIRA API docs: https://docs.atlassian.com/jira-software/REST/cloud/#agile/1.0/board-createBoard
func (s *BoardService) CreateBoard(board *Board) (*Board, *Response, error) {
2016-06-16 09:52:16 +02:00
apiEndpoint := "rest/agile/1.0/board"
req, err := s.client.NewRequest("POST", apiEndpoint, board)
if err != nil {
return nil, nil, err
}
responseBoard := new(Board)
resp, err := s.client.Do(req, responseBoard)
if err != nil {
return nil, resp, err
}
2016-06-16 09:52:16 +02:00
return responseBoard, resp, nil
}
2016-06-16 11:20:47 +02:00
// Delete will delete an agile board.
2016-06-16 11:20:47 +02:00
//
// JIRA API docs: https://docs.atlassian.com/jira-software/REST/cloud/#agile/1.0/board-deleteBoard
func (s *BoardService) DeleteBoard(boardID int) (*Board, *Response, error) {
2016-06-16 11:20:47 +02:00
apiEndpoint := fmt.Sprintf("rest/agile/1.0/board/%v", boardID)
req, err := s.client.NewRequest("DELETE", apiEndpoint, nil)
if err != nil {
return nil, nil, err
}
resp, err := s.client.Do(req, nil)
return nil, resp, err
}
// GetAllSprints will returns all sprints from a board, for a given board Id.
// This only includes sprints that the user has permission to view.
//
// JIRA API docs: https://docs.atlassian.com/jira-software/REST/cloud/#agile/1.0/board/{boardId}/sprint
func (s *BoardService) GetAllSprints(boardID string) ([]Sprint, *Response, error) {
apiEndpoint := fmt.Sprintf("rest/agile/1.0/board/%s/sprint", boardID)
req, err := s.client.NewRequest("GET", apiEndpoint, nil)
if err != nil {
return nil, nil, err
}
result := new(sprintsResult)
resp, err := s.client.Do(req, result)
return result.Sprints, resp, err
}