mirror of
https://github.com/interviewstreet/go-jira.git
synced 2025-03-17 20:47:57 +02:00
Implement BoardService and get boards list with parameters
This commit is contained in:
parent
00c9de8eaf
commit
81b91847b3
37
board.go
37
board.go
@ -11,33 +11,44 @@ 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"`
|
||||
Self string `json:"self"`
|
||||
Name string `json:"name"`
|
||||
Type string `json:"type"`
|
||||
} `json:"values"`
|
||||
MaxResults int `json:"maxResults"`
|
||||
StartAt int `json:"startAt"`
|
||||
Total int `json:"total"`
|
||||
IsLast bool `json:"isLast"`
|
||||
Values []Value `json:"values"`
|
||||
}
|
||||
|
||||
type Value struct {
|
||||
ID int `json:"id"`
|
||||
Self string `json:"self"`
|
||||
Name string `json:"name"`
|
||||
Type string `json:"type"`
|
||||
}
|
||||
|
||||
// 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"`
|
||||
BoardType string `url:"boardType,omitempty"`
|
||||
// Filters results to boards that match or partially match the specified name.
|
||||
Name string `url:"name,omitempty"`
|
||||
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
|
||||
// Works only for 1.0 endpoints
|
||||
// Default Pagination options
|
||||
ListOptions
|
||||
// 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"`
|
||||
}
|
||||
|
||||
|
||||
// Get all boards form jira
|
||||
//
|
||||
// JIRA API docs: https://docs.atlassian.com/jira/REST/latest/#api/2/project-getAllProjects
|
||||
|
@ -1 +1,67 @@
|
||||
package jira
|
||||
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestBoardsGetAll(t *testing.T) {
|
||||
setup()
|
||||
defer teardown()
|
||||
testAPIEdpoint := "/rest/agile/1.0/board"
|
||||
|
||||
raw, err := ioutil.ReadFile("./mocks/all_boards.json")
|
||||
if err != nil {
|
||||
t.Error(err.Error())
|
||||
}
|
||||
testMux.HandleFunc(testAPIEdpoint, func(w http.ResponseWriter, r *http.Request) {
|
||||
testMethod(t, r, "GET")
|
||||
testRequestURL(t, r, testAPIEdpoint)
|
||||
fmt.Fprint(w, string(raw))
|
||||
})
|
||||
|
||||
projects, _, err := testClient.Board.GetList(nil)
|
||||
if projects == nil {
|
||||
t.Error("Expected boards list. Boards list is nil")
|
||||
}
|
||||
if err != nil {
|
||||
t.Errorf("Error given: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Test with params
|
||||
func TestBoardsGetFiltered(t *testing.T) {
|
||||
setup()
|
||||
defer teardown()
|
||||
testAPIEdpoint := "/rest/agile/1.0/board"
|
||||
|
||||
raw, err := ioutil.ReadFile("./mocks/all_boards_filtered.json")
|
||||
if err != nil {
|
||||
t.Error(err.Error())
|
||||
}
|
||||
testMux.HandleFunc(testAPIEdpoint, func(w http.ResponseWriter, r *http.Request) {
|
||||
testMethod(t, r, "GET")
|
||||
testRequestURL(t, r, testAPIEdpoint)
|
||||
fmt.Fprint(w, string(raw))
|
||||
})
|
||||
|
||||
boardsListOptions := BoardListOptions {
|
||||
BoardType: "scrum",
|
||||
Name: "Test",
|
||||
ProjectKeyOrId: "TE",
|
||||
StartAt: 1,
|
||||
MaxResults: 10,
|
||||
}
|
||||
|
||||
projects, _, err := testClient.Board.GetList(&boardsListOptions)
|
||||
if projects == nil {
|
||||
t.Error("Expected boards list. Boards list is nil")
|
||||
}
|
||||
if err != nil {
|
||||
t.Errorf("Error given: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
14
jira.go
14
jira.go
@ -27,6 +27,7 @@ type Client struct {
|
||||
Authentication *AuthenticationService
|
||||
Issue *IssueService
|
||||
Project *ProjectService
|
||||
Board *BoardService
|
||||
}
|
||||
|
||||
// NewClient returns a new JIRA API client.
|
||||
@ -53,6 +54,7 @@ func NewClient(httpClient *http.Client, baseURL string) (*Client, error) {
|
||||
c.Authentication = &AuthenticationService{client: c}
|
||||
c.Issue = &IssueService{client: c}
|
||||
c.Project = &ProjectService{client: c}
|
||||
c.Board = &BoardService{client: c}
|
||||
|
||||
return c, nil
|
||||
}
|
||||
@ -95,18 +97,6 @@ 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.
|
||||
|
@ -10,6 +10,7 @@ import (
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -52,7 +53,7 @@ func testMethod(t *testing.T, r *http.Request, want string) {
|
||||
}
|
||||
|
||||
func testRequestURL(t *testing.T, r *http.Request, want string) {
|
||||
if got := r.URL.String(); got != want {
|
||||
if got := r.URL.String(); !strings.HasPrefix(got, want) {
|
||||
t.Errorf("Request URL: %v, want %v", got, want)
|
||||
}
|
||||
}
|
||||
|
43
mocks/all_boards.json
Normal file
43
mocks/all_boards.json
Normal file
@ -0,0 +1,43 @@
|
||||
{
|
||||
"maxResults": 50,
|
||||
"startAt": 0,
|
||||
"isLast": true,
|
||||
"values": [
|
||||
{
|
||||
"id": 4,
|
||||
"self": "https://test.jira.org/rest/agile/1.0/board/4",
|
||||
"name": "Test Weekly",
|
||||
"type": "scrum"
|
||||
},
|
||||
{
|
||||
"id": 5,
|
||||
"self": "https://test.jira.org/rest/agile/1.0/board/5",
|
||||
"name": "Test Production Support",
|
||||
"type": "kanban"
|
||||
},
|
||||
{
|
||||
"id": 6,
|
||||
"self": "https://test.jira.org/rest/agile/1.0/board/6",
|
||||
"name": "Test To Give",
|
||||
"type": "kanban"
|
||||
},
|
||||
{
|
||||
"id": 7,
|
||||
"self": "https://test.jira.org/rest/agile/1.0/board/7",
|
||||
"name": "Test Journey App",
|
||||
"type": "kanban"
|
||||
},
|
||||
{
|
||||
"id": 9,
|
||||
"self": "https://test.jira.org/rest/agile/1.0/board/9",
|
||||
"name": "Testix",
|
||||
"type": "scrum"
|
||||
},
|
||||
{
|
||||
"id": 1,
|
||||
"self": "https://test.jira.org/rest/agile/1.0/board/1",
|
||||
"name": "Test Mobile",
|
||||
"type": "scrum"
|
||||
}
|
||||
]
|
||||
}
|
25
mocks/all_boards_filtered.json
Normal file
25
mocks/all_boards_filtered.json
Normal file
@ -0,0 +1,25 @@
|
||||
{
|
||||
"maxResults": 10,
|
||||
"startAt": 1,
|
||||
"isLast": true,
|
||||
"values": [
|
||||
{
|
||||
"id": 4,
|
||||
"self": "https://test.jira.org/rest/agile/1.0/board/4",
|
||||
"name": "Test Weekly",
|
||||
"type": "scrum"
|
||||
},
|
||||
{
|
||||
"id": 9,
|
||||
"self": "https://test.jira.org/rest/agile/1.0/board/9",
|
||||
"name": "Testix",
|
||||
"type": "scrum"
|
||||
},
|
||||
{
|
||||
"id": 1,
|
||||
"self": "https://test.jira.org/rest/agile/1.0/board/1",
|
||||
"name": "Test Mobile",
|
||||
"type": "scrum"
|
||||
}
|
||||
]
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user