mirror of
https://github.com/interviewstreet/go-jira.git
synced 2024-11-28 08:39:03 +02:00
Merge branch 'master' of https://github.com/EvgenKostenko/go-jira into EvgenKostenko-master
* 'master' of https://github.com/EvgenKostenko/go-jira: 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
47c547b9ff
@ -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"`
|
||||
SetCoockie []*http.Cookie
|
||||
}
|
||||
|
||||
// AcquireSessionCookie creates a new session for a user in JIRA.
|
||||
@ -51,6 +53,10 @@ func (s *AuthenticationService) AcquireSessionCookie(username, password string)
|
||||
|
||||
session := new(Session)
|
||||
resp, err := s.client.Do(req, session)
|
||||
|
||||
cookies := resp.Cookies()
|
||||
session.SetCoockie = cookies
|
||||
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("Auth at JIRA instance failed (HTTP(S) request). %s", err)
|
||||
}
|
||||
|
87
issue.go
87
issue.go
@ -55,7 +55,6 @@ type IssueFields struct {
|
||||
// * "timeoriginalestimate": null,
|
||||
// * "timetracking": {},
|
||||
// * "aggregatetimeestimate": null,
|
||||
// * "subtasks": [],
|
||||
// * "environment": null,
|
||||
// * "duedate": null,
|
||||
Type IssueType `json:"issuetype"`
|
||||
@ -75,11 +74,12 @@ type IssueFields struct {
|
||||
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"`
|
||||
}
|
||||
|
||||
@ -177,7 +177,88 @@ type Progress struct {
|
||||
// Worklog represents the work log of a JIRA issue.
|
||||
// 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 []struct {
|
||||
Self string `json:"self"`
|
||||
Author struct {
|
||||
Self string `json:"self"`
|
||||
Name string `json:"name"`
|
||||
Key string `json:"key"`
|
||||
EmailAddress string `json:"emailAddress"`
|
||||
AvatarUrls struct {
|
||||
Four8X48 string `json:"48x48"`
|
||||
Two4X24 string `json:"24x24"`
|
||||
One6X16 string `json:"16x16"`
|
||||
Three2X32 string `json:"32x32"`
|
||||
} `json:"avatarUrls"`
|
||||
DisplayName string `json:"displayName"`
|
||||
Active bool `json:"active"`
|
||||
TimeZone string `json:"timeZone"`
|
||||
} `json:"author"`
|
||||
UpdateAuthor struct {
|
||||
Self string `json:"self"`
|
||||
Name string `json:"name"`
|
||||
Key string `json:"key"`
|
||||
EmailAddress string `json:"emailAddress"`
|
||||
AvatarUrls struct {
|
||||
Four8X48 string `json:"48x48"`
|
||||
Two4X24 string `json:"24x24"`
|
||||
One6X16 string `json:"16x16"`
|
||||
Three2X32 string `json:"32x32"`
|
||||
} `json:"avatarUrls"`
|
||||
DisplayName string `json:"displayName"`
|
||||
Active bool `json:"active"`
|
||||
TimeZone string `json:"timeZone"`
|
||||
} `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"`
|
||||
} `json:"worklogs"`
|
||||
}
|
||||
|
||||
type Subtasks struct {
|
||||
ID string `json:"id"`
|
||||
Key string `json:"key"`
|
||||
Self string `json:"self"`
|
||||
Fields struct {
|
||||
Summary string `json:"summary"`
|
||||
Status struct {
|
||||
Self string `json:"self"`
|
||||
Description string `json:"description"`
|
||||
IconURL string `json:"iconUrl"`
|
||||
Name string `json:"name"`
|
||||
ID string `json:"id"`
|
||||
StatusCategory struct {
|
||||
Self string `json:"self"`
|
||||
ID int `json:"id"`
|
||||
Key string `json:"key"`
|
||||
ColorName string `json:"colorName"`
|
||||
Name string `json:"name"`
|
||||
} `json:"statusCategory"`
|
||||
} `json:"status"`
|
||||
Priority struct {
|
||||
Self string `json:"self"`
|
||||
IconURL string `json:"iconUrl"`
|
||||
Name string `json:"name"`
|
||||
ID string `json:"id"`
|
||||
} `json:"priority"`
|
||||
Issuetype struct {
|
||||
Self string `json:"self"`
|
||||
ID string `json:"id"`
|
||||
Description string `json:"description"`
|
||||
IconURL string `json:"iconUrl"`
|
||||
Name string `json:"name"`
|
||||
Subtask bool `json:"subtask"`
|
||||
AvatarID int `json:"avatarId"`
|
||||
} `json:"issuetype"`
|
||||
} `json:"fields"`
|
||||
}
|
||||
|
||||
// IssueLink represents a link between two issues in JIRA.
|
||||
|
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.SetCoockie {
|
||||
req.AddCookie(cookie)
|
||||
}
|
||||
}
|
||||
|
||||
return req, nil
|
||||
|
9872
json_mocks/all_projects.json
Normal file
9872
json_mocks/all_projects.json
Normal file
File diff suppressed because it is too large
Load Diff
411
json_mocks/project.json
Normal file
411
json_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"
|
||||
}
|
||||
}
|
171
progect.go
Normal file
171
progect.go
Normal file
@ -0,0 +1,171 @@
|
||||
package jira
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type ProjectService struct {
|
||||
client *Client
|
||||
}
|
||||
|
||||
// Project list type
|
||||
type ProjectList []struct {
|
||||
Expand string `json:"expand"`
|
||||
Self string `json:"self"`
|
||||
ID string `json:"id"`
|
||||
Key string `json:"key"`
|
||||
Name string `json:"name"`
|
||||
AvatarUrls struct {
|
||||
Four8X48 string `json:"48x48"`
|
||||
Two4X24 string `json:"24x24"`
|
||||
One6X16 string `json:"16x16"`
|
||||
Three2X32 string `json:"32x32"`
|
||||
} `json:"avatarUrls"`
|
||||
ProjectTypeKey string `json:"projectTypeKey"`
|
||||
ProjectCategory struct {
|
||||
Self string `json:"self"`
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
} `json:"projectCategory,omitempty"`
|
||||
}
|
||||
|
||||
// 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 struct {
|
||||
Self string `json:"self"`
|
||||
Name string `json:"name"`
|
||||
AvatarUrls struct {
|
||||
Four8X48 string `json:"48x48"`
|
||||
Two4X24 string `json:"24x24"`
|
||||
One6X16 string `json:"16x16"`
|
||||
Three2X32 string `json:"32x32"`
|
||||
} `json:"avatarUrls"`
|
||||
DisplayName string `json:"displayName"`
|
||||
Active bool `json:"active"`
|
||||
} `json:"lead"`
|
||||
Components []struct {
|
||||
Self string `json:"self"`
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
Lead struct {
|
||||
Self string `json:"self"`
|
||||
Name string `json:"name"`
|
||||
AvatarUrls struct {
|
||||
Four8X48 string `json:"48x48"`
|
||||
Two4X24 string `json:"24x24"`
|
||||
One6X16 string `json:"16x16"`
|
||||
Three2X32 string `json:"32x32"`
|
||||
} `json:"avatarUrls"`
|
||||
DisplayName string `json:"displayName"`
|
||||
Active bool `json:"active"`
|
||||
} `json:"lead"`
|
||||
AssigneeType string `json:"assigneeType"`
|
||||
Assignee struct {
|
||||
Self string `json:"self"`
|
||||
Name string `json:"name"`
|
||||
AvatarUrls struct {
|
||||
Four8X48 string `json:"48x48"`
|
||||
Two4X24 string `json:"24x24"`
|
||||
One6X16 string `json:"16x16"`
|
||||
Three2X32 string `json:"32x32"`
|
||||
} `json:"avatarUrls"`
|
||||
DisplayName string `json:"displayName"`
|
||||
Active bool `json:"active"`
|
||||
} `json:"assignee"`
|
||||
RealAssigneeType string `json:"realAssigneeType"`
|
||||
RealAssignee struct {
|
||||
Self string `json:"self"`
|
||||
Name string `json:"name"`
|
||||
AvatarUrls struct {
|
||||
Four8X48 string `json:"48x48"`
|
||||
Two4X24 string `json:"24x24"`
|
||||
One6X16 string `json:"16x16"`
|
||||
Three2X32 string `json:"32x32"`
|
||||
} `json:"avatarUrls"`
|
||||
DisplayName string `json:"displayName"`
|
||||
Active bool `json:"active"`
|
||||
} `json:"realAssignee"`
|
||||
IsAssigneeTypeValid bool `json:"isAssigneeTypeValid"`
|
||||
Project string `json:"project"`
|
||||
ProjectID int `json:"projectId"`
|
||||
} `json:"components"`
|
||||
IssueTypes []struct {
|
||||
Self string `json:"self"`
|
||||
ID string `json:"id"`
|
||||
Description string `json:"description"`
|
||||
IconURL string `json:"iconUrl"`
|
||||
Name string `json:"name"`
|
||||
Subtask bool `json:"subtask"`
|
||||
AvatarID int `json:"avatarId"`
|
||||
} `json:"issueTypes"`
|
||||
URL string `json:"url"`
|
||||
Email string `json:"email"`
|
||||
AssigneeType string `json:"assigneeType"`
|
||||
Versions []interface{} `json:"versions"`
|
||||
Name string `json:"name"`
|
||||
Roles struct {
|
||||
Developers string `json:"Developers"`
|
||||
} `json:"roles"`
|
||||
AvatarUrls struct {
|
||||
Four8X48 string `json:"48x48"`
|
||||
Two4X24 string `json:"24x24"`
|
||||
One6X16 string `json:"16x16"`
|
||||
Three2X32 string `json:"32x32"`
|
||||
} `json:"avatarUrls"`
|
||||
ProjectCategory struct {
|
||||
Self string `json:"self"`
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
} `json:"projectCategory"`
|
||||
}
|
||||
|
||||
// Get 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) (*FullProject, *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)
|
||||
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("./json_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("./json_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 %s", projects)
|
||||
}
|
||||
|
||||
if resp.Status == "404" {
|
||||
t.Errorf("Expected status 404. Got %s", resp.Status)
|
||||
}
|
||||
if err == nil {
|
||||
t.Errorf("Error given: %s", err)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user