mirror of
https://github.com/interviewstreet/go-jira.git
synced 2025-06-04 23:07:35 +02:00
go fmt, go doc and reuse of Project struct
This commit is contained in:
parent
7c3e481c65
commit
7ac3d14dbc
15
issue.go
15
issue.go
@ -95,15 +95,6 @@ type IssueType struct {
|
|||||||
AvatarID int `json:"avatarId,omitempty"`
|
AvatarID int `json:"avatarId,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Project represents a JIRA Project.
|
|
||||||
type Project struct {
|
|
||||||
Self string `json:"self,omitempty"`
|
|
||||||
ID string `json:"id,omitempty"`
|
|
||||||
Key string `json:"key,omitempty"`
|
|
||||||
Name string `json:"name,omitempty"`
|
|
||||||
AvatarURLs map[string]string `json:"avatarUrls,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Resolution represents a resolution of a JIRA issue.
|
// Resolution represents a resolution of a JIRA issue.
|
||||||
// Typical types are "Fixed", "Suspended", "Won't Fix", ...
|
// Typical types are "Fixed", "Suspended", "Won't Fix", ...
|
||||||
type Resolution struct {
|
type Resolution struct {
|
||||||
@ -129,7 +120,7 @@ type Watches struct {
|
|||||||
IsWatching bool `json:"isWatching,omitempty"`
|
IsWatching bool `json:"isWatching,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assignee represents a user who is this JIRA issue assigned to.
|
// User represents a user who is this JIRA issue assigned to.
|
||||||
type User struct {
|
type User struct {
|
||||||
Self string `json:"self,omitempty"`
|
Self string `json:"self,omitempty"`
|
||||||
Name string `json:"name,omitempty"`
|
Name string `json:"name,omitempty"`
|
||||||
@ -141,6 +132,7 @@ type User struct {
|
|||||||
TimeZone string `json:"timeZone,omitempty"`
|
TimeZone string `json:"timeZone,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AvatarUrls represents different dimensions of avatars / images
|
||||||
type AvatarUrls struct {
|
type AvatarUrls struct {
|
||||||
Four8X48 string `json:"48x48,omitempty"`
|
Four8X48 string `json:"48x48,omitempty"`
|
||||||
Two4X24 string `json:"24x24,omitempty"`
|
Two4X24 string `json:"24x24,omitempty"`
|
||||||
@ -185,6 +177,7 @@ type Progress struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Worklog represents the work log of a JIRA issue.
|
// Worklog represents the work log of a JIRA issue.
|
||||||
|
// One Worklog contains zero or n WorklogRecords
|
||||||
// JIRA Wiki: https://confluence.atlassian.com/jira/logging-work-on-an-issue-185729605.html
|
// JIRA Wiki: https://confluence.atlassian.com/jira/logging-work-on-an-issue-185729605.html
|
||||||
type Worklog struct {
|
type Worklog struct {
|
||||||
StartAt int `json:"startAt"`
|
StartAt int `json:"startAt"`
|
||||||
@ -193,6 +186,7 @@ type Worklog struct {
|
|||||||
Worklogs []WorklogRecord `json:"worklogs"`
|
Worklogs []WorklogRecord `json:"worklogs"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WorklogRecord represents one entry of a Worklog
|
||||||
type WorklogRecord struct {
|
type WorklogRecord struct {
|
||||||
Self string `json:"self"`
|
Self string `json:"self"`
|
||||||
Author User `json:"author"`
|
Author User `json:"author"`
|
||||||
@ -207,6 +201,7 @@ type WorklogRecord struct {
|
|||||||
IssueID string `json:"issueId"`
|
IssueID string `json:"issueId"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Subtasks represents all issues of a parent issue.
|
||||||
type Subtasks struct {
|
type Subtasks struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
Key string `json:"key"`
|
Key string `json:"key"`
|
||||||
|
50
project.go
50
project.go
@ -5,11 +5,14 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ProjectService handles projects for the JIRA instance / API.
|
||||||
|
//
|
||||||
|
// JIRA API docs: https://docs.atlassian.com/jira/REST/latest/#api/2/project
|
||||||
type ProjectService struct {
|
type ProjectService struct {
|
||||||
client *Client
|
client *Client
|
||||||
}
|
}
|
||||||
|
|
||||||
// Project list type
|
// ProjectList represent a list of Projects
|
||||||
type ProjectList []struct {
|
type ProjectList []struct {
|
||||||
Expand string `json:"expand"`
|
Expand string `json:"expand"`
|
||||||
Self string `json:"self"`
|
Self string `json:"self"`
|
||||||
@ -21,6 +24,7 @@ type ProjectList []struct {
|
|||||||
ProjectCategory ProjectCategory `json:"projectCategory,omitempty"`
|
ProjectCategory ProjectCategory `json:"projectCategory,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ProjectCategory represents a single project category
|
||||||
type ProjectCategory struct {
|
type ProjectCategory struct {
|
||||||
Self string `json:"self"`
|
Self string `json:"self"`
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
@ -28,29 +32,29 @@ type ProjectCategory struct {
|
|||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Full project description
|
// Project represents a JIRA Project.
|
||||||
// Can't name it project because it exist in issue
|
type Project struct {
|
||||||
type FullProject struct {
|
Expand string `json:"expand,omitempty"`
|
||||||
Expand string `json:"expand"`
|
Self string `json:"self,omitempty"`
|
||||||
Self string `json:"self"`
|
ID string `json:"id,omitempty"`
|
||||||
ID string `json:"id"`
|
Key string `json:"key,omitempty"`
|
||||||
Key string `json:"key"`
|
Description string `json:"description,omitempty"`
|
||||||
Description string `json:"description"`
|
Lead User `json:"lead,omitempty"`
|
||||||
Lead User `json:"lead"`
|
Components []ProjectComponent `json:"components,omitempty"`
|
||||||
Components []ProjectComponent `json:"components"`
|
IssueTypes []IssueType `json:"issueTypes,omitempty"`
|
||||||
IssueTypes []IssueType `json:"issueTypes"`
|
URL string `json:"url,omitempty"`
|
||||||
URL string `json:"url"`
|
Email string `json:"email,omitempty"`
|
||||||
Email string `json:"email"`
|
AssigneeType string `json:"assigneeType,omitempty"`
|
||||||
AssigneeType string `json:"assigneeType"`
|
Versions []interface{} `json:"versions,omitempty"`
|
||||||
Versions []interface{} `json:"versions"`
|
Name string `json:"name,omitempty"`
|
||||||
Name string `json:"name"`
|
|
||||||
Roles struct {
|
Roles struct {
|
||||||
Developers string `json:"Developers"`
|
Developers string `json:"Developers,omitempty"`
|
||||||
} `json:"roles"`
|
} `json:"roles,omitempty"`
|
||||||
AvatarUrls AvatarUrls `json:"avatarUrls"`
|
AvatarUrls AvatarUrls `json:"avatarUrls,omitempty"`
|
||||||
ProjectCategory ProjectCategory `json:"projectCategory"`
|
ProjectCategory ProjectCategory `json:"projectCategory,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ProjectComponent represents a single component of a project
|
||||||
type ProjectComponent struct {
|
type ProjectComponent struct {
|
||||||
Self string `json:"self"`
|
Self string `json:"self"`
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
@ -89,14 +93,14 @@ func (s *ProjectService) GetList() (*ProjectList, *http.Response, error) {
|
|||||||
// This can be an project id, or an project key.
|
// This can be an project id, or an project key.
|
||||||
//
|
//
|
||||||
// JIRA API docs: https://docs.atlassian.com/jira/REST/latest/#api/2/project-getProject
|
// JIRA API docs: https://docs.atlassian.com/jira/REST/latest/#api/2/project-getProject
|
||||||
func (s *ProjectService) Get(projectID string) (*FullProject, *http.Response, error) {
|
func (s *ProjectService) Get(projectID string) (*Project, *http.Response, error) {
|
||||||
apiEndpoint := fmt.Sprintf("/rest/api/2/project/%s", projectID)
|
apiEndpoint := fmt.Sprintf("/rest/api/2/project/%s", projectID)
|
||||||
req, err := s.client.NewRequest("GET", apiEndpoint, nil)
|
req, err := s.client.NewRequest("GET", apiEndpoint, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
project := new(FullProject)
|
project := new(Project)
|
||||||
resp, err := s.client.Do(req, project)
|
resp, err := s.client.Do(req, project)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, resp, err
|
return nil, resp, err
|
||||||
|
@ -10,15 +10,15 @@ import (
|
|||||||
func TestProjectGetAll(t *testing.T) {
|
func TestProjectGetAll(t *testing.T) {
|
||||||
setup()
|
setup()
|
||||||
defer teardown()
|
defer teardown()
|
||||||
testApiEdpoint := "/rest/api/2/project"
|
testAPIEdpoint := "/rest/api/2/project"
|
||||||
|
|
||||||
raw, err := ioutil.ReadFile("./mocks/all_projects.json")
|
raw, err := ioutil.ReadFile("./mocks/all_projects.json")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err.Error())
|
t.Error(err.Error())
|
||||||
}
|
}
|
||||||
testMux.HandleFunc(testApiEdpoint, func(w http.ResponseWriter, r *http.Request) {
|
testMux.HandleFunc(testAPIEdpoint, func(w http.ResponseWriter, r *http.Request) {
|
||||||
testMethod(t, r, "GET")
|
testMethod(t, r, "GET")
|
||||||
testRequestURL(t, r, testApiEdpoint)
|
testRequestURL(t, r, testAPIEdpoint)
|
||||||
fmt.Fprint(w, string(raw))
|
fmt.Fprint(w, string(raw))
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -34,15 +34,15 @@ func TestProjectGetAll(t *testing.T) {
|
|||||||
func TestProjectGet(t *testing.T) {
|
func TestProjectGet(t *testing.T) {
|
||||||
setup()
|
setup()
|
||||||
defer teardown()
|
defer teardown()
|
||||||
testApiEdpoint := "/rest/api/2/project/12310505"
|
testAPIEdpoint := "/rest/api/2/project/12310505"
|
||||||
|
|
||||||
raw, err := ioutil.ReadFile("./mocks/project.json")
|
raw, err := ioutil.ReadFile("./mocks/project.json")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err.Error())
|
t.Error(err.Error())
|
||||||
}
|
}
|
||||||
testMux.HandleFunc(testApiEdpoint, func(w http.ResponseWriter, r *http.Request) {
|
testMux.HandleFunc(testAPIEdpoint, func(w http.ResponseWriter, r *http.Request) {
|
||||||
testMethod(t, r, "GET")
|
testMethod(t, r, "GET")
|
||||||
testRequestURL(t, r, testApiEdpoint)
|
testRequestURL(t, r, testAPIEdpoint)
|
||||||
fmt.Fprint(w, string(raw))
|
fmt.Fprint(w, string(raw))
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -58,17 +58,17 @@ func TestProjectGet(t *testing.T) {
|
|||||||
func TestProjectGet_NoProject(t *testing.T) {
|
func TestProjectGet_NoProject(t *testing.T) {
|
||||||
setup()
|
setup()
|
||||||
defer teardown()
|
defer teardown()
|
||||||
testApiEdpoint := "/rest/api/2/project/99999999"
|
testAPIEdpoint := "/rest/api/2/project/99999999"
|
||||||
|
|
||||||
testMux.HandleFunc(testApiEdpoint, func(w http.ResponseWriter, r *http.Request) {
|
testMux.HandleFunc(testAPIEdpoint, func(w http.ResponseWriter, r *http.Request) {
|
||||||
testMethod(t, r, "GET")
|
testMethod(t, r, "GET")
|
||||||
testRequestURL(t, r, testApiEdpoint)
|
testRequestURL(t, r, testAPIEdpoint)
|
||||||
fmt.Fprint(w, nil)
|
fmt.Fprint(w, nil)
|
||||||
})
|
})
|
||||||
|
|
||||||
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 %+v", projects)
|
||||||
}
|
}
|
||||||
|
|
||||||
if resp.Status == "404" {
|
if resp.Status == "404" {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user