mirror of
https://github.com/interviewstreet/go-jira.git
synced 2025-05-13 21:56:42 +02:00
Add boards and fix some bugs in project
This commit is contained in:
parent
ba0906a1b8
commit
065bb9db44
48
board.go
48
board.go
@ -11,41 +11,40 @@ type BoardService struct {
|
|||||||
|
|
||||||
//Type for boards list
|
//Type for boards list
|
||||||
type BoardsList struct {
|
type BoardsList struct {
|
||||||
MaxResults int `json:"maxResults"`
|
MaxResults int `json:"maxResults"`
|
||||||
StartAt int `json:"startAt"`
|
StartAt int `json:"startAt"`
|
||||||
Total int `json:"total"`
|
Total int `json:"total"`
|
||||||
IsLast bool `json:"isLast"`
|
IsLast bool `json:"isLast"`
|
||||||
Values []struct {
|
Values []struct {
|
||||||
ID int `json:"id"`
|
ID int `json:"id"`
|
||||||
Self string `json:"self"`
|
Self string `json:"self"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
} `json:"values"`
|
} `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
|
// Get all boards form jira
|
||||||
//
|
//
|
||||||
// JIRA API docs: https://docs.atlassian.com/jira/REST/latest/#api/2/project-getAllProjects
|
// 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"
|
apiEndpoint := "/rest/agile/1.0/board"
|
||||||
req, err := s.client.NewRequest("GET", apiEndpoint, nil)
|
url, err := addOptions(apiEndpoint, opt)
|
||||||
|
req, err := s.client.NewRequest("GET", url, nil)
|
||||||
if bs != nil {
|
|
||||||
values := req.URL.Query()
|
|
||||||
values.Add(name, value)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
@ -55,5 +54,6 @@ func (s *BoardService) GetList(bs *BoardListSettings) (*BoardsList, *http.Respon
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, resp, err
|
return nil, resp, err
|
||||||
}
|
}
|
||||||
return boards, resp, nil
|
|
||||||
|
return boards, resp, err
|
||||||
}
|
}
|
||||||
|
1
board_test.go
Normal file
1
board_test.go
Normal file
@ -0,0 +1 @@
|
|||||||
|
package jira
|
40
jira.go
40
jira.go
@ -7,6 +7,9 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"reflect"
|
||||||
|
|
||||||
|
"github.com/google/go-querystring/query"
|
||||||
)
|
)
|
||||||
|
|
||||||
// A Client manages communication with the JIRA API.
|
// 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
|
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.
|
// 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.
|
// 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.
|
// 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
|
return resp, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// CheckResponse checks the API response for errors, and returns them if present.
|
// 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.
|
// 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.
|
// The caller is responsible to analyze the response body.
|
||||||
|
@ -68,7 +68,7 @@ func TestProjectGet_NoProject(t *testing.T) {
|
|||||||
|
|
||||||
projects, resp, err := testClient.Project.Get("99999999")
|
projects, resp, err := testClient.Project.Get("99999999")
|
||||||
if projects != nil {
|
if projects != nil {
|
||||||
t.Errorf("Expected nil. Got %s", projects)
|
t.Errorf("Expected nil. Got %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if resp.Status == "404" {
|
if resp.Status == "404" {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user