mirror of
https://github.com/interviewstreet/go-jira.git
synced 2024-11-24 08:22:42 +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"`
|
||||
}
|
||||
|
||||
// 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.
|
||||
// Typical types are "Fixed", "Suspended", "Won't Fix", ...
|
||||
type Resolution struct {
|
||||
@ -129,7 +120,7 @@ type Watches struct {
|
||||
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 {
|
||||
Self string `json:"self,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
@ -141,6 +132,7 @@ type User struct {
|
||||
TimeZone string `json:"timeZone,omitempty"`
|
||||
}
|
||||
|
||||
// AvatarUrls represents different dimensions of avatars / images
|
||||
type AvatarUrls struct {
|
||||
Four8X48 string `json:"48x48,omitempty"`
|
||||
Two4X24 string `json:"24x24,omitempty"`
|
||||
@ -185,6 +177,7 @@ type Progress struct {
|
||||
}
|
||||
|
||||
// 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
|
||||
type Worklog struct {
|
||||
StartAt int `json:"startAt"`
|
||||
@ -193,6 +186,7 @@ type Worklog struct {
|
||||
Worklogs []WorklogRecord `json:"worklogs"`
|
||||
}
|
||||
|
||||
// WorklogRecord represents one entry of a Worklog
|
||||
type WorklogRecord struct {
|
||||
Self string `json:"self"`
|
||||
Author User `json:"author"`
|
||||
@ -207,6 +201,7 @@ type WorklogRecord struct {
|
||||
IssueID string `json:"issueId"`
|
||||
}
|
||||
|
||||
// Subtasks represents all issues of a parent issue.
|
||||
type Subtasks struct {
|
||||
ID string `json:"id"`
|
||||
Key string `json:"key"`
|
||||
|
50
project.go
50
project.go
@ -5,11 +5,14 @@ import (
|
||||
"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 {
|
||||
client *Client
|
||||
}
|
||||
|
||||
// Project list type
|
||||
// ProjectList represent a list of Projects
|
||||
type ProjectList []struct {
|
||||
Expand string `json:"expand"`
|
||||
Self string `json:"self"`
|
||||
@ -21,6 +24,7 @@ type ProjectList []struct {
|
||||
ProjectCategory ProjectCategory `json:"projectCategory,omitempty"`
|
||||
}
|
||||
|
||||
// ProjectCategory represents a single project category
|
||||
type ProjectCategory struct {
|
||||
Self string `json:"self"`
|
||||
ID string `json:"id"`
|
||||
@ -28,29 +32,29 @@ type ProjectCategory struct {
|
||||
Description string `json:"description"`
|
||||
}
|
||||
|
||||
// Full project description
|
||||
// Can't name it project because it exist in issue
|
||||
type FullProject struct {
|
||||
Expand string `json:"expand"`
|
||||
Self string `json:"self"`
|
||||
ID string `json:"id"`
|
||||
Key string `json:"key"`
|
||||
Description string `json:"description"`
|
||||
Lead User `json:"lead"`
|
||||
Components []ProjectComponent `json:"components"`
|
||||
IssueTypes []IssueType `json:"issueTypes"`
|
||||
URL string `json:"url"`
|
||||
Email string `json:"email"`
|
||||
AssigneeType string `json:"assigneeType"`
|
||||
Versions []interface{} `json:"versions"`
|
||||
Name string `json:"name"`
|
||||
// Project represents a JIRA Project.
|
||||
type Project struct {
|
||||
Expand string `json:"expand,omitempty"`
|
||||
Self string `json:"self,omitempty"`
|
||||
ID string `json:"id,omitempty"`
|
||||
Key string `json:"key,omitempty"`
|
||||
Description string `json:"description,omitempty"`
|
||||
Lead User `json:"lead,omitempty"`
|
||||
Components []ProjectComponent `json:"components,omitempty"`
|
||||
IssueTypes []IssueType `json:"issueTypes,omitempty"`
|
||||
URL string `json:"url,omitempty"`
|
||||
Email string `json:"email,omitempty"`
|
||||
AssigneeType string `json:"assigneeType,omitempty"`
|
||||
Versions []interface{} `json:"versions,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Roles struct {
|
||||
Developers string `json:"Developers"`
|
||||
} `json:"roles"`
|
||||
AvatarUrls AvatarUrls `json:"avatarUrls"`
|
||||
ProjectCategory ProjectCategory `json:"projectCategory"`
|
||||
Developers string `json:"Developers,omitempty"`
|
||||
} `json:"roles,omitempty"`
|
||||
AvatarUrls AvatarUrls `json:"avatarUrls,omitempty"`
|
||||
ProjectCategory ProjectCategory `json:"projectCategory,omitempty"`
|
||||
}
|
||||
|
||||
// ProjectComponent represents a single component of a project
|
||||
type ProjectComponent struct {
|
||||
Self string `json:"self"`
|
||||
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.
|
||||
//
|
||||
// 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)
|
||||
req, err := s.client.NewRequest("GET", apiEndpoint, nil)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
project := new(FullProject)
|
||||
project := new(Project)
|
||||
resp, err := s.client.Do(req, project)
|
||||
if err != nil {
|
||||
return nil, resp, err
|
||||
|
@ -10,15 +10,15 @@ import (
|
||||
func TestProjectGetAll(t *testing.T) {
|
||||
setup()
|
||||
defer teardown()
|
||||
testApiEdpoint := "/rest/api/2/project"
|
||||
testAPIEdpoint := "/rest/api/2/project"
|
||||
|
||||
raw, err := ioutil.ReadFile("./mocks/all_projects.json")
|
||||
if err != nil {
|
||||
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")
|
||||
testRequestURL(t, r, testApiEdpoint)
|
||||
testRequestURL(t, r, testAPIEdpoint)
|
||||
fmt.Fprint(w, string(raw))
|
||||
})
|
||||
|
||||
@ -34,15 +34,15 @@ func TestProjectGetAll(t *testing.T) {
|
||||
func TestProjectGet(t *testing.T) {
|
||||
setup()
|
||||
defer teardown()
|
||||
testApiEdpoint := "/rest/api/2/project/12310505"
|
||||
testAPIEdpoint := "/rest/api/2/project/12310505"
|
||||
|
||||
raw, err := ioutil.ReadFile("./mocks/project.json")
|
||||
if err != nil {
|
||||
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")
|
||||
testRequestURL(t, r, testApiEdpoint)
|
||||
testRequestURL(t, r, testAPIEdpoint)
|
||||
fmt.Fprint(w, string(raw))
|
||||
})
|
||||
|
||||
@ -58,17 +58,17 @@ func TestProjectGet(t *testing.T) {
|
||||
func TestProjectGet_NoProject(t *testing.T) {
|
||||
setup()
|
||||
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")
|
||||
testRequestURL(t, r, testApiEdpoint)
|
||||
testRequestURL(t, r, testAPIEdpoint)
|
||||
fmt.Fprint(w, nil)
|
||||
})
|
||||
|
||||
projects, resp, err := testClient.Project.Get("99999999")
|
||||
if projects != nil {
|
||||
t.Errorf("Expected nil. Got %s", projects)
|
||||
t.Errorf("Expected nil. Got %+v", projects)
|
||||
}
|
||||
|
||||
if resp.Status == "404" {
|
||||
|
Loading…
Reference in New Issue
Block a user