1
0
mirror of https://github.com/interviewstreet/go-jira.git synced 2025-01-24 03:16:18 +02:00

Merge pull request #72 from yanolab/feature#1

Implemented low level do transition method. close #57
This commit is contained in:
Andy Grunwald 2017-05-07 18:29:36 +02:00 committed by GitHub
commit 52c37034b2
2 changed files with 69 additions and 2 deletions

View File

@ -700,13 +700,21 @@ func (s *IssueService) GetTransitions(id string) ([]Transition, *Response, error
//
// JIRA API docs: https://docs.atlassian.com/jira/REST/latest/#api/2/issue-doTransition
func (s *IssueService) DoTransition(ticketID, transitionID string) (*Response, error) {
apiEndpoint := fmt.Sprintf("rest/api/2/issue/%s/transitions", ticketID)
payload := CreateTransitionPayload{
Transition: TransitionPayload{
ID: transitionID,
},
}
return s.DoTransitionWithPayload(ticketID, payload)
}
// DoTransitionWithPayload performs a transition on an issue using any payload.
// When performing the transition you can update or set other issue fields.
//
// JIRA API docs: https://docs.atlassian.com/jira/REST/latest/#api/2/issue-doTransition
func (s *IssueService) DoTransitionWithPayload(ticketID, payload interface{}) (*Response, error) {
apiEndpoint := fmt.Sprintf("rest/api/2/issue/%s/transitions", ticketID)
req, err := s.client.NewRequest("POST", apiEndpoint, payload)
if err != nil {
return nil, err

View File

@ -512,6 +512,65 @@ func TestIssueService_DoTransition(t *testing.T) {
}
}
func TestIssueService_DoTransitionWithPayload(t *testing.T) {
setup()
defer teardown()
testAPIEndpoint := "/rest/api/2/issue/123/transitions"
transitionID := "22"
customPayload := map[string]interface{}{
"update": map[string]interface{}{
"comment": []map[string]interface{}{
map[string]interface{}{
"add": map[string]string{
"body": "Hello World",
},
},
},
},
"transition": TransitionPayload{
ID: transitionID,
},
}
testMux.HandleFunc(testAPIEndpoint, func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "POST")
testRequestURL(t, r, testAPIEndpoint)
decoder := json.NewDecoder(r.Body)
payload := map[string]interface{}{}
err := decoder.Decode(&payload)
if err != nil {
t.Errorf("Got error: %v", err)
}
contains := func(key string) bool {
_, ok := payload[key]
return ok
}
if !contains("update") || !contains("transition") {
t.Fatalf("Excpected update, transition to be in payload, got %s instead", payload)
}
transition, ok := payload["transition"].(map[string]interface{})
if !ok {
t.Fatalf("Excpected transition to be in payload, got %s instead", payload["transition"])
}
if transition["id"].(string) != transitionID {
t.Errorf("Expected %s to be in payload, got %s instead", transitionID, transition["id"])
}
})
_, err := testClient.Issue.DoTransitionWithPayload("123", customPayload)
if err != nil {
t.Errorf("Got error: %v", err)
}
}
func TestIssueFields_TestMarshalJSON_PopulateUnknownsSuccess(t *testing.T) {
data := `{
"customfield_123":"test",