mirror of
https://github.com/interviewstreet/go-jira.git
synced 2025-03-21 21:07:03 +02:00
Merge branch 'EvgenKostenko-master'
* EvgenKostenko-master: go fmt, go doc and reuse of Project struct Renamed "json_mocks" into "mocks" Refactored struct types by reusing already existing components Fixed typo in Cookies Moved progect.go to project.go refactor project tests + go fmt add one more test for project service delete uncompleted boards add fmt dependency to jira.go get Authenticated reports session from main repository Add project and tests Implement workload in issue and Project list Change Coocke session get from request
This commit is contained in:
commit
5e8f6f0fd0
@ -2,6 +2,7 @@ package jira
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// AuthenticationService handles authentication for the JIRA instance / API.
|
||||
@ -25,6 +26,7 @@ type Session struct {
|
||||
LastFailedLoginTime string `json:"lastFailedLoginTime"`
|
||||
PreviousLoginTime string `json:"previousLoginTime"`
|
||||
} `json:"loginInfo"`
|
||||
Cookies []*http.Cookie
|
||||
}
|
||||
|
||||
// AcquireSessionCookie creates a new session for a user in JIRA.
|
||||
@ -51,6 +53,8 @@ func (s *AuthenticationService) AcquireSessionCookie(username, password string)
|
||||
|
||||
session := new(Session)
|
||||
resp, err := s.client.Do(req, session)
|
||||
session.Cookies = resp.Cookies()
|
||||
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("Auth at JIRA instance failed (HTTP(S) request). %s", err)
|
||||
}
|
||||
|
97
issue.go
97
issue.go
@ -31,15 +31,15 @@ type Issue struct {
|
||||
|
||||
// Attachment represents a JIRA attachment
|
||||
type Attachment struct {
|
||||
Self string `json:"self,omitempty"`
|
||||
ID string `json:"id,omitempty"`
|
||||
Filename string `json:"filename,omitempty"`
|
||||
Author *Assignee `json:"author,omitempty"`
|
||||
Created string `json:"created,omitempty"`
|
||||
Size int `json:"size,omitempty"`
|
||||
MimeType string `json:"mimeType,omitempty"`
|
||||
Content string `json:"content,omitempty"`
|
||||
Thumbnail string `json:"thumbnail,omitempty"`
|
||||
Self string `json:"self,omitempty"`
|
||||
ID string `json:"id,omitempty"`
|
||||
Filename string `json:"filename,omitempty"`
|
||||
Author *User `json:"author,omitempty"`
|
||||
Created string `json:"created,omitempty"`
|
||||
Size int `json:"size,omitempty"`
|
||||
MimeType string `json:"mimeType,omitempty"`
|
||||
Content string `json:"content,omitempty"`
|
||||
Thumbnail string `json:"thumbnail,omitempty"`
|
||||
}
|
||||
|
||||
// IssueFields represents single fields of a JIRA issue.
|
||||
@ -55,7 +55,6 @@ type IssueFields struct {
|
||||
// * "timeoriginalestimate": null,
|
||||
// * "timetracking": {},
|
||||
// * "aggregatetimeestimate": null,
|
||||
// * "subtasks": [],
|
||||
// * "environment": null,
|
||||
// * "duedate": null,
|
||||
Type IssueType `json:"issuetype"`
|
||||
@ -65,21 +64,22 @@ type IssueFields struct {
|
||||
Resolutiondate string `json:"resolutiondate,omitempty"`
|
||||
Created string `json:"created,omitempty"`
|
||||
Watches *Watches `json:"watches,omitempty"`
|
||||
Assignee *Assignee `json:"assignee,omitempty"`
|
||||
Assignee *User `json:"assignee,omitempty"`
|
||||
Updated string `json:"updated,omitempty"`
|
||||
Description string `json:"description,omitempty"`
|
||||
Summary string `json:"summary"`
|
||||
Creator *Assignee `json:"Creator,omitempty"`
|
||||
Reporter *Assignee `json:"reporter,omitempty"`
|
||||
Creator *User `json:"Creator,omitempty"`
|
||||
Reporter *User `json:"reporter,omitempty"`
|
||||
Components []*Component `json:"components,omitempty"`
|
||||
Status *Status `json:"status,omitempty"`
|
||||
Progress *Progress `json:"progress,omitempty"`
|
||||
AggregateProgress *Progress `json:"aggregateprogress,omitempty"`
|
||||
Worklog []*Worklog `json:"worklog.worklogs,omitempty"`
|
||||
Worklog *Worklog `json:"worklog,omitempty"`
|
||||
IssueLinks []*IssueLink `json:"issuelinks,omitempty"`
|
||||
Comments []*Comment `json:"comment.comments,omitempty"`
|
||||
FixVersions []*FixVersion `json:"fixVersions,omitempty"`
|
||||
Labels []string `json:"labels,omitempty"`
|
||||
Subtasks []*Subtasks `json:"subtasks,omitempty"`
|
||||
Attachments []*Attachment `json:"attachment,omitempty"`
|
||||
}
|
||||
|
||||
@ -92,15 +92,7 @@ type IssueType struct {
|
||||
IconURL string `json:"iconUrl,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Subtask bool `json:"subtask,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"`
|
||||
AvatarID int `json:"avatarId,omitempty"`
|
||||
}
|
||||
|
||||
// Resolution represents a resolution of a JIRA issue.
|
||||
@ -128,14 +120,24 @@ type Watches struct {
|
||||
IsWatching bool `json:"isWatching,omitempty"`
|
||||
}
|
||||
|
||||
// Assignee represents a user who is this JIRA issue assigned to.
|
||||
type Assignee struct {
|
||||
Self string `json:"self,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
EmailAddress string `json:"emailAddress,omitempty"`
|
||||
AvatarURLs map[string]string `json:"avatarUrls,omitempty"`
|
||||
DisplayName string `json:"displayName,omitempty"`
|
||||
Active bool `json:"active,omitempty"`
|
||||
// User represents a user who is this JIRA issue assigned to.
|
||||
type User struct {
|
||||
Self string `json:"self,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Key string `json:"key,omitempty"`
|
||||
EmailAddress string `json:"emailAddress,omitempty"`
|
||||
AvatarUrls AvatarUrls `json:"avatarUrls,omitempty"`
|
||||
DisplayName string `json:"displayName,omitempty"`
|
||||
Active bool `json:"active,omitempty"`
|
||||
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"`
|
||||
One6X16 string `json:"16x16,omitempty"`
|
||||
Three2X32 string `json:"32x32,omitempty"`
|
||||
}
|
||||
|
||||
// Component represents a "component" of a JIRA issue.
|
||||
@ -175,9 +177,36 @@ 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 {
|
||||
// TODO Add Worklogs
|
||||
StartAt int `json:"startAt"`
|
||||
MaxResults int `json:"maxResults"`
|
||||
Total int `json:"total"`
|
||||
Worklogs []WorklogRecord `json:"worklogs"`
|
||||
}
|
||||
|
||||
// WorklogRecord represents one entry of a Worklog
|
||||
type WorklogRecord struct {
|
||||
Self string `json:"self"`
|
||||
Author User `json:"author"`
|
||||
UpdateAuthor User `json:"updateAuthor"`
|
||||
Comment string `json:"comment"`
|
||||
Created string `json:"created"`
|
||||
Updated string `json:"updated"`
|
||||
Started string `json:"started"`
|
||||
TimeSpent string `json:"timeSpent"`
|
||||
TimeSpentSeconds int `json:"timeSpentSeconds"`
|
||||
ID string `json:"id"`
|
||||
IssueID string `json:"issueId"`
|
||||
}
|
||||
|
||||
// Subtasks represents all issues of a parent issue.
|
||||
type Subtasks struct {
|
||||
ID string `json:"id"`
|
||||
Key string `json:"key"`
|
||||
Self string `json:"self"`
|
||||
Fields IssueFields `json:"fields"`
|
||||
}
|
||||
|
||||
// IssueLink represents a link between two issues in JIRA.
|
||||
@ -204,9 +233,9 @@ type IssueLinkType struct {
|
||||
type Comment struct {
|
||||
Self string `json:"self,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Author Assignee `json:"author,omitempty"`
|
||||
Author User `json:"author,omitempty"`
|
||||
Body string `json:"body,omitempty"`
|
||||
UpdateAuthor Assignee `json:"updateAuthor,omitempty"`
|
||||
UpdateAuthor User `json:"updateAuthor,omitempty"`
|
||||
Updated string `json:"updated,omitempty"`
|
||||
Created string `json:"created,omitempty"`
|
||||
Visibility CommentVisibility `json:"visibility,omitempty"`
|
||||
|
6
jira.go
6
jira.go
@ -23,6 +23,7 @@ type Client struct {
|
||||
// Services used for talking to different parts of the JIRA API.
|
||||
Authentication *AuthenticationService
|
||||
Issue *IssueService
|
||||
Project *ProjectService
|
||||
}
|
||||
|
||||
// NewClient returns a new JIRA API client.
|
||||
@ -48,6 +49,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}
|
||||
|
||||
return c, nil
|
||||
}
|
||||
@ -82,7 +84,9 @@ func (c *Client) NewRequest(method, urlStr string, body interface{}) (*http.Requ
|
||||
|
||||
// Set session cookie if there is one
|
||||
if c.session != nil {
|
||||
req.Header.Set("Cookie", fmt.Sprintf("%s=%s", c.session.Session.Name, c.session.Session.Value))
|
||||
for _, cookie := range c.session.Cookies {
|
||||
req.AddCookie(cookie)
|
||||
}
|
||||
}
|
||||
|
||||
return req, nil
|
||||
|
9872
mocks/all_projects.json
Normal file
9872
mocks/all_projects.json
Normal file
File diff suppressed because it is too large
Load Diff
411
mocks/project.json
Normal file
411
mocks/project.json
Normal file
@ -0,0 +1,411 @@
|
||||
{
|
||||
"expand": "projectKeys",
|
||||
"self": "https://issues.apache.org/jira/rest/api/2/project/12310505",
|
||||
"id": "12310505",
|
||||
"key": "ABDERA",
|
||||
"description": "The Abdera project is an implementation of the Atom Syndication Format (RFC4287) and the Atom Publishing Protocol specifications published by the IETF Atompub working group.",
|
||||
"lead": {
|
||||
"self": "https://issues.apache.org/jira/rest/api/2/user?username=rooneg",
|
||||
"key": "rooneg",
|
||||
"name": "rooneg",
|
||||
"avatarUrls": {
|
||||
"48x48": "https://issues.apache.org/jira/secure/useravatar?avatarId=10452",
|
||||
"24x24": "https://issues.apache.org/jira/secure/useravatar?size=small&avatarId=10452",
|
||||
"16x16": "https://issues.apache.org/jira/secure/useravatar?size=xsmall&avatarId=10452",
|
||||
"32x32": "https://issues.apache.org/jira/secure/useravatar?size=medium&avatarId=10452"
|
||||
},
|
||||
"displayName": "Garrett Rooney",
|
||||
"active": true
|
||||
},
|
||||
"components": [],
|
||||
"issueTypes": [
|
||||
{
|
||||
"self": "https://issues.apache.org/jira/rest/api/2/issuetype/1",
|
||||
"id": "1",
|
||||
"description": "A problem which impairs or prevents the functions of the product.",
|
||||
"iconUrl": "https://issues.apache.org/jira/images/icons/issuetypes/bug.png",
|
||||
"name": "Bug",
|
||||
"subtask": false
|
||||
},
|
||||
{
|
||||
"self": "https://issues.apache.org/jira/rest/api/2/issuetype/2",
|
||||
"id": "2",
|
||||
"description": "A new feature of the product, which has yet to be developed.",
|
||||
"iconUrl": "https://issues.apache.org/jira/images/icons/issuetypes/newfeature.png",
|
||||
"name": "New Feature",
|
||||
"subtask": false
|
||||
},
|
||||
{
|
||||
"self": "https://issues.apache.org/jira/rest/api/2/issuetype/4",
|
||||
"id": "4",
|
||||
"description": "An improvement or enhancement to an existing feature or task.",
|
||||
"iconUrl": "https://issues.apache.org/jira/images/icons/issuetypes/improvement.png",
|
||||
"name": "Improvement",
|
||||
"subtask": false
|
||||
},
|
||||
{
|
||||
"self": "https://issues.apache.org/jira/rest/api/2/issuetype/6",
|
||||
"id": "6",
|
||||
"description": "A new unit, integration or system test.",
|
||||
"iconUrl": "https://issues.apache.org/jira/images/icons/issuetypes/requirement.png",
|
||||
"name": "Test",
|
||||
"subtask": false
|
||||
},
|
||||
{
|
||||
"self": "https://issues.apache.org/jira/rest/api/2/issuetype/5",
|
||||
"id": "5",
|
||||
"description": "General wishlist item.",
|
||||
"iconUrl": "https://issues.apache.org/jira/images/icons/issuetypes/improvement.png",
|
||||
"name": "Wish",
|
||||
"subtask": false
|
||||
},
|
||||
{
|
||||
"self": "https://issues.apache.org/jira/rest/api/2/issuetype/3",
|
||||
"id": "3",
|
||||
"description": "A task that needs to be done.",
|
||||
"iconUrl": "https://issues.apache.org/jira/images/icons/issuetypes/task.png",
|
||||
"name": "Task",
|
||||
"subtask": false
|
||||
},
|
||||
{
|
||||
"self": "https://issues.apache.org/jira/rest/api/2/issuetype/7",
|
||||
"id": "7",
|
||||
"description": "The sub-task of the issue",
|
||||
"iconUrl": "https://issues.apache.org/jira/images/icons/issuetypes/subtask_alternate.png",
|
||||
"name": "Sub-task",
|
||||
"subtask": true
|
||||
},
|
||||
{
|
||||
"self": "https://issues.apache.org/jira/rest/api/2/issuetype/8",
|
||||
"id": "8",
|
||||
"description": "A request for a new JIRA project to be set up",
|
||||
"iconUrl": "https://issues.apache.org/jira/images/icons/jiraman18.gif",
|
||||
"name": "New JIRA Project",
|
||||
"subtask": false
|
||||
},
|
||||
{
|
||||
"self": "https://issues.apache.org/jira/rest/api/2/issuetype/9",
|
||||
"id": "9",
|
||||
"description": "An RTC request",
|
||||
"iconUrl": "https://issues.apache.org/jira/images/icons/issuetypes/newfeature.png",
|
||||
"name": "RTC",
|
||||
"subtask": false
|
||||
},
|
||||
{
|
||||
"self": "https://issues.apache.org/jira/rest/api/2/issuetype/10",
|
||||
"id": "10",
|
||||
"description": "Challenges made against the Sun Compatibility Test Suite",
|
||||
"iconUrl": "https://issues.apache.org/jira/images/icons/issuetypes/task.png",
|
||||
"name": "TCK Challenge",
|
||||
"subtask": false
|
||||
},
|
||||
{
|
||||
"self": "https://issues.apache.org/jira/rest/api/2/issuetype/11",
|
||||
"id": "11",
|
||||
"description": "A formal question. Initially added for the Legal JIRA.",
|
||||
"iconUrl": "https://issues.apache.org/jira/images/icons/issuetypes/genericissue.png",
|
||||
"name": "Question",
|
||||
"subtask": false
|
||||
},
|
||||
{
|
||||
"self": "https://issues.apache.org/jira/rest/api/2/issuetype/12",
|
||||
"id": "12",
|
||||
"description": "",
|
||||
"iconUrl": "https://issues.apache.org/jira/images/icons/issuetypes/genericissue.png",
|
||||
"name": "Temp",
|
||||
"subtask": false
|
||||
},
|
||||
{
|
||||
"self": "https://issues.apache.org/jira/rest/api/2/issuetype/13",
|
||||
"id": "13",
|
||||
"description": "A place to record back and forth on notions not yet formed enough to make a 'New Feature' or 'Task'",
|
||||
"iconUrl": "https://issues.apache.org/jira/images/icons/issuetypes/genericissue.png",
|
||||
"name": "Brainstorming",
|
||||
"subtask": false
|
||||
},
|
||||
{
|
||||
"self": "https://issues.apache.org/jira/rest/api/2/issuetype/14",
|
||||
"id": "14",
|
||||
"description": "An overarching type made of sub-tasks",
|
||||
"iconUrl": "https://issues.apache.org/jira/images/icons/issuetypes/genericissue.png",
|
||||
"name": "Umbrella",
|
||||
"subtask": false
|
||||
},
|
||||
{
|
||||
"self": "https://issues.apache.org/jira/rest/api/2/issuetype/15",
|
||||
"id": "15",
|
||||
"description": "Created by JIRA Agile - do not edit or delete. Issue type for a big user story that needs to be broken down.",
|
||||
"iconUrl": "https://issues.apache.org/jira/images/icons/issuetypes/epic.png",
|
||||
"name": "Epic",
|
||||
"subtask": false
|
||||
},
|
||||
{
|
||||
"self": "https://issues.apache.org/jira/rest/api/2/issuetype/16",
|
||||
"id": "16",
|
||||
"description": "Created by JIRA Agile - do not edit or delete. Issue type for a user story.",
|
||||
"iconUrl": "https://issues.apache.org/jira/images/icons/issuetypes/story.png",
|
||||
"name": "Story",
|
||||
"subtask": false
|
||||
},
|
||||
{
|
||||
"self": "https://issues.apache.org/jira/rest/api/2/issuetype/17",
|
||||
"id": "17",
|
||||
"description": "A technical task.",
|
||||
"iconUrl": "https://issues.apache.org/jira/images/icons/issuetypes/task_agile.png",
|
||||
"name": "Technical task",
|
||||
"subtask": true
|
||||
},
|
||||
{
|
||||
"self": "https://issues.apache.org/jira/rest/api/2/issuetype/18",
|
||||
"id": "18",
|
||||
"description": "Upgrading a dependency to a newer version",
|
||||
"iconUrl": "https://issues.apache.org/jira/images/icons/issuetypes/improvement.png",
|
||||
"name": "Dependency upgrade",
|
||||
"subtask": false
|
||||
},
|
||||
{
|
||||
"self": "https://issues.apache.org/jira/rest/api/2/issuetype/19",
|
||||
"id": "19",
|
||||
"description": "A search for a suitable name for an Apache product",
|
||||
"iconUrl": "https://issues.apache.org/jira/images/icons/issuetypes/requirement.png",
|
||||
"name": "Suitable Name Search",
|
||||
"subtask": false
|
||||
},
|
||||
{
|
||||
"self": "https://issues.apache.org/jira/rest/api/2/issuetype/20",
|
||||
"id": "20",
|
||||
"description": "Documentation or Website",
|
||||
"iconUrl": "https://issues.apache.org/jira/images/icons/issuetypes/documentation.png",
|
||||
"name": "Documentation",
|
||||
"subtask": false
|
||||
},
|
||||
{
|
||||
"self": "https://issues.apache.org/jira/rest/api/2/issuetype/10000",
|
||||
"id": "10000",
|
||||
"description": "Assigned specifically to Contractors by the VP Infra or or other VP/ Board Member.",
|
||||
"iconUrl": "https://issues.apache.org/jira/images/icons/issuetypes/sales.png",
|
||||
"name": "Planned Work",
|
||||
"subtask": false
|
||||
},
|
||||
{
|
||||
"self": "https://issues.apache.org/jira/rest/api/2/issuetype/10100",
|
||||
"id": "10100",
|
||||
"description": "A request for a new Confluence Wiki to be set up",
|
||||
"iconUrl": "https://issues.apache.org/jira/secure/viewavatar?size=xsmall&avatarId=23211&avatarType=issuetype",
|
||||
"name": "New Confluence Wiki",
|
||||
"subtask": false
|
||||
},
|
||||
{
|
||||
"self": "https://issues.apache.org/jira/rest/api/2/issuetype/10200",
|
||||
"id": "10200",
|
||||
"description": "",
|
||||
"iconUrl": "https://issues.apache.org/jira/secure/viewavatar?size=xsmall&avatarId=21140&avatarType=issuetype",
|
||||
"name": "New Git Repo",
|
||||
"subtask": false
|
||||
},
|
||||
{
|
||||
"self": "https://issues.apache.org/jira/rest/api/2/issuetype/10201",
|
||||
"id": "10201",
|
||||
"description": "",
|
||||
"iconUrl": "https://issues.apache.org/jira/secure/viewavatar?size=xsmall&avatarId=21130&avatarType=issuetype",
|
||||
"name": "Github Integration",
|
||||
"subtask": false
|
||||
},
|
||||
{
|
||||
"self": "https://issues.apache.org/jira/rest/api/2/issuetype/10202",
|
||||
"id": "10202",
|
||||
"description": "",
|
||||
"iconUrl": "https://issues.apache.org/jira/secure/viewavatar?size=xsmall&avatarId=21130&avatarType=issuetype",
|
||||
"name": "New TLP ",
|
||||
"subtask": false
|
||||
},
|
||||
{
|
||||
"self": "https://issues.apache.org/jira/rest/api/2/issuetype/10204",
|
||||
"id": "10204",
|
||||
"description": "",
|
||||
"iconUrl": "https://issues.apache.org/jira/secure/viewavatar?size=xsmall&avatarId=21130&avatarType=issuetype",
|
||||
"name": "New TLP - Common Tasks",
|
||||
"subtask": false
|
||||
},
|
||||
{
|
||||
"self": "https://issues.apache.org/jira/rest/api/2/issuetype/10205",
|
||||
"id": "10205",
|
||||
"description": "",
|
||||
"iconUrl": "https://issues.apache.org/jira/secure/viewavatar?size=xsmall&avatarId=21134&avatarType=issuetype",
|
||||
"name": "SVN->GIT Migration",
|
||||
"subtask": false
|
||||
},
|
||||
{
|
||||
"self": "https://issues.apache.org/jira/rest/api/2/issuetype/10206",
|
||||
"id": "10206",
|
||||
"description": "",
|
||||
"iconUrl": "https://issues.apache.org/jira/secure/viewavatar?size=xsmall&avatarId=21130&avatarType=issuetype",
|
||||
"name": "Blog - New Blog Request",
|
||||
"subtask": false
|
||||
},
|
||||
{
|
||||
"self": "https://issues.apache.org/jira/rest/api/2/issuetype/10207",
|
||||
"id": "10207",
|
||||
"description": "",
|
||||
"iconUrl": "https://issues.apache.org/jira/secure/viewavatar?size=xsmall&avatarId=21130&avatarType=issuetype",
|
||||
"name": "Blogs - New Blog User Account Request",
|
||||
"subtask": false
|
||||
},
|
||||
{
|
||||
"self": "https://issues.apache.org/jira/rest/api/2/issuetype/10208",
|
||||
"id": "10208",
|
||||
"description": "",
|
||||
"iconUrl": "https://issues.apache.org/jira/secure/viewavatar?size=xsmall&avatarId=21130&avatarType=issuetype",
|
||||
"name": "Blogs - Access to Existing Blog",
|
||||
"subtask": false
|
||||
},
|
||||
{
|
||||
"self": "https://issues.apache.org/jira/rest/api/2/issuetype/10209",
|
||||
"id": "10209",
|
||||
"description": "",
|
||||
"iconUrl": "https://issues.apache.org/jira/secure/viewavatar?size=xsmall&avatarId=21130&avatarType=issuetype",
|
||||
"name": "New Bugzilla Project",
|
||||
"subtask": false
|
||||
},
|
||||
{
|
||||
"self": "https://issues.apache.org/jira/rest/api/2/issuetype/10210",
|
||||
"id": "10210",
|
||||
"description": "",
|
||||
"iconUrl": "https://issues.apache.org/jira/secure/viewavatar?size=xsmall&avatarId=21130&avatarType=issuetype",
|
||||
"name": "SVN->GIT Mirroring",
|
||||
"subtask": false
|
||||
},
|
||||
{
|
||||
"self": "https://issues.apache.org/jira/rest/api/2/issuetype/10300",
|
||||
"id": "10300",
|
||||
"description": "For general IT problems and questions. Created by JIRA Service Desk.",
|
||||
"iconUrl": "https://issues.apache.org/jira/servicedesk/issue-type-icons?icon=it-help",
|
||||
"name": "IT Help",
|
||||
"subtask": false
|
||||
},
|
||||
{
|
||||
"self": "https://issues.apache.org/jira/rest/api/2/issuetype/10301",
|
||||
"id": "10301",
|
||||
"description": "For new system accounts or passwords. Created by JIRA Service Desk.",
|
||||
"iconUrl": "https://issues.apache.org/jira/servicedesk/issue-type-icons?icon=access",
|
||||
"name": "Access",
|
||||
"subtask": false
|
||||
},
|
||||
{
|
||||
"self": "https://issues.apache.org/jira/rest/api/2/issuetype/10400",
|
||||
"id": "10400",
|
||||
"description": "",
|
||||
"iconUrl": "https://issues.apache.org/jira/images/icons/issuetypes/genericissue.png",
|
||||
"name": "Request",
|
||||
"subtask": false
|
||||
}
|
||||
],
|
||||
"url": "http://abdera.apache.org",
|
||||
"assigneeType": "UNASSIGNED",
|
||||
"versions": [
|
||||
{
|
||||
"self": "https://issues.apache.org/jira/rest/api/2/version/12312506",
|
||||
"id": "12312506",
|
||||
"name": "0.2.2",
|
||||
"archived": false,
|
||||
"released": true,
|
||||
"releaseDate": "2007-02-19",
|
||||
"userReleaseDate": "19/Feb/07",
|
||||
"projectId": 12310505
|
||||
},
|
||||
{
|
||||
"self": "https://issues.apache.org/jira/rest/api/2/version/12312507",
|
||||
"id": "12312507",
|
||||
"name": "0.3.0",
|
||||
"archived": false,
|
||||
"released": true,
|
||||
"releaseDate": "2007-10-05",
|
||||
"userReleaseDate": "05/Oct/07",
|
||||
"projectId": 12310505
|
||||
},
|
||||
{
|
||||
"self": "https://issues.apache.org/jira/rest/api/2/version/12312825",
|
||||
"id": "12312825",
|
||||
"name": "0.4.0",
|
||||
"archived": false,
|
||||
"released": true,
|
||||
"releaseDate": "2008-04-11",
|
||||
"userReleaseDate": "11/Apr/08",
|
||||
"projectId": 12310505
|
||||
},
|
||||
{
|
||||
"self": "https://issues.apache.org/jira/rest/api/2/version/12313105",
|
||||
"id": "12313105",
|
||||
"name": "1.0",
|
||||
"archived": false,
|
||||
"released": true,
|
||||
"releaseDate": "2010-05-02",
|
||||
"userReleaseDate": "02/May/10",
|
||||
"projectId": 12310505
|
||||
},
|
||||
{
|
||||
"self": "https://issues.apache.org/jira/rest/api/2/version/12314990",
|
||||
"id": "12314990",
|
||||
"name": "1.1",
|
||||
"archived": false,
|
||||
"released": true,
|
||||
"releaseDate": "2010-07-11",
|
||||
"userReleaseDate": "11/Jul/10",
|
||||
"projectId": 12310505
|
||||
},
|
||||
{
|
||||
"self": "https://issues.apache.org/jira/rest/api/2/version/12315922",
|
||||
"id": "12315922",
|
||||
"name": "1.1.1",
|
||||
"archived": false,
|
||||
"released": true,
|
||||
"releaseDate": "2010-12-06",
|
||||
"userReleaseDate": "06/Dec/10",
|
||||
"projectId": 12310505
|
||||
},
|
||||
{
|
||||
"self": "https://issues.apache.org/jira/rest/api/2/version/12316041",
|
||||
"id": "12316041",
|
||||
"name": "1.1.2",
|
||||
"archived": false,
|
||||
"released": true,
|
||||
"releaseDate": "2011-01-15",
|
||||
"userReleaseDate": "15/Jan/11",
|
||||
"projectId": 12310505
|
||||
},
|
||||
{
|
||||
"self": "https://issues.apache.org/jira/rest/api/2/version/12323557",
|
||||
"id": "12323557",
|
||||
"name": "1.1.3",
|
||||
"archived": false,
|
||||
"released": false,
|
||||
"projectId": 12310505
|
||||
},
|
||||
{
|
||||
"self": "https://issues.apache.org/jira/rest/api/2/version/12316141",
|
||||
"id": "12316141",
|
||||
"name": "1.2",
|
||||
"archived": false,
|
||||
"released": false,
|
||||
"projectId": 12310505
|
||||
}
|
||||
],
|
||||
"name": "Abdera",
|
||||
"roles": {
|
||||
"Service Desk Team": "https://issues.apache.org/jira/rest/api/2/project/12310505/role/10251",
|
||||
"Developers": "https://issues.apache.org/jira/rest/api/2/project/12310505/role/10050",
|
||||
"Service Desk Customers": "https://issues.apache.org/jira/rest/api/2/project/12310505/role/10250",
|
||||
"Contributors": "https://issues.apache.org/jira/rest/api/2/project/12310505/role/10010",
|
||||
"PMC": "https://issues.apache.org/jira/rest/api/2/project/12310505/role/10011",
|
||||
"Committers": "https://issues.apache.org/jira/rest/api/2/project/12310505/role/10001",
|
||||
"Administrators": "https://issues.apache.org/jira/rest/api/2/project/12310505/role/10002",
|
||||
"ASF Members": "https://issues.apache.org/jira/rest/api/2/project/12310505/role/10150",
|
||||
"Users": "https://issues.apache.org/jira/rest/api/2/project/12310505/role/10040"
|
||||
},
|
||||
"avatarUrls": {
|
||||
"48x48": "https://issues.apache.org/jira/secure/projectavatar?pid=12310505&avatarId=10011",
|
||||
"24x24": "https://issues.apache.org/jira/secure/projectavatar?size=small&pid=12310505&avatarId=10011",
|
||||
"16x16": "https://issues.apache.org/jira/secure/projectavatar?size=xsmall&pid=12310505&avatarId=10011",
|
||||
"32x32": "https://issues.apache.org/jira/secure/projectavatar?size=medium&pid=12310505&avatarId=10011"
|
||||
}
|
||||
}
|
109
project.go
Normal file
109
project.go
Normal file
@ -0,0 +1,109 @@
|
||||
package jira
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"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
|
||||
}
|
||||
|
||||
// ProjectList represent a list of Projects
|
||||
type ProjectList []struct {
|
||||
Expand string `json:"expand"`
|
||||
Self string `json:"self"`
|
||||
ID string `json:"id"`
|
||||
Key string `json:"key"`
|
||||
Name string `json:"name"`
|
||||
AvatarUrls AvatarUrls `json:"avatarUrls"`
|
||||
ProjectTypeKey string `json:"projectTypeKey"`
|
||||
ProjectCategory ProjectCategory `json:"projectCategory,omitempty"`
|
||||
}
|
||||
|
||||
// ProjectCategory represents a single project category
|
||||
type ProjectCategory struct {
|
||||
Self string `json:"self"`
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
}
|
||||
|
||||
// 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,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"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
Lead User `json:"lead"`
|
||||
AssigneeType string `json:"assigneeType"`
|
||||
Assignee User `json:"assignee"`
|
||||
RealAssigneeType string `json:"realAssigneeType"`
|
||||
RealAssignee User `json:"realAssignee"`
|
||||
IsAssigneeTypeValid bool `json:"isAssigneeTypeValid"`
|
||||
Project string `json:"project"`
|
||||
ProjectID int `json:"projectId"`
|
||||
}
|
||||
|
||||
// GetList gets all projects form JIRA
|
||||
//
|
||||
// JIRA API docs: https://docs.atlassian.com/jira/REST/latest/#api/2/project-getAllProjects
|
||||
func (s *ProjectService) GetList() (*ProjectList, *http.Response, error) {
|
||||
apiEndpoint := "rest/api/2/project"
|
||||
req, err := s.client.NewRequest("GET", apiEndpoint, nil)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
projectList := new(ProjectList)
|
||||
resp, err := s.client.Do(req, projectList)
|
||||
if err != nil {
|
||||
return nil, resp, err
|
||||
}
|
||||
return projectList, resp, nil
|
||||
}
|
||||
|
||||
// Get returns a full representation of the project for the given issue key.
|
||||
// JIRA will attempt to identify the project by the projectIdOrKey path parameter.
|
||||
// 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) (*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(Project)
|
||||
resp, err := s.client.Do(req, project)
|
||||
if err != nil {
|
||||
return nil, resp, err
|
||||
}
|
||||
return project, resp, nil
|
||||
}
|
80
project_test.go
Normal file
80
project_test.go
Normal file
@ -0,0 +1,80 @@
|
||||
package jira
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestProjectGetAll(t *testing.T) {
|
||||
setup()
|
||||
defer teardown()
|
||||
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) {
|
||||
testMethod(t, r, "GET")
|
||||
testRequestURL(t, r, testAPIEdpoint)
|
||||
fmt.Fprint(w, string(raw))
|
||||
})
|
||||
|
||||
projects, _, err := testClient.Project.GetList()
|
||||
if projects == nil {
|
||||
t.Error("Expected project list. Project list is nil")
|
||||
}
|
||||
if err != nil {
|
||||
t.Errorf("Error given: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestProjectGet(t *testing.T) {
|
||||
setup()
|
||||
defer teardown()
|
||||
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) {
|
||||
testMethod(t, r, "GET")
|
||||
testRequestURL(t, r, testAPIEdpoint)
|
||||
fmt.Fprint(w, string(raw))
|
||||
})
|
||||
|
||||
projects, _, err := testClient.Project.Get("12310505")
|
||||
if projects == nil {
|
||||
t.Error("Expected project list. Project list is nil")
|
||||
}
|
||||
if err != nil {
|
||||
t.Errorf("Error given: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestProjectGet_NoProject(t *testing.T) {
|
||||
setup()
|
||||
defer teardown()
|
||||
testAPIEdpoint := "/rest/api/2/project/99999999"
|
||||
|
||||
testMux.HandleFunc(testAPIEdpoint, func(w http.ResponseWriter, r *http.Request) {
|
||||
testMethod(t, r, "GET")
|
||||
testRequestURL(t, r, testAPIEdpoint)
|
||||
fmt.Fprint(w, nil)
|
||||
})
|
||||
|
||||
projects, resp, err := testClient.Project.Get("99999999")
|
||||
if projects != nil {
|
||||
t.Errorf("Expected nil. Got %+v", projects)
|
||||
}
|
||||
|
||||
if resp.Status == "404" {
|
||||
t.Errorf("Expected status 404. Got %s", resp.Status)
|
||||
}
|
||||
if err == nil {
|
||||
t.Errorf("Error given: %s", err)
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user