1
0
mirror of https://github.com/interviewstreet/go-jira.git synced 2024-11-28 08:39:03 +02:00

Adjusted PR #19

* go doc
* go fmt
* Usage of already existing structs
* Adjustments related to the wrapping response
This commit is contained in:
Andy Grunwald 2016-06-19 15:08:53 +02:00
parent ce47602482
commit c0b29dac50
3 changed files with 45 additions and 44 deletions

View File

@ -1,15 +1,15 @@
package jira
import (
"fmt"
"net/http"
)
import "fmt"
// BoardService handles Agile Boards for the JIRA instance / API.
//
// JIRA API docs: https://docs.atlassian.com/jira-software/REST/server/
type BoardService struct {
client *Client
}
//Type for boards list
// BoardsList reflects a list of agile boards
type BoardsList struct {
MaxResults int `json:"maxResults"`
StartAt int `json:"startAt"`
@ -18,41 +18,33 @@ type BoardsList struct {
Values []Board `json:"values"`
}
// Board represents a JIRA board
// Board represents a JIRA agile board
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 `omitempty`
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"`
}
// BoardListOptions specifies the optional parameters to the BoardService.GetList
type BoardListOptions struct {
// Filters results to boards of the specified type.
// BoardType filters results to boards of the specified type.
// Valid values: scrum, kanban.
BoardType string `url:"boardType,omitempty"`
// Filters results to boards that match or partially match the specified name.
// Name filters results to boards that match or partially match the specified name.
Name string `url:"name,omitempty"`
// 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"`
// ListOptions specifies the optional parameters to various List methods that
// support pagination.
// Pagination is used for the JIRA REST APIs to conserve server resources and limit
// response size for resources that return potentially large collection of items.
// A request to a pages API will result in a values array wrapped in a JSON object with some paging metadata
// Default Pagination options
// The starting index of the returned projects. Base index: 0.
StartAt int `url:"startAt,omitempty"`
// The maximum number of projects to return per page. Default: 50.
MaxResults int `url:"maxResults,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
}
// Get all boards form jira
// GetList will return all boards from JIRA
//
// JIRA API docs: https://docs.atlassian.com/jira/REST/latest/#api/2/project-getAllProjects
func (s *BoardService) GetList(opt *BoardListOptions) (*BoardsList, *http.Response, error) {
// JIRA API docs: https://docs.atlassian.com/jira-software/REST/cloud/#agile/1.0/board-getAllBoards
func (s *BoardService) GetList(opt *BoardListOptions) (*BoardsList, *Response, error) {
apiEndpoint := "rest/agile/1.0/board"
url, err := addOptions(apiEndpoint, opt)
req, err := s.client.NewRequest("GET", url, nil)
@ -69,8 +61,11 @@ func (s *BoardService) GetList(opt *BoardListOptions) (*BoardsList, *http.Respon
return boards, resp, err
}
// Returns the board for the given board Id. This board will only be returned if the user has permission to view it.
func (s *BoardService) Get(boardID int) (*Board, *http.Response, error) {
// Get will return 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) Get(boardID int) (*Board, *Response, error) {
apiEndpoint := fmt.Sprintf("rest/agile/1.0/board/%v", boardID)
req, err := s.client.NewRequest("GET", apiEndpoint, nil)
if err != nil {
@ -85,7 +80,7 @@ func (s *BoardService) Get(boardID int) (*Board, *http.Response, error) {
return board, resp, nil
}
// Creates a new board. Board name, type and filter Id is required.
// Create creates a new board. Board name, type and filter Id is required.
// name - Must be less than 255 characters.
// type - Valid values: scrum, kanban
// filterId - Id of a filter that the user has permissions to view.
@ -93,8 +88,7 @@ func (s *BoardService) Get(boardID int) (*Board, *http.Response, error) {
// board will be created instead (remember that board sharing depends on the filter sharing).
//
// JIRA API docs: https://docs.atlassian.com/jira-software/REST/cloud/#agile/1.0/board-createBoard
func (s *BoardService) Create(board *Board) (*Board, *http.Response, error) {
func (s *BoardService) Create(board *Board) (*Board, *Response, error) {
apiEndpoint := "rest/agile/1.0/board"
req, err := s.client.NewRequest("POST", apiEndpoint, board)
if err != nil {
@ -106,13 +100,14 @@ func (s *BoardService) Create(board *Board) (*Board, *http.Response, error) {
if err != nil {
return nil, resp, err
}
return responseBoard, resp, nil
}
// Deletes the board.
// Delete will delete an agile board.
//
// https://docs.atlassian.com/jira-software/REST/cloud/#agile/1.0/board-deleteBoard
func (s *BoardService) Delete(boardID int) (*Board, *http.Response, error) {
func (s *BoardService) Delete(boardID int) (*Board, *Response, error) {
apiEndpoint := fmt.Sprintf("rest/agile/1.0/board/%v", boardID)
req, err := s.client.NewRequest("DELETE", apiEndpoint, nil)
if err != nil {

View File

@ -50,10 +50,10 @@ func TestBoardsGetFiltered(t *testing.T) {
boardsListOptions := &BoardListOptions{
BoardType: "scrum",
Name: "Test",
ProjectKeyOrId: "TE",
StartAt: 1,
MaxResults: 10,
ProjectKeyOrID: "TE",
}
boardsListOptions.StartAt = 1
boardsListOptions.MaxResults = 10
projects, _, err := testClient.Board.GetList(boardsListOptions)
if projects == nil {
@ -122,7 +122,7 @@ func TestBoardCreate(t *testing.T) {
b := &Board{
Name: "Test",
Type: "kanban",
FilterId: 17,
FilterID: 17,
}
issue, _, err := testClient.Board.Create(b)
if issue == nil {

View File

@ -277,11 +277,17 @@ type CommentVisibility struct {
Value string `json:"value,omitempty"`
}
// SearchOptions represents options you can apply
// at a Search functionality (JQL in JIRA).
// SearchOptions specifies the optional parameters to various List methods that
// support pagination.
// Pagination is used for the JIRA REST APIs to conserve server resources and limit
// response size for resources that return potentially large collection of items.
// A request to a pages API will result in a values array wrapped in a JSON object with some paging metadata
// Default Pagination options
type SearchOptions struct {
StartAt int
MaxResults int
// StartAt: The starting index of the returned projects. Base index: 0.
StartAt int `url:"startAt,omitempty"`
// MaxResults: The maximum number of projects to return per page. Default: 50.
MaxResults int `url:"maxResults,omitempty"`
}
// searchResult is only a small wrapper arround the Search (with JQL) method