-
-
Notifications
You must be signed in to change notification settings - Fork 474
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #148 from natemara/component-service
Create component service
- Loading branch information
Showing
3 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package jira | ||
|
||
// ComponentService handles components for the JIRA instance / API. | ||
// | ||
// JIRA API docs: https://docs.atlassian.com/software/jira/docs/api/REST/7.10.1/#api/2/component | ||
type ComponentService struct { | ||
client *Client | ||
} | ||
|
||
// CreateComponentOptions are passed to the ComponentService.Create function to create a new JIRA component | ||
type CreateComponentOptions struct { | ||
Name string `json:"name,omitempty" structs:"name,omitempty"` | ||
Description string `json:"description,omitempty" structs:"description,omitempty"` | ||
Lead *User `json:"lead,omitempty" structs:"lead,omitempty"` | ||
LeadUserName string `json:"leadUserName,omitempty" structs:"leadUserName,omitempty"` | ||
AssigneeType string `json:"assigneeType,omitempty" structs:"assigneeType,omitempty"` | ||
Assignee *User `json:"assignee,omitempty" structs:"assignee,omitempty"` | ||
Project string `json:"project,omitempty" structs:"project,omitempty"` | ||
ProjectID int `json:"projectId,omitempty" structs:"projectId,omitempty"` | ||
} | ||
|
||
// Create creates a new JIRA component based on the given options. | ||
func (s *ComponentService) Create(options *CreateComponentOptions) (*ProjectComponent, *Response, error) { | ||
apiEndpoint := "rest/api/2/component" | ||
req, err := s.client.NewRequest("POST", apiEndpoint, options) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
component := new(ProjectComponent) | ||
resp, err := s.client.Do(req, component) | ||
|
||
if err != nil { | ||
return nil, resp, NewJiraError(resp, err) | ||
} | ||
|
||
return component, resp, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package jira | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"testing" | ||
) | ||
|
||
func TestComponentService_Create_Success(t *testing.T) { | ||
setup() | ||
defer teardown() | ||
testMux.HandleFunc("/rest/api/2/component", func(w http.ResponseWriter, r *http.Request) { | ||
testMethod(t, r, "POST") | ||
testRequestURL(t, r, "/rest/api/2/component") | ||
|
||
w.WriteHeader(http.StatusCreated) | ||
fmt.Fprint(w, `{ "self": "http://www.example.com/jira/rest/api/2/component/10000", "id": "10000", "name": "Component 1", "description": "This is a JIRA component", "lead": { "self": "http://www.example.com/jira/rest/api/2/user?username=fred", "name": "fred", "avatarUrls": { "48x48": "http://www.example.com/jira/secure/useravatar?size=large&ownerId=fred", "24x24": "http://www.example.com/jira/secure/useravatar?size=small&ownerId=fred", "16x16": "http://www.example.com/jira/secure/useravatar?size=xsmall&ownerId=fred", "32x32": "http://www.example.com/jira/secure/useravatar?size=medium&ownerId=fred" }, "displayName": "Fred F. User", "active": false }, "assigneeType": "PROJECT_LEAD", "assignee": { "self": "http://www.example.com/jira/rest/api/2/user?username=fred", "name": "fred", "avatarUrls": { "48x48": "http://www.example.com/jira/secure/useravatar?size=large&ownerId=fred", "24x24": "http://www.example.com/jira/secure/useravatar?size=small&ownerId=fred", "16x16": "http://www.example.com/jira/secure/useravatar?size=xsmall&ownerId=fred", "32x32": "http://www.example.com/jira/secure/useravatar?size=medium&ownerId=fred" }, "displayName": "Fred F. User", "active": false }, "realAssigneeType": "PROJECT_LEAD", "realAssignee": { "self": "http://www.example.com/jira/rest/api/2/user?username=fred", "name": "fred", "avatarUrls": { "48x48": "http://www.example.com/jira/secure/useravatar?size=large&ownerId=fred", "24x24": "http://www.example.com/jira/secure/useravatar?size=small&ownerId=fred", "16x16": "http://www.example.com/jira/secure/useravatar?size=xsmall&ownerId=fred", "32x32": "http://www.example.com/jira/secure/useravatar?size=medium&ownerId=fred" }, "displayName": "Fred F. User", "active": false }, "isAssigneeTypeValid": false, "project": "HSP", "projectId": 10000 }`) | ||
}) | ||
|
||
component, _, err := testClient.Component.Create(&CreateComponentOptions{ | ||
Name: "foo-bar", | ||
}) | ||
if component == nil { | ||
t.Error("Expected component. Component is nil") | ||
} | ||
if err != nil { | ||
t.Errorf("Error given: %s", err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters