1
0
mirror of https://github.com/interviewstreet/go-jira.git synced 2025-03-19 20:57:47 +02:00

Merge pull request #142 from Thiht/master

Add method to retrieve Priorities
This commit is contained in:
rbriski 2018-06-12 07:50:43 -07:00 committed by GitHub
commit ab73d577bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 121 additions and 12 deletions

View File

@ -207,7 +207,7 @@ func main() {
}
jiraClient, err := jira.NewClient(tp.Client(), base)
req, _ := jiraClient.NewRequest("GET", "/rest/api/2/project", nil)
req, _ := jiraClient.NewRequest("GET", "rest/api/2/project", nil)
projects := new([]jira.Project)
_, err := jiraClient.Do(req, projects)

View File

@ -49,6 +49,7 @@ type GroupMember struct {
TimeZone string `json:"timeZone,omitempty"`
}
// GroupSearchOptions specifies the optional parameters for the Get Group methods
type GroupSearchOptions struct {
StartAt int
MaxResults int
@ -78,7 +79,7 @@ func (s *GroupService) Get(name string) ([]GroupMember, *Response, error) {
return group.Members, resp, nil
}
// Get returns a paginated list of members of the specified group and its subgroups.
// GetWithOptions returns a paginated list of members of the specified group and its subgroups.
// Users in the page are ordered by user names.
// User of this resource is required to have sysadmin or admin permissions.
//

View File

@ -235,15 +235,6 @@ type Resolution struct {
Name string `json:"name" structs:"name"`
}
// Priority represents a priority of a JIRA issue.
// Typical types are "Normal", "Moderate", "Urgent", ...
type Priority struct {
Self string `json:"self,omitempty" structs:"self,omitempty"`
IconURL string `json:"iconUrl,omitempty" structs:"iconUrl,omitempty"`
Name string `json:"name,omitempty" structs:"name,omitempty"`
ID string `json:"id,omitempty" structs:"id,omitempty"`
}
// Watches represents a type of how many and which user are "observing" a JIRA issue to track the status / updates.
type Watches struct {
Self string `json:"self,omitempty" structs:"self,omitempty"`

View File

@ -35,6 +35,7 @@ type Client struct {
User *UserService
Group *GroupService
Version *VersionService
Priority *PriorityService
}
// NewClient returns a new JIRA API client.
@ -71,6 +72,7 @@ func NewClient(httpClient *http.Client, baseURL string) (*Client, error) {
c.User = &UserService{client: c}
c.Group = &GroupService{client: c}
c.Version = &VersionService{client: c}
c.Priority = &PriorityService{client: c}
return c, nil
}

View File

@ -115,6 +115,9 @@ func TestNewClient_WithServices(t *testing.T) {
if c.Version == nil {
t.Error("No VersionService provided")
}
if c.Priority == nil {
t.Error("No PriorityService provided")
}
}
func TestCheckResponse(t *testing.T) {

42
mocks/all_priorities.json Normal file
View File

@ -0,0 +1,42 @@
[
{
"self": "https://issues.apache.org/jira/rest/api/2/priority/1",
"statusColor": "#cc0000",
"description": "Blocks development and/or testing work, production could not run",
"iconUrl": "https://issues.apache.org/jira/images/icons/priorities/blocker.svg",
"name": "Blocker",
"id": "1"
},
{
"self": "https://issues.apache.org/jira/rest/api/2/priority/2",
"statusColor": "#ff0000",
"description": "Crashes, loss of data, severe memory leak.",
"iconUrl": "https://issues.apache.org/jira/images/icons/priorities/critical.svg",
"name": "Critical",
"id": "2"
},
{
"self": "https://issues.apache.org/jira/rest/api/2/priority/3",
"statusColor": "#009900",
"description": "Major loss of function.",
"iconUrl": "https://issues.apache.org/jira/images/icons/priorities/major.svg",
"name": "Major",
"id": "3"
},
{
"self": "https://issues.apache.org/jira/rest/api/2/priority/4",
"statusColor": "#006600",
"description": "Minor loss of function, or other problem where easy workaround is present.",
"iconUrl": "https://issues.apache.org/jira/images/icons/priorities/minor.svg",
"name": "Minor",
"id": "4"
},
{
"self": "https://issues.apache.org/jira/rest/api/2/priority/5",
"statusColor": "#003300",
"description": "Cosmetic problem like misspelt words or misaligned text.",
"iconUrl": "https://issues.apache.org/jira/images/icons/priorities/trivial.svg",
"name": "Trivial",
"id": "5"
}
]

37
priority.go Normal file
View File

@ -0,0 +1,37 @@
package jira
// PriorityService handles priorities for the JIRA instance / API.
//
// JIRA API docs: https://developer.atlassian.com/cloud/jira/platform/rest/#api-Priority
type PriorityService struct {
client *Client
}
// Priority represents a priority of a JIRA issue.
// Typical types are "Normal", "Moderate", "Urgent", ...
type Priority struct {
Self string `json:"self,omitempty" structs:"self,omitempty"`
IconURL string `json:"iconUrl,omitempty" structs:"iconUrl,omitempty"`
Name string `json:"name,omitempty" structs:"name,omitempty"`
ID string `json:"id,omitempty" structs:"id,omitempty"`
StatusColor string `json:"statusColor,omitempty" structs:"statusColor,omitempty"`
Description string `json:"description,omitempty" structs:"description,omitempty"`
}
// GetList gets all priorities from JIRA
//
// JIRA API docs: https://developer.atlassian.com/cloud/jira/platform/rest/#api-api-2-priority-get
func (s *PriorityService) GetList() ([]Priority, *Response, error) {
apiEndpoint := "rest/api/2/priority"
req, err := s.client.NewRequest("GET", apiEndpoint, nil)
if err != nil {
return nil, nil, err
}
priorityList := []Priority{}
resp, err := s.client.Do(req, &priorityList)
if err != nil {
return nil, resp, NewJiraError(resp, err)
}
return priorityList, resp, nil
}

32
priority_test.go Normal file
View File

@ -0,0 +1,32 @@
package jira
import (
"fmt"
"io/ioutil"
"net/http"
"testing"
)
func TestPriorityService_GetList(t *testing.T) {
setup()
defer teardown()
testAPIEdpoint := "/rest/api/2/priority"
raw, err := ioutil.ReadFile("./mocks/all_priorities.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))
})
priorities, _, err := testClient.Priority.GetList()
if priorities == nil {
t.Error("Expected priority list. Priority list is nil")
}
if err != nil {
t.Errorf("Error given: %s", err)
}
}

View File

@ -2,6 +2,7 @@ package jira
import (
"fmt"
"github.com/google/go-querystring/query"
)
@ -67,7 +68,7 @@ func (s *SprintService) GetIssuesForSprint(sprintID int) ([]Issue, *Response, er
return result.Issues, resp, err
}
// Get returns a full representation of the issue for the given issue key.
// GetIssue returns a full representation of the issue for the given issue key.
// JIRA will attempt to identify the issue by the issueIdOrKey path parameter.
// This can be an issue id, or an issue key.
// If the issue cannot be found via an exact match, JIRA will also look for the issue in a case-insensitive way, or by looking to see if the issue was moved.