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

Add boards and fix some bugs in project

This commit is contained in:
Evgen Kostenko 2016-06-15 12:20:37 +03:00
parent ba0906a1b8
commit 065bb9db44
4 changed files with 66 additions and 25 deletions

View File

@ -11,41 +11,40 @@ type BoardService struct {
//Type for boards list
type BoardsList struct {
MaxResults int `json:"maxResults"`
StartAt int `json:"startAt"`
Total int `json:"total"`
IsLast bool `json:"isLast"`
Values []struct {
ID int `json:"id"`
MaxResults int `json:"maxResults"`
StartAt int `json:"startAt"`
Total int `json:"total"`
IsLast bool `json:"isLast"`
Values []struct {
ID int `json:"id"`
Self string `json:"self"`
Name string `json:"name"`
Type string `json:"type"`
} `json:"values"`
}
type BoardListSettings struct {
startAt int
maxResults int
boardType string
name string
projectKeyOrId string
}
// BoardListOptions specifies the optional parameters to the BoardService.GetList
type BoardListOptions struct {
// 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 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"`
// Default Pagination options
ListOptions
}
// Get all boards form jira
//
// JIRA API docs: https://docs.atlassian.com/jira/REST/latest/#api/2/project-getAllProjects
func (s *BoardService) GetList(bs *BoardListSettings) (*BoardsList, *http.Response, error) {
func (s *BoardService) GetList(opt *BoardListOptions) (*BoardsList, *http.Response, error) {
apiEndpoint := "/rest/agile/1.0/board"
req, err := s.client.NewRequest("GET", apiEndpoint, nil)
if bs != nil {
values := req.URL.Query()
values.Add(name, value)
}
url, err := addOptions(apiEndpoint, opt)
req, err := s.client.NewRequest("GET", url, nil)
if err != nil {
return nil, nil, err
}
@ -55,5 +54,6 @@ func (s *BoardService) GetList(bs *BoardListSettings) (*BoardsList, *http.Respon
if err != nil {
return nil, resp, err
}
return boards, resp, nil
return boards, resp, err
}

1
board_test.go Normal file
View File

@ -0,0 +1 @@
package jira

40
jira.go
View File

@ -7,6 +7,9 @@ import (
"io"
"net/http"
"net/url"
"reflect"
"github.com/google/go-querystring/query"
)
// A Client manages communication with the JIRA API.
@ -92,6 +95,41 @@ func (c *Client) NewRequest(method, urlStr string, body interface{}) (*http.Requ
return req, nil
}
// 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
type ListOptions struct {
// 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"`
}
// addOptions adds the parameters in opt as URL query parameters to s. opt
// must be a struct whose fields may contain "url" tags.
func addOptions(s string, opt interface{}) (string, error) {
v := reflect.ValueOf(opt)
if v.Kind() == reflect.Ptr && v.IsNil() {
return s, nil
}
u, err := url.Parse(s)
if err != nil {
return s, err
}
qs, err := query.Values(opt)
if err != nil {
return s, err
}
u.RawQuery = qs.Encode()
return u.String(), nil
}
// NewMultiPartRequest creates an API request including a multi-part file.
// A relative URL can be provided in urlStr, in which case it is resolved relative to the baseURL of the Client.
// Relative URLs should always be specified without a preceding slash.
@ -144,6 +182,8 @@ func (c *Client) Do(req *http.Request, v interface{}) (*http.Response, error) {
return resp, err
}
// CheckResponse checks the API response for errors, and returns them if present.
// A response is considered an error if it has a status code outside the 200 range.
// The caller is responsible to analyze the response body.

View File

@ -68,7 +68,7 @@ func TestProjectGet_NoProject(t *testing.T) {
projects, resp, err := testClient.Project.Get("99999999")
if projects != nil {
t.Errorf("Expected nil. Got %s", projects)
t.Errorf("Expected nil. Got %s", err)
}
if resp.Status == "404" {